Merge pull request #5696 from Budibase/fix/pc-fixes-automations
Foreach block fixes
This commit is contained in:
commit
b4ecee81ee
|
@ -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
|
||||
|
|
|
@ -182,7 +182,11 @@
|
|||
<div class="fields">
|
||||
{#each schemaProperties as [key, value]}
|
||||
<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}
|
||||
<Select
|
||||
on:change={e => onChange(e, key)}
|
||||
|
|
|
@ -86,3 +86,15 @@ exports.substituteLoopStep = (hbsString, substitute) => {
|
|||
|
||||
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) {
|
||||
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
|
||||
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,9 +136,6 @@ class Orchestrator {
|
|||
newInput,
|
||||
loopStep.schema.inputs
|
||||
)
|
||||
this._context.steps[loopStepNumber] = {
|
||||
currentItem: newInput.binding[index],
|
||||
}
|
||||
|
||||
let tempOutput = { items: loopSteps, iterations: iterationCount }
|
||||
if (
|
||||
|
@ -154,6 +153,20 @@ class Orchestrator {
|
|||
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
|
||||
// Pretty hacky because we need to account for the row object
|
||||
for (let [key, value] of Object.entries(originalStepInput)) {
|
||||
|
|
Loading…
Reference in New Issue