diff --git a/packages/builder/src/builderStore/store/automation/index.js b/packages/builder/src/builderStore/store/automation/index.js index 7e61b410e4..84e6033439 100644 --- a/packages/builder/src/builderStore/store/automation/index.js +++ b/packages/builder/src/builderStore/store/automation/index.js @@ -98,7 +98,6 @@ const automationActions = store => ({ automationId: automation?._id, testData, }) - console.log(result) store.update(state => { state.selectedAutomation.testResults = result return state diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte index 00b2366657..5a00b3e790 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte @@ -34,7 +34,6 @@ $: testResult = $automationStore.selectedAutomation.testResults?.steps.filter( step => (block.id ? step.id === block.id : step.stepId === block.stepId) ) - $: console.log(testResult) $: isTrigger = block.type === "TRIGGER" $: selected = $automationStore.selectedBlock?.id === block.id @@ -57,6 +56,7 @@ x => x.blockToLoop === block.id ) $: showLooping = false + async function deleteStep() { try { automationStore.actions.deleteAutomationBlock(block) @@ -81,18 +81,6 @@ ) } - async function removeLooping() { - loopingSelected = false - const loopToDelete = - $automationStore.selectedAutomation.automation.definition.steps.findIndex( - x => x.blockToLoop === block.id - ) - - automationStore.actions.deleteAutomationBlock(loopToDelete) - await automationStore.actions.save( - $automationStore.selectedAutomation?.automation - ) - } async function addLooping() { loopingSelected = true const loopDefinition = $automationStore.blockDefinitions.ACTION.LOOP @@ -103,6 +91,7 @@ loopDefinition ) loopBlock.blockToLoop = block.id + block.loopBlock = loopBlock.id automationStore.actions.addBlockToAutomation(loopBlock, blockIdx - 1) await automationStore.actions.save( $automationStore.selectedAutomation?.automation @@ -142,6 +131,16 @@
+ {#if testResult && testResult[0]} +
resultsModal.show()}> + View response +
+ {/if} +
{ diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 2b4be4bb29..bd309d9809 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -104,7 +104,13 @@ ) bindings = bindings.concat( outputs.map(([name, value]) => { - const runtime = idx === 0 ? `trigger.${name}` : `steps.${idx}.${name}` + let runtimeName = + $automationStore.selectedAutomation.automation.definition.steps.find( + x => block.id === x.blockToLoop + ) + ? `loop.${name}` + : `steps.${idx}.${name}` + const runtime = idx === 0 ? `trigger.${name}` : runtimeName return { label: runtime, type: value.type, @@ -115,6 +121,7 @@ }) ) } + return bindings } diff --git a/packages/server/src/automations/steps/loop.js b/packages/server/src/automations/steps/loop.js index 1f53210269..543317f3be 100644 --- a/packages/server/src/automations/steps/loop.js +++ b/packages/server/src/automations/steps/loop.js @@ -36,7 +36,7 @@ exports.definition = { }, success: { type: "boolean", - description: "Whether the message sent successfully", + description: "Whether the message loop was successfully", }, iterations: { type: "number", diff --git a/packages/server/src/threads/automation.js b/packages/server/src/threads/automation.js index 666403d595..8ebad28f9a 100644 --- a/packages/server/src/threads/automation.js +++ b/packages/server/src/threads/automation.js @@ -17,7 +17,6 @@ const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId const CRON_STEP_ID = triggerDefs.CRON.stepId const STOPPED_STATUS = { success: false, status: "STOPPED" } const { cloneDeep } = require("lodash/fp") -const { loop } = require("svelte/internal") /** * The automation orchestrator is a class responsible for executing automations. @@ -89,6 +88,7 @@ class Orchestrator { let stepCount = 0 let loopStepNumber let loopSteps = [] + let lastLoopStep for (let step of automation.definition.steps) { stepCount++ if (step.stepId === LOOP_STEP_ID) { @@ -145,13 +145,9 @@ class Orchestrator { }) continue } - if (loopStep) { - loopSteps.push({ - id: step.id, - stepId: step.stepId, - inputs: step.inputs, - outputs, - }) + this._context.steps.splice(loopStepNumber, 1) + if (loopStep && loopSteps) { + loopSteps.push(outputs) } else { this.updateExecutionOutput( step.id, @@ -166,34 +162,30 @@ class Orchestrator { } if (index === iterations - 1) { + lastLoopStep = loopStep loopStep = null break } } - if (loopSteps) { - this.executionOutput.steps.splice(loopStepNumber, 0, { - id: step.id, - stepId: step.stepId, - outputs: { - success: true, - outputs: loopSteps, - iterations: iterations, - }, - }) - this._context.steps.splice(loopStepNumber, 0, { - id: step.id, - stepId: step.stepId, - steps: loopSteps, - iterations, - success: true, + + if (loopSteps && loopSteps.length) { + let tempOutput = { success: true, outputs: loopSteps } + this.executionOutput.steps.splice(loopStep, 0, { + id: lastLoopStep.id, + stepId: lastLoopStep.stepId, + outputs: tempOutput, + inputs: step.inputs, }) + this._context.steps.splice(loopStep, 0, tempOutput) loopSteps = null } } + // Increment quota for automation runs if (!env.SELF_HOSTED && !isDevAppID(this._appId)) { await usage.update(usage.Properties.AUTOMATION, 1) } + console.log(JSON.stringify(this._context, null, 2)) // make that we don't loop the next step if we have already been looping (loop block only has one step) return this.executionOutput }