diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 37a72ba334..e83b4efa35 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -23,9 +23,10 @@ import { AutomationStatus, AutomationStep, AutomationStepStatus, + BranchSearchFilters, BranchStep, + LogicalOperator, LoopStep, - SearchFilters, UserBindings, } from "@budibase/types" import { AutomationContext, TriggerOutput } from "../definitions/automations" @@ -546,12 +547,31 @@ class Orchestrator { ) } + private recurseSearchFilters( + filters: BranchSearchFilters, + processFn: (filter: BranchSearchFilters) => BranchSearchFilters + ): BranchSearchFilters { + // Process the current level + filters = processFn(filters) + + // Recurse through logical operators + for (const logical of Object.values(LogicalOperator)) { + if (filters[logical]) { + filters[logical]!.conditions = filters[logical]!.conditions.map( + condition => this.recurseSearchFilters(condition, processFn) + ) + } + } + + return filters + } + private async evaluateBranchCondition( - conditions: SearchFilters + conditions: BranchSearchFilters ): Promise { const toFilter: Record = {} - const processedConditions = dataFilters.recurseSearchFilters( + const processedConditions = this.recurseSearchFilters( conditions, filter => { Object.entries(filter).forEach(([_, value]) => { diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 7720fe2b8d..15c30800a1 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -142,25 +142,6 @@ export function recurseLogicalOperators( return filters } -export function recurseSearchFilters( - filters: SearchFilters, - processFn: (filter: SearchFilters) => SearchFilters -): SearchFilters { - // Process the current level - filters = processFn(filters) - - // Recurse through logical operators - for (const logical of LOGICAL_OPERATORS) { - if (filters[logical]) { - filters[logical]!.conditions = filters[logical]!.conditions.map( - condition => recurseSearchFilters(condition, processFn) - ) - } - } - - return filters -} - /** * Removes any fields that contain empty strings that would cause inconsistent * behaviour with how backend tables are filtered (no value means no filter). diff --git a/packages/types/src/documents/app/automation/StepInputsOutputs.ts b/packages/types/src/documents/app/automation/StepInputsOutputs.ts index 1b734c589c..3aadb77108 100644 --- a/packages/types/src/documents/app/automation/StepInputsOutputs.ts +++ b/packages/types/src/documents/app/automation/StepInputsOutputs.ts @@ -1,5 +1,10 @@ import { SortOrder } from "../../../api" -import { SearchFilters, EmptyFilterOption } from "../../../sdk" +import { + SearchFilters, + EmptyFilterOption, + BasicOperator, + LogicalOperator, +} from "../../../sdk" import { HttpMethod } from "../query" import { Row } from "../row" import { LoopStepType, EmailAttachment, AutomationResults } from "./automation" @@ -118,9 +123,17 @@ export type BranchStepInputs = { export type Branch = { id: any name: string - condition: SearchFilters + condition: BranchSearchFilters } +export type BranchSearchFilters = Pick< + SearchFilters, + | BasicOperator.EQUAL + | BasicOperator.NOT_EQUAL + | LogicalOperator.AND + | LogicalOperator.OR +> + export type MakeIntegrationInputs = { url: string body: any