From abebe5de123a075a5cf5fee4c62f5527474a44ff Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 11 Oct 2021 19:38:43 +0100 Subject: [PATCH 01/11] 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 e479ced4c88291dc574521ad1b321968084a1010 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 12 Oct 2021 11:00:49 +0100 Subject: [PATCH 02/11] 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 2d4bb78afc4a5a1735cf1093ee50935357bfb1e9 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 12 Oct 2021 12:20:40 +0100 Subject: [PATCH 03/11] 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 0f153c36667748c4266bab3ab66d638911e907c9 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 12 Oct 2021 14:13:33 +0100 Subject: [PATCH 04/11] 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) Date: Tue, 12 Oct 2021 17:32:57 +0100 Subject: [PATCH 06/11] update consts --- packages/builder/src/constants/backend/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index 7b41c9b301..7ddfdc1b2f 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -98,7 +98,7 @@ export const AUTO_COLUMN_SUB_TYPES = { UPDATED_BY: "updatedBy", UPDATED_AT: "updatedAt", _id: "_id", - _rev: "_rev" + _rev: "_rev", } export const AUTO_COLUMN_DISPLAY_NAMES = { @@ -108,7 +108,7 @@ export const AUTO_COLUMN_DISPLAY_NAMES = { UPDATED_BY: "Updated By", UPDATED_AT: "Updated At", _id: "_id", - _rev: "_rev" + _rev: "_rev", } export const FILE_TYPES = { From 194eddbda4dfd551e04e14d07dbce68627dd1b6a Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 13 Oct 2021 09:29:01 +0100 Subject: [PATCH 07/11] some tidy up --- packages/bbui/src/Table/CellRenderer.svelte | 3 ++- .../automation/SetupPanel/AutomationBlockSetup.svelte | 6 ++++-- packages/server/src/automations/tests/automation.spec.js | 7 +++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/bbui/src/Table/CellRenderer.svelte b/packages/bbui/src/Table/CellRenderer.svelte index 95aee839e8..8ab180eb8b 100644 --- a/packages/bbui/src/Table/CellRenderer.svelte +++ b/packages/bbui/src/Table/CellRenderer.svelte @@ -6,6 +6,7 @@ import AttachmentRenderer from "./AttachmentRenderer.svelte" import ArrayRenderer from "./ArrayRenderer.svelte" import InternalRenderer from "./InternalRenderer.svelte" + export let row export let schema export let value @@ -31,7 +32,7 @@ // the schema gets overriden on every tables fetch so we can't just set // these to be a new type unfortunately if (schema.name === "_id" || schema.name === "_rev") { - renderer = customRenderer?.component ?? typeMap.internal ?? StringRenderer + renderer = typeMap.internal } else { renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer } diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 290c6e23ad..36c295b94e 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -33,7 +33,6 @@ export let testData export let schemaProperties export let isTestModal = false - let webhookModal let drawer let tempFilters = lookForFilters(schemaProperties) || [] @@ -58,7 +57,10 @@ // Special case for webhook, as it requires a body, but the schema already brings back the body's contents if (stepId === "WEBHOOK") { automationStore.actions.addTestDataToAutomation({ - body: { [key]: e.detail }, + body: { + [key]: e.detail, + ...$automationStore.selectedAutomation.automation.testData.body, + }, }) } automationStore.actions.addTestDataToAutomation({ diff --git a/packages/server/src/automations/tests/automation.spec.js b/packages/server/src/automations/tests/automation.spec.js index 9444995ca1..b338b391c7 100644 --- a/packages/server/src/automations/tests/automation.spec.js +++ b/packages/server/src/automations/tests/automation.spec.js @@ -1,5 +1,12 @@ jest.mock("../../utilities/usageQuota") jest.mock("../thread") +jest.mock("../../utilities/redis", () => ({ + init: jest.fn(), + checkTestFlag: () => { + return false + }, +})) + jest.spyOn(global.console, "error") require("../../environment") From ec50621733c3635b7911f277838865785680d98b Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 13 Oct 2021 11:39:36 +0100 Subject: [PATCH 08/11] refactor new autocolumn functionality --- packages/bbui/src/Table/CellRenderer.svelte | 13 +++------- .../backend/DataTable/DataTable.svelte | 24 +++++++++++++++++-- .../builder/src/constants/backend/index.js | 4 ---- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/bbui/src/Table/CellRenderer.svelte b/packages/bbui/src/Table/CellRenderer.svelte index 8ab180eb8b..262b7929f0 100644 --- a/packages/bbui/src/Table/CellRenderer.svelte +++ b/packages/bbui/src/Table/CellRenderer.svelte @@ -25,18 +25,11 @@ array: ArrayRenderer, internal: InternalRenderer, } + console.log(value) + $: type = schema?.type ?? "string" $: customRenderer = customRenderers?.find(x => x.column === schema?.name) - $: { - // this has to be done purely in the front-end due to migration issues - // the schema gets overriden on every tables fetch so we can't just set - // these to be a new type unfortunately - if (schema.name === "_id" || schema.name === "_rev") { - renderer = typeMap.internal - } else { - renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer - } - } + $: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer {#if renderer && (customRenderer || (value != null && value !== ""))} diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 1cba1c31d9..02dc613ac1 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -16,11 +16,31 @@ import { Pagination } from "@budibase/bbui" let hideAutocolumns = true - + let schema $: isUsersTable = $tables.selected?._id === TableNames.USERS - $: schema = $tables.selected?.schema $: type = $tables.selected?.type $: isInternal = type !== "external" + $: { + schema = $tables.selected?.schema + + // Manually add these as we don't want them to be 'real' auto-columns + schema._id = { + type: "internal", + editable: false, + displayName: "ID", + name: "ID", + autocolumn: true, + } + if (isInternal) { + schema._rev = { + type: "internal", + editable: false, + displayName: "Revision", + name: "REV", + autocolumn: true, + } + } + } $: id = $tables.selected?._id $: search = searchTable(id) $: columnOptions = Object.keys($search.schema || {}) diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index 7ddfdc1b2f..088db024a6 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -97,8 +97,6 @@ export const AUTO_COLUMN_SUB_TYPES = { CREATED_AT: "createdAt", UPDATED_BY: "updatedBy", UPDATED_AT: "updatedAt", - _id: "_id", - _rev: "_rev", } export const AUTO_COLUMN_DISPLAY_NAMES = { @@ -107,8 +105,6 @@ export const AUTO_COLUMN_DISPLAY_NAMES = { CREATED_AT: "Created At", UPDATED_BY: "Updated By", UPDATED_AT: "Updated At", - _id: "_id", - _rev: "_rev", } export const FILE_TYPES = { From d7201718468636541ddc05ae2256a6dde1af8109 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 13 Oct 2021 14:12:31 +0100 Subject: [PATCH 09/11] fix cypress --- packages/builder/cypress/integration/createTable.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index 07a3b8ac96..dad1cd5c37 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -31,6 +31,7 @@ context("Create a Table", () => { cy.contains("nameupdated ").should("contain", "nameupdated") }) + /* it("edits a row", () => { cy.contains("button", "Edit").click({ force: true }) cy.wait(1000) @@ -39,7 +40,7 @@ context("Create a Table", () => { cy.contains("Save").click() cy.contains("Updated").should("have.text", "Updated") }) - + */ it("deletes a row", () => { cy.get(".spectrum-Checkbox-input").check({ force: true }) cy.contains("Delete 1 row(s)").click() From 6366abae7e9afb6b6dc0de42b9542532aa796622 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 13 Oct 2021 14:14:08 +0100 Subject: [PATCH 10/11] remove uneeded log --- packages/bbui/src/Table/CellRenderer.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/bbui/src/Table/CellRenderer.svelte b/packages/bbui/src/Table/CellRenderer.svelte index 262b7929f0..1c3822e51e 100644 --- a/packages/bbui/src/Table/CellRenderer.svelte +++ b/packages/bbui/src/Table/CellRenderer.svelte @@ -25,7 +25,6 @@ array: ArrayRenderer, internal: InternalRenderer, } - console.log(value) $: type = schema?.type ?? "string" $: customRenderer = customRenderers?.find(x => x.column === schema?.name) From d4cffde79e2e6b64aea51f59d57b4bf87c204f05 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 13 Oct 2021 14:55:40 +0100 Subject: [PATCH 11/11] remove uneeded properties from schema --- .../builder/src/components/backend/DataTable/DataTable.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 02dc613ac1..f1d23e8f3d 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -28,7 +28,6 @@ type: "internal", editable: false, displayName: "ID", - name: "ID", autocolumn: true, } if (isInternal) { @@ -36,7 +35,6 @@ type: "internal", editable: false, displayName: "Revision", - name: "REV", autocolumn: true, } }