From 0fadf104e257823d232dfc9d9da1c9409b535f67 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 9 Sep 2021 12:00:37 +0100 Subject: [PATCH] save automation on change / delete / create --- .../FlowChart/FlowChart.svelte | 51 +++++-- .../FlowChart/FlowItem.svelte | 124 ++++++------------ .../FlowChart/ResultsModal.svelte | 58 ++++++++ .../FlowChart/TestDataModal.svelte | 18 ++- .../CreateAutomationModal.svelte | 8 +- .../SetupPanel/AutomationBlockSetup.svelte | 57 ++++++-- .../automation/SetupPanel/CronBuilder.svelte | 11 +- .../automation/SetupPanel/RowSelector.svelte | 20 ++- .../automation/SetupPanel/SchemaSetup.svelte | 6 + .../SetupPanel/TableSelector.svelte | 9 ++ .../automate/[automation]/_layout.svelte | 15 +++ .../app/[application]/automate/_layout.svelte | 2 +- 12 files changed, 262 insertions(+), 117 deletions(-) create mode 100644 packages/builder/src/components/automation/AutomationBuilder/FlowChart/ResultsModal.svelte create mode 100644 packages/builder/src/pages/builder/app/[application]/automate/[automation]/_layout.svelte 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"> - + 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]} - testDataModal.show()} cta + >Test Automation {/if} - {/if} - - - - -
- -
{ - if (setupComplete) { - testToggled = !testToggled - } - }} - class="toggle" - > - {#if testToggled} - - {:else} - - {/if} - Test -
- {#if testToggled} - Add test data Add 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 +
+ > + +