fix failure condition

This commit is contained in:
Peter Clement 2022-04-11 23:10:29 +01:00
parent b58b84776e
commit 261b6ccb03
3 changed files with 70 additions and 106 deletions

View File

@ -10,7 +10,7 @@
Button, Button,
StatusLight, StatusLight,
Select, Select,
Label, ActionButton,
notifications, notifications,
} from "@budibase/bbui" } from "@budibase/bbui"
import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte" import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte"
@ -58,7 +58,15 @@
$: showLooping = false $: showLooping = false
async function deleteStep() { async function deleteStep() {
let loopBlock =
$automationStore.selectedAutomation?.automation.definition.steps.find(
x => x.blockToLoop === block.id
)
try { try {
if (loopBlock) {
automationStore.actions.deleteAutomationBlock(loopBlock)
}
automationStore.actions.deleteAutomationBlock(block) automationStore.actions.deleteAutomationBlock(block)
await automationStore.actions.save( await automationStore.actions.save(
$automationStore.selectedAutomation?.automation $automationStore.selectedAutomation?.automation
@ -233,29 +241,24 @@
<div> <div>
<div class="block-options"> <div class="block-options">
{#if !loopingSelected} {#if !loopingSelected}
<div style="display: flex;" on:click={() => addLooping()}> <ActionButton on:click={() => addLooping()} icon="Reuse"
<Icon name="Reuse" /> >Add Looping</ActionButton
<div style="margin-left:10px"> >
<Label>Add looping</Label>
</div>
</div>
{/if} {/if}
{#if showBindingPicker} {#if showBindingPicker}
<div> <Select
<Select on:change={toggleFieldControl}
on:change={toggleFieldControl} defaultValue="Use values"
quiet autoWidth
defaultValue="Use values" value={rowControl ? "Use bindings" : "Use values"}
autoWidth options={["Use values", "Use bindings"]}
value={rowControl ? "Use bindings" : "Use values"} placeholder={null}
options={["Use values", "Use bindings"]} />
placeholder={null}
/>
</div>
{/if} {/if}
<div class="delete-padding" on:click={() => deleteStep()}> <ActionButton
<Icon name="DeleteOutline" /> on:click={() => deleteStep()}
</div> icon="DeleteOutline"
/>
</div> </div>
</div> </div>
{/if} {/if}
@ -306,6 +309,7 @@
justify-content: flex-end; justify-content: flex-end;
align-items: center; align-items: center;
display: flex; display: flex;
gap: var(--spacing-m);
} }
.center-items { .center-items {
display: flex; display: flex;

View File

@ -30,7 +30,6 @@
import FilterDrawer from "components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte" import FilterDrawer from "components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte"
import { LuceneUtils } from "@budibase/frontend-core" import { LuceneUtils } from "@budibase/frontend-core"
import { getSchemaForTable } from "builderStore/dataBinding" import { getSchemaForTable } from "builderStore/dataBinding"
import { cloneDeep } from "lodash/fp"
export let block export let block
export let testData export let testData
@ -97,19 +96,23 @@
} }
let blockIdx = allSteps.findIndex(step => step.id === block.id) let blockIdx = allSteps.findIndex(step => step.id === block.id)
let loopBlockIdx = cloneDeep(allSteps)
.splice(0, blockIdx)
.findIndex(x => x.stepId === "LOOP")
// if a loop stepId exists in previous steps, we need to decerement the blockIdx
if (loopBlockIdx > -1 && blockIdx > loopBlockIdx) {
blockIdx--
}
// Extract all outputs from all previous steps as available bindins // Extract all outputs from all previous steps as available bindins
let bindings = [] let bindings = []
for (let idx = 0; idx < blockIdx; idx++) { for (let idx = 0; idx < blockIdx; idx++) {
let isLoopBlock = allSteps[idx + 1]?.blockToLoop === block.id let wasLoopBlock = allSteps[idx]?.stepId === "LOOP"
let isLoopBlock =
allSteps[idx]?.stepId === "LOOP" &&
allSteps.find(x => x.blockToLoop === block.id)
// If the previous block was a loop block, decerement the index so the following
// steps are in the correct order
if (wasLoopBlock) {
blockIdx--
}
let schema = allSteps[idx]?.schema?.outputs?.properties ?? {} let schema = allSteps[idx]?.schema?.outputs?.properties ?? {}
// If its a Loop Block, we need to add this custom schema
if (isLoopBlock) { if (isLoopBlock) {
schema = { schema = {
currentItem: { currentItem: {
@ -118,14 +121,6 @@
}, },
} }
} }
if (loopBlockIdx && allSteps[blockIdx - 1]?.stepId === "LOOP") {
schema = {
...schema,
...$automationStore.blockDefinitions.ACTION.LOOP.schema.outputs
.properties.properties,
}
}
const outputs = Object.entries(schema) const outputs = Object.entries(schema)
bindings = bindings.concat( bindings = bindings.concat(

View File

@ -77,6 +77,24 @@ class Orchestrator {
this.executionOutput.steps.push(stepObj) this.executionOutput.steps.push(stepObj)
} }
updateContextAndOutput(loopStepNumber, step, output, result) {
this.executionOutput.steps.splice(loopStepNumber, 0, {
id: step.id,
stepId: step.stepId,
outputs: {
...output,
success: result.success,
status: result.status,
},
inputs: step.inputs,
})
this._context.steps.splice(loopStepNumber, 0, {
...output,
success: result.success,
status: result.status,
})
}
async execute() { async execute() {
let automation = this._automation let automation = this._automation
const app = await this.getApp() const app = await this.getApp()
@ -118,62 +136,30 @@ class Orchestrator {
this._context.steps[loopStepNumber] = { this._context.steps[loopStepNumber] = {
currentItem: newInput.binding[index], currentItem: newInput.binding[index],
} }
let tempOutput = { items: loopSteps, iterations: iterationCount } let tempOutput = { items: loopSteps, iterations: iterationCount }
if ( if (
loopStep.inputs.option === "Array" && (loopStep.inputs.option === "Array" &&
!Array.isArray(newInput.binding) !Array.isArray(newInput.binding)) ||
(loopStep.inputs.option === "String" &&
typeof newInput.binding !== "string")
) { ) {
this.executionOutput.steps.splice(loopStepNumber, 0, { this.updateContextAndOutput(loopStepNumber, step, tempOutput, {
id: step.id,
stepId: step.stepId,
outputs: {
...tempOutput,
success: true,
status: "INCORRECT_TYPE",
},
inputs: step.inputs,
})
this._context.steps.splice(loopStepNumber, 0, {
...tempOutput,
success: true,
status: "INCORRECT_TYPE", status: "INCORRECT_TYPE",
success: false,
}) })
loopSteps = null
loopStep = null
break
} else if (
loopStep.inputs.option === "String" &&
typeof newInput.binding !== "string"
) {
this.executionOutput.steps.splice(loopStepNumber, 0, {
id: step.id,
stepId: step.stepId,
outputs: {
...tempOutput,
success: false,
status: "INCORRECT_TYPE",
},
inputs: step.inputs,
})
this._context.steps.splice(loopStepNumber, 0, {
...tempOutput,
success: true,
status: "INCORRECT_TYPE",
})
loopSteps = null loopSteps = null
loopStep = null loopStep = null
break break
} }
// The "Loop" binding in the front end is "fake", so replace it here so the context can understand it // 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
for (let key in originalStepInput) { for (let key in originalStepInput) {
if (key === "row") { if (key === "row") {
for (let test in originalStepInput["row"]) { for (let val in originalStepInput["row"]) {
originalStepInput["row"][test] = originalStepInput["row"][ originalStepInput["row"][val] = originalStepInput["row"][
test val
].replace(/loop/, `steps.${loopStepNumber}`) ].replace(/loop/, `steps.${loopStepNumber}`)
} }
} else { } else {
@ -185,18 +171,10 @@ class Orchestrator {
} }
if (index >= loopStep.inputs.iterations) { if (index >= loopStep.inputs.iterations) {
this.executionOutput.steps.splice(loopStepNumber, 0, { this.updateContextAndOutput(loopStepNumber, step, tempOutput, {
id: step.id, status: "MAX_ITERATIONS_REACHED",
stepId: step.stepId,
outputs: { ...tempOutput, success: true, status: "LOOP_BROKEN" },
inputs: step.inputs,
})
this._context.steps.splice(loopStepNumber, 0, {
...tempOutput,
success: true, success: true,
status: "LOOP_BROKEN",
}) })
loopSteps = null loopSteps = null
loopStep = null loopStep = null
break break
@ -206,23 +184,10 @@ class Orchestrator {
this._context.steps[loopStepNumber]?.currentItem === this._context.steps[loopStepNumber]?.currentItem ===
loopStep.inputs.failure loopStep.inputs.failure
) { ) {
console.log("hello?????") this.updateContextAndOutput(loopStepNumber, step, tempOutput, {
this.executionOutput.steps.splice(loopStepNumber, 0, {
id: step.id,
stepId: step.stepId,
outputs: {
...tempOutput,
success: false,
status: "FAILURE_CONDITION_MET",
},
inputs: step.inputs,
})
this._context.steps.splice(loopStepNumber, 0, {
...tempOutput,
success: false,
status: "FAILURE_CONDITION_MET", status: "FAILURE_CONDITION_MET",
success: false,
}) })
loopSteps = null loopSteps = null
loopStep = null loopStep = null
break break