fix issue where bindings where incorrect in automations
This commit is contained in:
parent
7fe41ef949
commit
2a3f943957
|
@ -16,6 +16,7 @@ import {
|
|||
AutomationTriggerStepId,
|
||||
AutomationEventType,
|
||||
AutomationStepType,
|
||||
AutomationActionStepId,
|
||||
} from "@budibase/types"
|
||||
import { ActionStepID } from "constants/backend/automations"
|
||||
import { FIELDS } from "constants/backend"
|
||||
|
@ -466,9 +467,13 @@ const automationActions = store => ({
|
|||
.getPathSteps(block.pathTo, automation)
|
||||
.slice(0, -1)
|
||||
|
||||
// Current step will always be the last step of the path
|
||||
const currentBlock = store.actions
|
||||
.getPathSteps(block.pathTo, automation)
|
||||
.at(-1)
|
||||
|
||||
// Extract all outputs from all previous steps as available bindingsx§x
|
||||
let bindings = []
|
||||
|
||||
const addBinding = (name, value, icon, idx, isLoopBlock, bindingName) => {
|
||||
if (!name) return
|
||||
const runtimeBinding = determineRuntimeBinding(
|
||||
|
@ -519,6 +524,10 @@ const automationActions = store => ({
|
|||
runtimeName = `loop.${name}`
|
||||
} else if (idx === 0) {
|
||||
runtimeName = `trigger.${name}`
|
||||
} else if (
|
||||
currentBlock?.stepId === AutomationActionStepId.EXECUTE_SCRIPT
|
||||
) {
|
||||
runtimeName = `steps["${pathSteps[idx]?.id}"].${name}`
|
||||
} else {
|
||||
runtimeName = `steps.${pathSteps[idx]?.id}.${name}`
|
||||
}
|
||||
|
@ -637,7 +646,6 @@ const automationActions = store => ({
|
|||
console.error("Loop block missing.")
|
||||
}
|
||||
}
|
||||
|
||||
Object.entries(schema).forEach(([name, value]) => {
|
||||
addBinding(name, value, icon, blockIdx, isLoopBlock, bindingName)
|
||||
})
|
||||
|
|
|
@ -61,8 +61,10 @@ export async function run({
|
|||
inputs: ServerLogStepInputs
|
||||
appId: string
|
||||
}): Promise<ServerLogStepOutputs> {
|
||||
if (typeof inputs.text === "object") {
|
||||
inputs.text = JSON.stringify(inputs.text)
|
||||
}
|
||||
const message = `App ${appId} - ${inputs.text}`
|
||||
console.log(message)
|
||||
return {
|
||||
success: true,
|
||||
message,
|
||||
|
|
|
@ -385,7 +385,7 @@ class Orchestrator {
|
|||
stepIdx: number,
|
||||
pathIdx?: number
|
||||
): Promise<number> {
|
||||
await processObject(loopStep.inputs, this.processContext(this.context))
|
||||
await processObject(loopStep.inputs, this.mergeContexts(this.context))
|
||||
const iterations = getLoopIterations(loopStep)
|
||||
let stepToLoopIndex = stepIdx + 1
|
||||
let pathStepIdx = (pathIdx || stepIdx) + 1
|
||||
|
@ -573,14 +573,14 @@ class Orchestrator {
|
|||
for (const [field, value] of Object.entries(filters[filterKey])) {
|
||||
const fromContext = processStringSync(
|
||||
field,
|
||||
this.processContext(this.context)
|
||||
this.mergeContexts(this.context)
|
||||
)
|
||||
toFilter[field] = fromContext
|
||||
|
||||
if (typeof value === "string" && findHBSBlocks(value).length > 0) {
|
||||
const processedVal = processStringSync(
|
||||
value,
|
||||
this.processContext(this.context)
|
||||
this.mergeContexts(this.context)
|
||||
)
|
||||
|
||||
filters[filterKey][field] = processedVal
|
||||
|
@ -637,7 +637,7 @@ class Orchestrator {
|
|||
const stepFn = await this.getStepFunctionality(step.stepId)
|
||||
let inputs = await processObject(
|
||||
originalStepInput,
|
||||
this.processContext(this.context)
|
||||
this.mergeContexts(this.context)
|
||||
)
|
||||
inputs = automationUtils.cleanInputValues(inputs, step.schema.inputs)
|
||||
|
||||
|
@ -645,7 +645,7 @@ class Orchestrator {
|
|||
inputs: inputs,
|
||||
appId: this.appId,
|
||||
emitter: this.emitter,
|
||||
context: this.context,
|
||||
context: this.mergeContexts(this.context),
|
||||
})
|
||||
this.handleStepOutput(step, outputs, loopIteration)
|
||||
}
|
||||
|
@ -665,8 +665,8 @@ class Orchestrator {
|
|||
return null
|
||||
}
|
||||
|
||||
private processContext(context: AutomationContext) {
|
||||
const processContext = {
|
||||
private mergeContexts(context: AutomationContext) {
|
||||
const mergeContexts = {
|
||||
...context,
|
||||
steps: {
|
||||
...context.steps,
|
||||
|
@ -674,7 +674,7 @@ class Orchestrator {
|
|||
...context.stepsByName,
|
||||
},
|
||||
}
|
||||
return processContext
|
||||
return mergeContexts
|
||||
}
|
||||
|
||||
private handleStepOutput(
|
||||
|
|
Loading…
Reference in New Issue