Merge pull request #14787 from Budibase/branching/branch-evaluation-bindings
Changes to support processing bindings on both sides of branch condition evaluation
This commit is contained in:
commit
20acd90838
|
@ -48,7 +48,9 @@ describe("Branching automations", () => {
|
|||
{ stepId: branch1LogId }
|
||||
),
|
||||
condition: {
|
||||
equal: { [`{{ steps.${firstLogId}.success }}`]: true },
|
||||
equal: {
|
||||
[`{{ literal steps.${firstLogId}.success }}`]: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
branch2: {
|
||||
|
@ -58,19 +60,21 @@ describe("Branching automations", () => {
|
|||
{ stepId: branch2LogId }
|
||||
),
|
||||
condition: {
|
||||
equal: { [`{{ steps.${firstLogId}.success }}`]: false },
|
||||
equal: {
|
||||
[`{{ literal steps.${firstLogId}.success }}`]: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
condition: {
|
||||
equal: { [`{{ steps.${firstLogId}.success }}`]: true },
|
||||
equal: { [`{{ literal steps.${firstLogId}.success }}`]: true },
|
||||
},
|
||||
},
|
||||
topLevelBranch2: {
|
||||
steps: stepBuilder =>
|
||||
stepBuilder.serverLog({ text: "Branch 2" }, { stepId: branch2Id }),
|
||||
condition: {
|
||||
equal: { [`{{ steps.${firstLogId}.success }}`]: false },
|
||||
equal: { [`{{ literal steps.${firstLogId}.success }}`]: false },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -217,4 +221,90 @@ describe("Branching automations", () => {
|
|||
)
|
||||
expect(results.steps[2]).toBeUndefined()
|
||||
})
|
||||
|
||||
it("evaluate multiple conditions", async () => {
|
||||
const builder = createAutomationBuilder({
|
||||
name: "evaluate multiple conditions",
|
||||
})
|
||||
|
||||
const results = await builder
|
||||
.appAction({ fields: { test_trigger: true } })
|
||||
.serverLog({ text: "Starting automation" }, { stepId: "aN6znRYHG" })
|
||||
.branch({
|
||||
specialBranch: {
|
||||
steps: stepBuilder => stepBuilder.serverLog({ text: "Special user" }),
|
||||
condition: {
|
||||
$or: {
|
||||
conditions: [
|
||||
{
|
||||
equal: {
|
||||
'{{ js "cmV0dXJuICQoInRyaWdnZXIuZmllbGRzLnRlc3RfdHJpZ2dlciIp" }}':
|
||||
"{{ literal trigger.fields.test_trigger}}",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
regularBranch: {
|
||||
steps: stepBuilder => stepBuilder.serverLog({ text: "Regular user" }),
|
||||
condition: {
|
||||
$and: {
|
||||
conditions: [
|
||||
{
|
||||
equal: { "{{ literal trigger.fields.test_trigger}}": "blah" },
|
||||
},
|
||||
{
|
||||
equal: { "{{ literal trigger.fields.test_trigger}}": "123" },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
.run()
|
||||
|
||||
expect(results.steps[2].outputs.message).toContain("Special user")
|
||||
})
|
||||
|
||||
it("evaluate multiple conditions with interpolated text", async () => {
|
||||
const builder = createAutomationBuilder({
|
||||
name: "evaluate multiple conditions",
|
||||
})
|
||||
|
||||
const results = await builder
|
||||
.appAction({ fields: { test_trigger: true } })
|
||||
.serverLog({ text: "Starting automation" }, { stepId: "aN6znRYHG" })
|
||||
.branch({
|
||||
specialBranch: {
|
||||
steps: stepBuilder => stepBuilder.serverLog({ text: "Special user" }),
|
||||
condition: {
|
||||
$or: {
|
||||
conditions: [
|
||||
{
|
||||
equal: {
|
||||
"{{ trigger.fields.test_trigger }} 5":
|
||||
"{{ trigger.fields.test_trigger }} 5",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
regularBranch: {
|
||||
steps: stepBuilder => stepBuilder.serverLog({ text: "Regular user" }),
|
||||
condition: {
|
||||
$and: {
|
||||
conditions: [
|
||||
{ equal: { "{{ trigger.fields.test_trigger }}": "blah" } },
|
||||
{ equal: { "{{ trigger.fields.test_trigger }}": "123" } },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
.run()
|
||||
|
||||
expect(results.steps[2].outputs.message).toContain("Special user")
|
||||
})
|
||||
})
|
||||
|
|
|
@ -88,13 +88,13 @@ class BaseStepBuilder {
|
|||
Object.entries(branchConfig).forEach(([key, branch]) => {
|
||||
const stepBuilder = new StepBuilder()
|
||||
branch.steps(stepBuilder)
|
||||
|
||||
let branchId = uuidv4()
|
||||
branchStepInputs.branches.push({
|
||||
name: key,
|
||||
condition: branch.condition,
|
||||
id: uuidv4(),
|
||||
id: branchId,
|
||||
})
|
||||
branchStepInputs.children![key] = stepBuilder.build()
|
||||
branchStepInputs.children![branchId] = stepBuilder.build()
|
||||
})
|
||||
const branchStep: AutomationStep = {
|
||||
...definition,
|
||||
|
|
|
@ -30,7 +30,11 @@ import {
|
|||
import { AutomationContext, TriggerOutput } from "../definitions/automations"
|
||||
import { WorkerCallback } from "./definitions"
|
||||
import { context, logging } from "@budibase/backend-core"
|
||||
import { processObject, processStringSync } from "@budibase/string-templates"
|
||||
import {
|
||||
findHBSBlocks,
|
||||
processObject,
|
||||
processStringSync,
|
||||
} from "@budibase/string-templates"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import { performance } from "perf_hooks"
|
||||
import * as sdkUtils from "../sdk/utils"
|
||||
|
@ -535,13 +539,21 @@ class Orchestrator {
|
|||
conditions,
|
||||
filter => {
|
||||
Object.entries(filter).forEach(([_, value]) => {
|
||||
Object.entries(value).forEach(([field, _]) => {
|
||||
const updatedField = field.replace("{{", "{{ literal ")
|
||||
Object.entries(value).forEach(([field, val]) => {
|
||||
const fromContext = processStringSync(
|
||||
updatedField,
|
||||
field,
|
||||
this.processContext(this.context)
|
||||
)
|
||||
toFilter[field] = fromContext
|
||||
|
||||
if (typeof val === "string" && findHBSBlocks(val).length > 0) {
|
||||
const processedVal = processStringSync(
|
||||
val,
|
||||
this.processContext(this.context)
|
||||
)
|
||||
|
||||
value[field] = processedVal
|
||||
}
|
||||
})
|
||||
})
|
||||
return filter
|
||||
|
|
Loading…
Reference in New Issue