diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte index de89ebbb12..2398d2754a 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte @@ -1,16 +1,18 @@ @@ -32,26 +57,23 @@ style="display:flex; color: var(--spectrum-global-color-gray-400);" > - + deleteAutomation()} class="iconPadding"> - Delete + testAutomation()} + icon="MultipleCheck" + size="S">Run test - - {#if published} - Automation is published{:else} - Automation is not published{/if} - {#each blocks as block, idx (block.id)} {#if idx !== blocks.length - 1} @@ -97,6 +119,7 @@ } .iconPadding { + cursor: pointer; display: flex; padding-right: var(--spacing-m); } diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte index cca59345ee..bc2ded8870 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte @@ -8,77 +8,52 @@ Detail, Modal, Button, - ActionButton, - notifications, StatusLight, } from "@budibase/bbui" import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte" import CreateWebhookModal from "components/automation/shared/CreateWebhookModal.svelte" import TestDataModal from "./TestDataModal.svelte" + import ResultsModal from "./ResultsModal.svelte" + import ActionModal from "./ActionModal.svelte" import { database } from "stores/backend" export let onSelect export let block - let selected let webhookModal let testDataModal let actionModal - let setupComplete + let resultsModal + let setupToggled let blockComplete - let testToggled - - $: setupToggled = !setupComplete || false - $: instanceId = $database._id - $: schemaKey = Object.keys(block.schema?.inputs?.properties || {}) + + $: isTrigger = block.type === "TRIGGER" $: selected = $automationStore.selectedBlock?.id === block.id $: steps = $automationStore.selectedAutomation?.automation?.definition?.steps ?? [] $: blockIdx = steps.findIndex(step => step.id === block.id) - $: allowDeleteTrigger = !steps.length + $: lastStep = !isTrigger && blockIdx + 1 === steps.length - function deleteStep() { + // Logic for hiding / showing the add button.first we check if it has a child + // then we check to see whether its inputs have been commpleted + $: disableAddButton = isTrigger + ? $automationStore.selectedAutomation?.automation?.definition?.steps + .length > 0 + : !isTrigger && steps.length - blockIdx > 1 + $: hasCompletedInputs = Object.keys( + block.schema?.inputs?.properties || {} + ).every(x => block?.inputs[x]) + + async function deleteStep() { automationStore.actions.deleteAutomationBlock(block) - } - - async function testAutomation() { - const result = await automationStore.actions.trigger({ - automation: $automationStore.selectedAutomation.automation, - }) - if (result.status === 200) { - notifications.success( - `Automation ${$automationStore.selectedAutomation.automation.name} triggered successfully.` - ) - } else { - notifications.error( - `Failed to trigger automation ${$automationStore.selectedAutomation.automation.name}.` - ) - } - return result - } - - async function saveAutomation() { await automationStore.actions.save({ instanceId, - automation: $automationStore.selectedAutomation.automation, + automation: $automationStore.selectedAutomation?.automation, }) - notifications.success( - `Automation ${$automationStore.selectedAutomation.automation.name} saved.` - ) - } - - function onContinue() { - const testResult = testAutomation() - const saveResult = saveAutomation() - - if (testResult && saveResult) { - setupComplete = true - testToggled = true - } } @@ -108,8 +83,12 @@ {block?.name?.toUpperCase() || ""} - {#if blockComplete} - + {#if !blockComplete} + resultsModal.show()}> + View response + {/if} @@ -120,9 +99,7 @@ { - if (!setupComplete) { - setupToggled = !setupToggled - } + setupToggled = !setupToggled }} class="toggle" > @@ -133,55 +110,38 @@ {/if} Setup - deleteStep()}> - - + {#if !isTrigger} + deleteStep()}> + + + {/if} {#if setupToggled} - {#if block.inputs[schemaKey]} - onContinue()} cta - >Continue and test trigger testDataModal.show()} cta + >Test Automation {/if} - {/if} - - - - - - - { - if (setupComplete) { - testToggled = !testToggled - } - }} - class="toggle" - > - {#if testToggled} - - {:else} - - {/if} - Test - - {#if testToggled} - Add test data { + setupToggled = false actionModal.show() }} - cta>Save trigger and continue to actionAdd Action {/if} {/if} + + + + diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ResultsModal.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ResultsModal.svelte new file mode 100644 index 0000000000..cbfd5ad432 --- /dev/null +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ResultsModal.svelte @@ -0,0 +1,58 @@ + + + + + { + inputToggled = !inputToggled + }} + class="toggle" + > + {#if inputToggled} + + {:else} + + {/if} + Input + + + + + { + outputToggled = !outputToggled + }} + class="toggle" + > + {#if outputToggled} + + {:else} + + {/if} + Output + + + + + diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte index 31139fdc9e..9de0265dc9 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte @@ -1,5 +1,10 @@ - test + + > + + JSON + + + diff --git a/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte b/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte index 799cd930dd..e774c366a5 100644 --- a/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte @@ -26,8 +26,14 @@ automationStore.actions.addBlockToAutomation(newBlock) if (triggerVal.stepId === "WEBHOOK") { - webhookModal.show() + webhookModal.show } + + await automationStore.actions.save({ + instanceId, + automation: $automationStore.selectedAutomation?.automation, + }) + notifications.success(`Automation ${name} created.`) $goto(`./${$automationStore.selectedAutomation.automation._id}`) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index e571102625..7930a38274 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -12,16 +12,25 @@ import QueryParamSelector from "./QueryParamSelector.svelte" import CronBuilder from "./CronBuilder.svelte" import Editor from "components/integration/QueryEditor.svelte" + import { database } from "stores/backend" export let block export let webhookModal - $: inputs = Object.entries(block.schema?.inputs?.properties || {}) $: stepId = block.stepId $: bindings = getAvailableBindings( block, $automationStore.selectedAutomation?.automation?.definition ) + $: instanceId = $database._id + + async function saveOnChange(e, key) { + block.inputs[key] = e.detail + await automationStore.actions.save({ + instanceId, + automation: $automationStore.selectedAutomation?.automation, + }) + } function getAvailableBindings(block, automation) { if (!block || !automation) { @@ -61,41 +70,67 @@ {value.title} {#if value.type === "string" && value.enum} saveOnChange(e, key)} + value={block.inputs[key]} options={value.enum} getOptionLabel={(x, idx) => (value.pretty ? value.pretty[idx] : x)} /> {:else if value.customType === "password"} - + saveOnChange(e, key)} + value={block.inputs[key]} + /> {:else if value.customType === "email"} (block.inputs[key] = e.detail)} + on:change={e => saveOnChange(e, key)} {bindings} /> {:else if value.customType === "query"} - + saveOnChange(e, key)} + value={block.inputs[key]} + /> {:else if value.customType === "cron"} - + saveOnChange(e, key)} + value={block.inputs[key]} + /> {:else if value.customType === "queryParams"} - + saveOnChange(e, key)} + value={block.inputs[key]} + {bindings} + /> {:else if value.customType === "table"} - + saveOnChange(e, key)} + /> {:else if value.customType === "row"} - + saveOnChange(e, key)} + {bindings} + /> {:else if value.customType === "webhookUrl"} {:else if value.customType === "triggerSchema"} - + saveOnChange(e, key)} + value={block.inputs[key]} + /> {:else if value.customType === "code"} {JSON.stringify(bindings, null, 2)} { + saveOnChange(e, key) block.inputs[key] = e.detail.value }} value={block.inputs[key]} @@ -107,7 +142,7 @@ panel={AutomationBindingPanel} type={value.customType} value={block.inputs[key]} - on:change={e => (block.inputs[key] = e.detail)} + on:change={e => saveOnChange(e, key)} {bindings} /> {/if} diff --git a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte index 810e452742..1b410cd86a 100644 --- a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte +++ b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte @@ -1,7 +1,13 @@ - + (presets = !presets)} @@ -38,7 +44,8 @@ > {#if presets} { + value = e.detail + dispatch("change", e.detail) + } export let value export let bindings - $: table = $tables.list.find(table => table._id === value?.tableId) $: schemaFields = Object.entries(table?.schema ?? {}) @@ -20,7 +27,8 @@ table.name} getOptionValue={table => table._id} @@ -32,15 +40,19 @@ {#if !schema.autocolumn} {#if schemaHasOptions(schema)} {:else if schema.type === "string" || schema.type === "number"} (value[field] = e.detail)} + on:change={e => { + value[field] = e.detail + dispatch("change", e.detail) + }} label={field} type="string" {bindings} diff --git a/packages/builder/src/components/automation/SetupPanel/SchemaSetup.svelte b/packages/builder/src/components/automation/SetupPanel/SchemaSetup.svelte index 1257563ff8..78ec776ad5 100644 --- a/packages/builder/src/components/automation/SetupPanel/SchemaSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/SchemaSetup.svelte @@ -1,5 +1,8 @@ diff --git a/packages/builder/src/components/automation/SetupPanel/TableSelector.svelte b/packages/builder/src/components/automation/SetupPanel/TableSelector.svelte index 4f9ac05a06..ceb28a37ca 100644 --- a/packages/builder/src/components/automation/SetupPanel/TableSelector.svelte +++ b/packages/builder/src/components/automation/SetupPanel/TableSelector.svelte @@ -1,11 +1,20 @@ table.name} diff --git a/packages/builder/src/pages/builder/app/[application]/automate/[automation]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/automate/[automation]/_layout.svelte new file mode 100644 index 0000000000..3be71a1bbe --- /dev/null +++ b/packages/builder/src/pages/builder/app/[application]/automate/[automation]/_layout.svelte @@ -0,0 +1,15 @@ + + + diff --git a/packages/builder/src/pages/builder/app/[application]/automate/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/automate/_layout.svelte index 5123e50bc6..82554fc8aa 100644 --- a/packages/builder/src/pages/builder/app/[application]/automate/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/automate/_layout.svelte @@ -40,7 +40,7 @@ {/if} - +
{JSON.stringify(bindings, null, 2)}