1
0
Fork 0
mirror of synced 2024-08-12 16:41:26 +12:00

Some foreach block fixes

This commit is contained in:
Peter Clement 2022-05-04 10:24:28 +01:00
parent 3c5ffb3212
commit af9b9b6921
2 changed files with 28 additions and 15 deletions

View file

@ -53,6 +53,18 @@
x => x.blockToLoop === block.id
)
async function removeLooping() {
loopingSelected = false
let loopBlock =
$automationStore.selectedAutomation?.automation.definition.steps.find(
x => x.blockToLoop === block.id
)
automationStore.actions.deleteAutomationBlock(loopBlock)
await automationStore.actions.save(
$automationStore.selectedAutomation?.automation
)
}
async function deleteStep() {
let loopBlock =
$automationStore.selectedAutomation?.automation.definition.steps.find(
@ -151,9 +163,7 @@
{#if !showLooping}
<div class="blockSection">
<div class="block-options">
<div class="delete-padding" on:click={() => deleteStep()}>
<Icon name="DeleteOutline" />
</div>
<ActionButton on:click={() => removeLooping()} icon="DeleteOutline" />
</div>
<Layout noPadding gap="S">
<AutomationBlockSetup

View file

@ -107,7 +107,6 @@ class Orchestrator {
let loopSteps = []
for (let step of automation.definition.steps) {
stepCount++
let input
if (step.stepId === LOOP_STEP_ID) {
loopStep = step
loopStepNumber = stepCount
@ -115,17 +114,21 @@ class Orchestrator {
}
if (loopStep) {
input = await processObject(loopStep.inputs, this._context)
// lets first of all handle the input
if (
typeof loopStep.inputs.binding === "string" &&
loopStep.inputs.option === "String"
) {
loopStep.inputs.binding = loopStep.inputs.binding.split("\n")
}
}
let iterations = loopStep ? input.binding.length : 1
let iterations = loopStep ? loopStep.inputs.binding.length : 1
let iterationCount = 0
for (let index = 0; index < iterations; index++) {
let originalStepInput = cloneDeep(step.inputs)
// Handle if the user has set a max iteration count or if it reaches the max limit set by us
if (loopStep) {
// lets first of all handle the input
// if the input is array then use it, if it is a string then split it on every new line
let newInput = await processObject(
loopStep.inputs,
cloneDeep(this._context)
@ -134,16 +137,13 @@ class Orchestrator {
newInput,
loopStep.schema.inputs
)
this._context.steps[loopStepNumber] = {
currentItem: newInput.binding[index],
}
let tempOutput = { items: loopSteps, iterations: iterationCount }
if (
(loopStep.inputs.option === "Array" &&
!Array.isArray(newInput.binding)) ||
(loopStep.inputs.option === "String" &&
typeof newInput.binding !== "string")
(originalStepInput.option === "Array" &&
!Array.isArray(originalStepInput.binding)) ||
(originalStepInput.option === "String" &&
typeof originalStepInput.binding !== "string")
) {
this.updateContextAndOutput(loopStepNumber, step, tempOutput, {
status: AutomationErrors.INCORRECT_TYPE,
@ -153,6 +153,9 @@ class Orchestrator {
loopStep = null
break
}
this._context.steps[loopStepNumber] = {
currentItem: newInput.binding[index],
}
// The "Loop" binding in the front end is "fake", so replace it here so the context can understand it
// Pretty hacky because we need to account for the row object