From a8829d9adbeba78a6ada807178f3ae8222e21f24 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 11 Oct 2021 19:38:43 +0100 Subject: [PATCH 01/25] fix app action trigger --- .../SetupPanel/AutomationBlockSetup.svelte | 16 ++++++++++++-- .../server/src/automations/triggerInfo/app.js | 1 + packages/server/src/automations/triggers.js | 21 +++++++++++-------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index ff52c7d11a..daac9427b2 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -9,7 +9,10 @@ Label, ActionButton, Drawer, + Modal, } from "@budibase/bbui" + import CreateWebhookModal from "components/automation/Shared/CreateWebhookModal.svelte" + import { automationStore } from "builderStore" import { tables } from "stores/backend" import WebhookDisplay from "../Shared/WebhookDisplay.svelte" @@ -27,13 +30,15 @@ import { buildLuceneQuery } from "helpers/lucene" export let block - export let webhookModal export let testData export let schemaProperties export let isTestModal = false + + let webhookModal let drawer let tempFilters = lookForFilters(schemaProperties) || [] let fillWidth = true + $: stepId = block.stepId $: bindings = getAvailableBindings( block || $automationStore.selectedBlock, @@ -205,7 +210,10 @@ {bindings} /> {:else if value.customType === "webhookUrl"} - + onChange(e, key)} + value={inputData[key]} + /> {:else if value.customType === "triggerSchema"} onChange(e, key)} value={inputData[key]} /> {:else if value.customType === "code"} @@ -247,6 +255,10 @@ {/each} + + + + {#if stepId === "WEBHOOK"} {/if} diff --git a/packages/server/src/automations/triggerInfo/app.js b/packages/server/src/automations/triggerInfo/app.js index 40d1531fa0..b1b07e9d5b 100644 --- a/packages/server/src/automations/triggerInfo/app.js +++ b/packages/server/src/automations/triggerInfo/app.js @@ -22,6 +22,7 @@ exports.definition = { fields: { type: "object", description: "Fields submitted from the app frontend", + customType: "triggerSchema", }, }, required: ["fields"], diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index ae98f0e73a..f774c23123 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -81,16 +81,19 @@ exports.externalTrigger = async function ( params, { getResponses } = {} ) { - if (automation.definition != null && automation.definition.trigger != null) { - if (automation.definition.trigger.stepId === "APP") { - // values are likely to be submitted as strings, so we shall convert to correct type - const coercedFields = {} - const fields = automation.definition.trigger.inputs.fields - for (let key of Object.keys(fields)) { - coercedFields[key] = coerce(params.fields[key], fields[key]) - } - params.fields = coercedFields + if ( + automation.definition != null && + automation.definition.trigger != null && + automation.definition.trigger.stepId === definitions.APP.stepId && + !checkTestFlag(automation._id) + ) { + // values are likely to be submitted as strings, so we shall convert to correct type + const coercedFields = {} + const fields = automation.definition.trigger.inputs.fields + for (let key of Object.keys(fields)) { + coercedFields[key] = coerce(params.fields[key], fields[key]) } + params.fields = coercedFields } const data = { automation, event: params } if (getResponses) { From 6f708ec86b7296efc2fd10bd3ce892bb7183ae5c Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 12 Oct 2021 11:00:49 +0100 Subject: [PATCH 02/25] fix webhook issue in automations --- .../builderStore/store/automation/Automation.js | 2 +- .../FlowChart/TestDataModal.svelte | 17 ++++++++++------- .../SetupPanel/AutomationBlockSetup.svelte | 9 +++++++++ .../automation/Shared/CreateWebhookModal.svelte | 2 -- packages/server/src/automations/triggers.js | 1 + 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/builder/src/builderStore/store/automation/Automation.js b/packages/builder/src/builderStore/store/automation/Automation.js index 49928c69a9..af0c03cb5a 100644 --- a/packages/builder/src/builderStore/store/automation/Automation.js +++ b/packages/builder/src/builderStore/store/automation/Automation.js @@ -14,7 +14,7 @@ export default class Automation { } addTestData(data) { - this.automation.testData = data + this.automation.testData = { ...this.automation.testData, ...data } } addBlock(block, idx) { diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte index 8caba9d351..3c75c9963d 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte @@ -5,20 +5,24 @@ import { cloneDeep } from "lodash/fp" let failedParse = null + let trigger = {} + let schemaProperties = {} + // clone the trigger so we're not mutating the reference - let trigger = cloneDeep( + $: trigger = cloneDeep( $automationStore.selectedAutomation.automation.definition.trigger ) - let schemaProperties = Object.entries(trigger.schema.outputs.properties || {}) + + // get the outputs so we can define the fields + $: schemaProperties = Object.entries(trigger?.schema?.outputs?.properties) if (!$automationStore.selectedAutomation.automation.testData) { $automationStore.selectedAutomation.automation.testData = {} } - // get the outputs so we can define the fields - // check to see if there is existing test data in the store - $: testData = $automationStore.selectedAutomation.automation.testData + $: testData = $automationStore.selectedAutomation.automation.testData || {} + // Check the schema to see if required fields have been entered $: isError = !trigger.schema.outputs.required.every( required => testData[required] @@ -41,7 +45,6 @@ showConfirmButton={true} disabled={isError} onConfirm={() => { - automationStore.actions.addTestDataToAutomation(testData) automationStore.actions.test( $automationStore.selectedAutomation?.automation, testData @@ -53,7 +56,7 @@ >
import { Icon } from "@budibase/bbui" import { automationStore } from "builderStore" - import { database } from "stores/backend" import WebhookDisplay from "./WebhookDisplay.svelte" import { ModalContent } from "@budibase/bbui" import { onMount, onDestroy } from "svelte" @@ -12,7 +11,6 @@ let schemaURL let propCount = 0 - $: instanceId = $database._id $: automation = $automationStore.selectedAutomation?.automation onMount(async () => { diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index f774c23123..e6c722ce3e 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -85,6 +85,7 @@ exports.externalTrigger = async function ( automation.definition != null && automation.definition.trigger != null && automation.definition.trigger.stepId === definitions.APP.stepId && + automation.definition.trigger.stepId === "APP" && !checkTestFlag(automation._id) ) { // values are likely to be submitted as strings, so we shall convert to correct type From 31feef68825f621484399cecd0eccffbb893265e Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 12 Oct 2021 12:20:40 +0100 Subject: [PATCH 03/25] surface schema for user in json --- .../automation/SetupPanel/RowSelector.svelte | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte b/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte index 1d54c86b4a..7bd83069e6 100644 --- a/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte +++ b/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte @@ -11,10 +11,22 @@ export let value export let bindings - $: table = $tables.list.find(table => table._id === value?.tableId) - $: schemaFields = Object.entries(table?.schema ?? {}) + let table + let schemaFields + + $: { + table = $tables.list.find(table => table._id === value?.tableId) + schemaFields = Object.entries(table?.schema ?? {}) + // surface the schema so the user can see it in the json + schemaFields.map(([, schema]) => { + if (!schema.autocolumn && !value[schema.name]) { + value[schema.name] = "" + } + }) + } + const onChangeTable = e => { - value = { tableId: e.detail } + value["tableId"] = e.detail dispatch("change", value) } From b2b1d53c94b451d23c7fa6c804eac0f7330542c0 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 12 Oct 2021 14:13:33 +0100 Subject: [PATCH 04/25] add relationship selector to automation blocks --- .../src/components/automation/SetupPanel/RowSelector.svelte | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte b/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte index 7bd83069e6..3821157e51 100644 --- a/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte +++ b/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte @@ -5,6 +5,7 @@ import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte" import { createEventDispatcher } from "svelte" import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte" + import LinkedRowSelector from "components/common/LinkedRowSelector.svelte" import { automationStore } from "builderStore" const dispatch = createEventDispatcher() @@ -42,6 +43,8 @@ function schemaHasOptions(schema) { return !!schema.constraints?.inclusion?.length } + + $: console.log($tables.list) - import { Label, Input, Layout, Toggle, Button } from "@budibase/bbui" + import { + Label, + Input, + Layout, + Toggle, + Button, + TextArea, + } from "@budibase/bbui" import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte" import { capitalise } from "helpers" export let integration export let schema + let addButton @@ -29,6 +37,15 @@
+ {:else if schema[configKey].type === "longForm"} +
+ +