Merge pull request #5696 from Budibase/fix/pc-fixes-automations
Foreach block fixes
This commit is contained in:
commit
18d461830c
|
@ -53,6 +53,18 @@
|
||||||
x => x.blockToLoop === block.id
|
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() {
|
async function deleteStep() {
|
||||||
let loopBlock =
|
let loopBlock =
|
||||||
$automationStore.selectedAutomation?.automation.definition.steps.find(
|
$automationStore.selectedAutomation?.automation.definition.steps.find(
|
||||||
|
@ -151,9 +163,7 @@
|
||||||
{#if !showLooping}
|
{#if !showLooping}
|
||||||
<div class="blockSection">
|
<div class="blockSection">
|
||||||
<div class="block-options">
|
<div class="block-options">
|
||||||
<div class="delete-padding" on:click={() => deleteStep()}>
|
<ActionButton on:click={() => removeLooping()} icon="DeleteOutline" />
|
||||||
<Icon name="DeleteOutline" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<Layout noPadding gap="S">
|
<Layout noPadding gap="S">
|
||||||
<AutomationBlockSetup
|
<AutomationBlockSetup
|
||||||
|
|
|
@ -182,7 +182,11 @@
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
{#each schemaProperties as [key, value]}
|
{#each schemaProperties as [key, value]}
|
||||||
<div class="block-field">
|
<div class="block-field">
|
||||||
<Label>{value.title || (key === "row" ? "Table" : key)}</Label>
|
<Label
|
||||||
|
tooltip={value.title === "Binding / Value"
|
||||||
|
? "If using the String input type, please use a comma or newline separated string"
|
||||||
|
: null}>{value.title || (key === "row" ? "Table" : key)}</Label
|
||||||
|
>
|
||||||
{#if value.type === "string" && value.enum}
|
{#if value.type === "string" && value.enum}
|
||||||
<Select
|
<Select
|
||||||
on:change={e => onChange(e, key)}
|
on:change={e => onChange(e, key)}
|
||||||
|
|
|
@ -86,3 +86,15 @@ exports.substituteLoopStep = (hbsString, substitute) => {
|
||||||
|
|
||||||
return hbsString
|
return hbsString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.stringSplit = value => {
|
||||||
|
if (value == null) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
if (value.split("\n").length > 1) {
|
||||||
|
value = value.split("\n")
|
||||||
|
} else {
|
||||||
|
value = value.split(",")
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
|
@ -117,15 +117,17 @@ class Orchestrator {
|
||||||
if (loopStep) {
|
if (loopStep) {
|
||||||
input = await processObject(loopStep.inputs, this._context)
|
input = await processObject(loopStep.inputs, this._context)
|
||||||
}
|
}
|
||||||
let iterations = loopStep ? input.binding.length : 1
|
let iterations = loopStep
|
||||||
|
? Array.isArray(input.binding)
|
||||||
|
? input.binding.length
|
||||||
|
: automationUtils.stringSplit(input.binding).length
|
||||||
|
: 1
|
||||||
let iterationCount = 0
|
let iterationCount = 0
|
||||||
for (let index = 0; index < iterations; index++) {
|
for (let index = 0; index < iterations; index++) {
|
||||||
let originalStepInput = cloneDeep(step.inputs)
|
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
|
// Handle if the user has set a max iteration count or if it reaches the max limit set by us
|
||||||
if (loopStep) {
|
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(
|
let newInput = await processObject(
|
||||||
loopStep.inputs,
|
loopStep.inputs,
|
||||||
cloneDeep(this._context)
|
cloneDeep(this._context)
|
||||||
|
@ -134,9 +136,6 @@ class Orchestrator {
|
||||||
newInput,
|
newInput,
|
||||||
loopStep.schema.inputs
|
loopStep.schema.inputs
|
||||||
)
|
)
|
||||||
this._context.steps[loopStepNumber] = {
|
|
||||||
currentItem: newInput.binding[index],
|
|
||||||
}
|
|
||||||
|
|
||||||
let tempOutput = { items: loopSteps, iterations: iterationCount }
|
let tempOutput = { items: loopSteps, iterations: iterationCount }
|
||||||
if (
|
if (
|
||||||
|
@ -154,6 +153,20 @@ class Orchestrator {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let item
|
||||||
|
if (
|
||||||
|
typeof loopStep.inputs.binding === "string" &&
|
||||||
|
loopStep.inputs.option === "String"
|
||||||
|
) {
|
||||||
|
item = automationUtils.stringSplit(newInput.binding)
|
||||||
|
} else {
|
||||||
|
item = loopStep.inputs.binding
|
||||||
|
}
|
||||||
|
|
||||||
|
this._context.steps[loopStepNumber] = {
|
||||||
|
currentItem: item[index],
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
// Pretty hacky because we need to account for the row object
|
||||||
for (let [key, value] of Object.entries(originalStepInput)) {
|
for (let [key, value] of Object.entries(originalStepInput)) {
|
||||||
|
|
Loading…
Reference in New Issue