From fd71ad57dac2b88f5e67b865b774a365934f4d19 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 24 Aug 2023 16:12:12 +0100 Subject: [PATCH] Add better support for generic DS+ into databindings and update save row to work with view V2s --- .../builder/src/builderStore/dataBinding.js | 22 +++++++++++----- .../SetupPanel/AutomationBlockSetup.svelte | 4 +-- .../actions/DeleteRow.svelte | 8 +++--- .../actions/DuplicateRow.svelte | 4 +-- .../ButtonActionEditor/actions/SaveRow.svelte | 26 ++++++++++++------- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index 615b032d92..8f12b36083 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -418,7 +418,7 @@ const getProviderContextBindings = (asset, dataProviders) => { */ export const getUserBindings = () => { let bindings = [] - const { schema } = getSchemaForTable(TableNames.USERS) + const { schema } = getSchemaForDatasourcePlus(TableNames.USERS) const keys = Object.keys(schema).sort() const safeUser = makePropSafe("user") @@ -647,17 +647,25 @@ export const getEventContextBindings = ( } /** - * Gets the schema for a certain table ID. + * Gets the schema for a certain datasource plus. * The options which can be passed in are: * formSchema: whether the schema is for a form * searchableSchema: whether to generate a searchable schema, which may have * fewer fields than a readable schema - * @param tableId the table ID to get the schema for + * @param resourceId the DS+ resource ID * @param options options for generating the schema * @return {{schema: Object, table: Object}} */ -export const getSchemaForTable = (tableId, options) => { - return getSchemaForDatasource(null, { type: "table", tableId }, options) +export const getSchemaForDatasourcePlus = (resourceId, options) => { + const isViewV2 = resourceId?.includes("view_ta_") + const datasource = isViewV2 + ? { + type: "viewV2", + id: resourceId, + tableId: resourceId.split("_").slice(1, 3).join("_"), + } + : { type: "table", tableId: resourceId } + return getSchemaForDatasource(null, datasource, options) } /** @@ -738,7 +746,9 @@ export const getSchemaForDatasource = (asset, datasource, options) => { schema = cloneDeep(table.views?.[datasource.name]?.schema) } else if (type === "viewV2") { // New views which are DS+ - const view = table.views?.[datasource.name] + const view = Object.values(table.views || {}).find( + view => view.id === datasource.id + ) schema = cloneDeep(view?.schema) // Strip hidden fields diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 6b57fe3d18..33a2c7cd73 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -39,7 +39,7 @@ import FilterDrawer from "components/design/settings/controls/FilterEditor/FilterDrawer.svelte" import { LuceneUtils } from "@budibase/frontend-core" import { - getSchemaForTable, + getSchemaForDatasourcePlus, getEnvironmentBindings, } from "builderStore/dataBinding" import { Utils } from "@budibase/frontend-core" @@ -158,7 +158,7 @@ // instead fetch the schema in the backend at runtime. let schema if (e.detail?.tableId) { - schema = getSchemaForTable(e.detail.tableId, { + schema = getSchemaForDatasourcePlus(e.detail.tableId, { searchableSchema: true, }).schema } diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte index d7741d8e26..1e79c51051 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte @@ -1,20 +1,20 @@
diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DuplicateRow.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DuplicateRow.svelte index bb253da56a..db1fff47f2 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DuplicateRow.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DuplicateRow.svelte @@ -4,7 +4,7 @@ import { tables } from "stores/backend" import { getContextProviderComponents, - getSchemaForTable, + getSchemaForDatasourcePlus, } from "builderStore/dataBinding" import SaveFields from "./SaveFields.svelte" @@ -60,7 +60,7 @@ } const getSchemaFields = (asset, tableId) => { - const { schema } = getSchemaForTable(tableId) + const { schema } = getSchemaForDatasourcePlus(tableId) delete schema._id delete schema._rev return Object.values(schema || {}) diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveRow.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveRow.svelte index d16a279c68..c1917ad90f 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveRow.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveRow.svelte @@ -1,10 +1,10 @@