From 6eeffb43ef2b7296e5dbea42b019ee2d7bfe73e3 Mon Sep 17 00:00:00 2001 From: Conor Webb Date: Tue, 16 Jul 2024 12:59:43 +0100 Subject: [PATCH 01/27] Add logic to prevent sidepanel and modals from closing when onload actions are active. --- packages/client/src/components/ClientApp.svelte | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index 9bfb1192ea..3d68b3bea7 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -51,6 +51,7 @@ let dataLoaded = false let permissionError = false let embedNoScreens = false + let onLoadCheck = false // Determine if we should show devtools or not $: showDevTools = $devToolsEnabled && !$routeStore.queryParams?.peek @@ -106,12 +107,24 @@ } const handleHashChange = () => { const { open: sidePanelOpen } = $sidePanelStore - if (sidePanelOpen) { + // only close if the sidepanel is open and theres no onload side panel actions on the screen. + if ( + sidePanelOpen && + !$screenStore.activeScreen.onLoad?.some( + item => item["##eventHandlerType"] === "Open Side Panel" + ) + ) { sidePanelStore.actions.close() } const { open: modalOpen } = $modalStore - if (modalOpen) { + // only close if the modal is open and theres onload modals actions on the screen. + if ( + modalOpen && + !$screenStore.activeScreen.onLoad?.some( + item => item["##eventHandlerType"] === "Open Modal" + ) + ) { modalStore.actions.close() } } From e2343073f0ecc802600df8ca02f9a210f6d5f6d2 Mon Sep 17 00:00:00 2001 From: Conor Webb Date: Tue, 16 Jul 2024 13:05:41 +0100 Subject: [PATCH 02/27] Remove unused variable --- packages/client/src/components/ClientApp.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index 3d68b3bea7..763c8ef771 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -51,7 +51,6 @@ let dataLoaded = false let permissionError = false let embedNoScreens = false - let onLoadCheck = false // Determine if we should show devtools or not $: showDevTools = $devToolsEnabled && !$routeStore.queryParams?.peek From c857bacafa6ba20f1a21df12726475f451b6d12a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 22 Jul 2024 16:26:59 +0100 Subject: [PATCH 03/27] Fix for #14201, adds the test helper into the manifest correctly. --- .../scripts/gen-collection-info.ts | 22 ++++------------- .../string-templates/src/helpers/constants.ts | 16 +++++++++++++ .../string-templates/src/helpers/external.ts | 24 ++++--------------- packages/string-templates/src/manifest.json | 20 ++++++++++++++++ 4 files changed, 46 insertions(+), 36 deletions(-) diff --git a/packages/string-templates/scripts/gen-collection-info.ts b/packages/string-templates/scripts/gen-collection-info.ts index d176665a5b..8b3825bf5c 100644 --- a/packages/string-templates/scripts/gen-collection-info.ts +++ b/packages/string-templates/scripts/gen-collection-info.ts @@ -1,4 +1,7 @@ -import { HelperFunctionBuiltin } from "../src/helpers/constants" +import { + HelperFunctionBuiltin, + EXTERNAL_FUNCTION_COLLECTIONS, +} from "../src/helpers/constants" import { readFileSync, writeFileSync } from "fs" import { marked } from "marked" import { join, dirname } from "path" @@ -14,21 +17,6 @@ type HelperInfo = { tags?: any[] } -/** - * full list of supported helpers can be found here: - * https://github.com/budibase/handlebars-helpers - */ - -const COLLECTIONS = [ - "math", - "array", - "number", - "url", - "string", - "comparison", - "object", - "uuid", -] const FILENAME = join(__dirname, "..", "src", "manifest.json") const outputJSON: any = {} const ADDED_HELPERS = { @@ -140,7 +128,7 @@ const excludeFunctions: Record = { string: ["raw"] } */ function run() { const foundNames: string[] = [] - for (let collection of COLLECTIONS) { + for (let collection of EXTERNAL_FUNCTION_COLLECTIONS) { const collectionFile = readFileSync( `${dirname( require.resolve("@budibase/handlebars-helpers") diff --git a/packages/string-templates/src/helpers/constants.ts b/packages/string-templates/src/helpers/constants.ts index ffccd36ab0..ee84a1dc47 100644 --- a/packages/string-templates/src/helpers/constants.ts +++ b/packages/string-templates/src/helpers/constants.ts @@ -15,6 +15,22 @@ export const HelperFunctionBuiltin = [ "with", ] +/** + * full list of supported helpers can be found here: + * https://github.com/Budibase/handlebars-helpers + */ +export const EXTERNAL_FUNCTION_COLLECTIONS = [ + "math", + "array", + "number", + "url", + "string", + "comparison", + "object", + "regex", + "uuid", +] + export const HelperFunctionNames = { OBJECT: "object", ALL: "all", diff --git a/packages/string-templates/src/helpers/external.ts b/packages/string-templates/src/helpers/external.ts index 36d5ac0f54..da4af779f3 100644 --- a/packages/string-templates/src/helpers/external.ts +++ b/packages/string-templates/src/helpers/external.ts @@ -2,26 +2,12 @@ import helpers from "@budibase/handlebars-helpers" import { date, duration } from "./date" -import { HelperFunctionBuiltin } from "./constants" +import { + HelperFunctionBuiltin, + EXTERNAL_FUNCTION_COLLECTIONS, +} from "./constants" import Handlebars from "handlebars" -/** - * full list of supported helpers can be found here: - * https://github.com/Budibase/handlebars-helpers - */ - -const EXTERNAL_FUNCTION_COLLECTIONS = [ - "math", - "array", - "number", - "url", - "string", - "comparison", - "object", - "regex", - "uuid", -] - const ADDED_HELPERS = { date: date, duration: duration, @@ -40,7 +26,7 @@ export function registerAll(handlebars: typeof Handlebars) { let hbsHelperInfo = helpers[collection]() for (let entry of Object.entries(hbsHelperInfo)) { const name = entry[0] - // skip built in functions and ones seen already + // skip built-in functions and ones seen already if ( HelperFunctionBuiltin.indexOf(name) !== -1 || externalNames.indexOf(name) !== -1 diff --git a/packages/string-templates/src/manifest.json b/packages/string-templates/src/manifest.json index 2af84caa08..7931c60641 100644 --- a/packages/string-templates/src/manifest.json +++ b/packages/string-templates/src/manifest.json @@ -1312,6 +1312,26 @@ "requiresBlock": false } }, + "regex": { + "toRegex": { + "args": [ + "str" + ], + "numArgs": 1, + "example": "{{toRegex 'foo'}} -> /foo/", + "description": "

Convert the given string to a regular expression.

\n", + "requiresBlock": false + }, + "test": { + "args": [ + "str" + ], + "numArgs": 1, + "example": "{{test 'foobar' (toRegex 'foo')}} -> true", + "description": "

Returns true if the given str matches the given regex. A regex can be passed on the context, or using the toRegex helper as a subexpression.

\n", + "requiresBlock": false + } + }, "uuid": { "uuid": { "args": [], From b611b0da3332ed7cdf0514edd99092da06abf9b2 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 22 Jul 2024 18:12:12 +0100 Subject: [PATCH 04/27] Fixing JS generation ordering. --- packages/string-templates/src/conversion/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/string-templates/src/conversion/index.ts b/packages/string-templates/src/conversion/index.ts index 7eb5ea71af..25700951c9 100644 --- a/packages/string-templates/src/conversion/index.ts +++ b/packages/string-templates/src/conversion/index.ts @@ -58,7 +58,7 @@ function buildList(parts: string[], value: any) { if (!value) { return parts.length > 1 ? `${build()}` : build() } else { - return parts.length === 0 ? value : `${value}, ${build()}` + return parts.length === 0 ? value : `${build()}, ${value}` } } From e34257a018f8fd47a3069c4d2186a739fd491220 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 22 Jul 2024 18:22:04 +0100 Subject: [PATCH 05/27] One more fix. --- packages/string-templates/test/hbsToJs.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/string-templates/test/hbsToJs.spec.ts b/packages/string-templates/test/hbsToJs.spec.ts index ea375064a1..ae071cfe37 100644 --- a/packages/string-templates/test/hbsToJs.spec.ts +++ b/packages/string-templates/test/hbsToJs.spec.ts @@ -93,10 +93,10 @@ describe("Test that the string processing works correctly", () => { it("should handle a complex statement", () => { const response = convertToJS( - "This is the average: {{ join ( avg val1 val2 val3 ) val4 }}" + "This is the average: {{ join val1 ( avg val2 val3 val4 ) }}" ) checkLines(response, [ - 'const var1 = helpers.join(helpers.avg($("val1"), $("val2"), $("val3")), $("val4"));', + 'const var1 = helpers.join($("val1"), helpers.avg($("val2"), $("val3"), $("val4")));', "return `This is the average: ${var1}`;", ]) }) @@ -119,10 +119,10 @@ describe("Test that the string processing works correctly", () => { it("should handle multiple complex statements", () => { const response = convertToJS( - "average: {{ avg ( abs val1 ) val2 }} add: {{ add 1 2 }}" + "average: {{ avg val1 ( abs val2 ) }} add: {{ add 1 2 }}" ) checkLines(response, [ - 'const var1 = helpers.avg(helpers.abs($("val1")), $("val2"));', + 'const var1 = helpers.avg($("val1"), helpers.abs($("val2")));', "const var2 = helpers.add(1, 2);", "return `average: ${var1} add: ${var2}`;", ]) From 9719e527f12cf608944e1b0e7f4aedb87561fded Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Tue, 23 Jul 2024 12:35:49 +0000 Subject: [PATCH 06/27] Bump version to 2.29.23 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index 843addc63c..fedbdf036a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "2.29.22", + "version": "2.29.23", "npmClient": "yarn", "packages": [ "packages/*", From 8a12523bcc59b66245ec2ce0e80d608ec7f87764 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 23 Jul 2024 14:58:21 +0200 Subject: [PATCH 07/27] Add find by usermetadata test --- .../server/src/api/routes/tests/row.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 8cabdf5e0f..7ed4c7d640 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -36,6 +36,7 @@ import { generator, mocks } from "@budibase/backend-core/tests" import _, { merge } from "lodash" import * as uuid from "uuid" import { Knex } from "knex" +import { InternalTables } from "../../../db/utils" const timestamp = new Date("2023-01-26T11:48:57.597Z").toISOString() tk.freeze(timestamp) @@ -804,6 +805,23 @@ describe.each([ status: 404, }) }) + + isInternal && + it("can search row from user table", async () => { + const res = await config.api.row.get( + InternalTables.USER_METADATA, + config.userMetadataId! + ) + + expect(res).toEqual({ + ...config.getUser(), + _id: config.userMetadataId!, + _rev: expect.any(String), + roles: undefined, + roleId: "ADMIN", + tableId: InternalTables.USER_METADATA, + }) + }) }) describe("fetch", () => { From 89173be9f409e46d9a0de5b67195b1343c8acb91 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 23 Jul 2024 15:03:44 +0200 Subject: [PATCH 08/27] Remove controller dependency --- packages/server/src/api/controllers/row/utils/utils.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/server/src/api/controllers/row/utils/utils.ts b/packages/server/src/api/controllers/row/utils/utils.ts index ae34034221..1a8b5c1041 100644 --- a/packages/server/src/api/controllers/row/utils/utils.ts +++ b/packages/server/src/api/controllers/row/utils/utils.ts @@ -1,5 +1,5 @@ import { InternalTables } from "../../../../db/utils" -import * as userController from "../../user" + import { context } from "@budibase/backend-core" import { Ctx, @@ -24,6 +24,7 @@ import { import sdk from "../../../../sdk" import { processStringSync } from "@budibase/string-templates" import validateJs from "validate.js" +import { getFullUser } from "../../../../utilities/users" validateJs.extend(validateJs.validators.datetime, { parse: function (value: string) { @@ -68,11 +69,7 @@ export async function findRow(ctx: UserCtx, tableId: string, rowId: string) { let row: Row // TODO remove special user case in future if (tableId === InternalTables.USER_METADATA) { - ctx.params = { - id: rowId, - } - await userController.findMetadata(ctx) - row = ctx.body + row = await getFullUser(rowId) } else { row = await db.get(rowId) } From 66a2b29ca27b91479be4bc22391c4136d54b29af Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 23 Jul 2024 15:06:00 +0200 Subject: [PATCH 09/27] Clean unnecessary ctx --- packages/server/src/api/controllers/row/internal.ts | 6 +++--- packages/server/src/api/controllers/row/utils/utils.ts | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/server/src/api/controllers/row/internal.ts b/packages/server/src/api/controllers/row/internal.ts index 54d9b6a536..fe09526c33 100644 --- a/packages/server/src/api/controllers/row/internal.ts +++ b/packages/server/src/api/controllers/row/internal.ts @@ -32,7 +32,7 @@ export async function patch(ctx: UserCtx) { try { oldRow = await outputProcessing( dbTable, - await utils.findRow(ctx, tableId, inputs._id!) + await utils.findRow(tableId, inputs._id!) ) } catch (err) { if (isUserTable) { @@ -100,7 +100,7 @@ export async function find(ctx: UserCtx): Promise { const tableId = utils.getTableId(ctx), rowId = ctx.params.rowId const table = await sdk.tables.getTable(tableId) - let row = await utils.findRow(ctx, tableId, rowId) + let row = await utils.findRow(tableId, rowId) row = await outputProcessing(table, row) return row } @@ -195,7 +195,7 @@ export async function fetchEnrichedRow(ctx: UserCtx) { sdk.tables.getTable(tableId), linkRows.getLinkDocuments({ tableId, rowId, fieldName }), ]) - let row = await utils.findRow(ctx, tableId, rowId) + let row = await utils.findRow(tableId, rowId) row = await outputProcessing(table, row) const linkVals = links as LinkDocumentValue[] diff --git a/packages/server/src/api/controllers/row/utils/utils.ts b/packages/server/src/api/controllers/row/utils/utils.ts index 1a8b5c1041..911cfe8d5b 100644 --- a/packages/server/src/api/controllers/row/utils/utils.ts +++ b/packages/server/src/api/controllers/row/utils/utils.ts @@ -8,7 +8,6 @@ import { RelationshipsJson, Row, Table, - UserCtx, } from "@budibase/types" import { processDates, @@ -64,7 +63,7 @@ export async function processRelationshipFields( return row } -export async function findRow(ctx: UserCtx, tableId: string, rowId: string) { +export async function findRow(tableId: string, rowId: string) { const db = context.getAppDB() let row: Row // TODO remove special user case in future From 75609b2a9b4aa686e3542668ea8a332de37c12b8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 23 Jul 2024 15:16:15 +0200 Subject: [PATCH 10/27] Move row.find to sdk --- .../src/api/controllers/row/external.ts | 27 ++-------------- .../server/src/api/controllers/row/index.ts | 7 ++-- .../src/api/controllers/row/internal.ts | 9 ------ packages/server/src/sdk/app/rows/external.ts | 17 ++++++++-- packages/server/src/sdk/app/rows/internal.ts | 32 +++++++++++++++++-- packages/server/src/sdk/app/rows/rows.ts | 4 +++ 6 files changed, 56 insertions(+), 40 deletions(-) diff --git a/packages/server/src/api/controllers/row/external.ts b/packages/server/src/api/controllers/row/external.ts index 601f47b511..18c88923e0 100644 --- a/packages/server/src/api/controllers/row/external.ts +++ b/packages/server/src/api/controllers/row/external.ts @@ -57,9 +57,7 @@ export async function patch(ctx: UserCtx) { throw { validation: validateResult.errors } } - const beforeRow = await sdk.rows.external.getRow(tableId, _id, { - relationships: true, - }) + const beforeRow = await sdk.rows.external.find(tableId, _id) const response = await handleRequest(Operation.UPDATE, tableId, { id: breakRowIdField(_id), @@ -69,9 +67,7 @@ export async function patch(ctx: UserCtx) { // The id might have been changed, so the refetching would fail. Recalculating the id just in case const updatedId = generateIdForRow({ ...beforeRow, ...dataToUpdate }, table) || _id - const row = await sdk.rows.external.getRow(tableId, updatedId, { - relationships: true, - }) + const row = await sdk.rows.external.find(tableId, updatedId) const [enrichedRow, oldRow] = await Promise.all([ outputProcessing(table, row, { @@ -92,25 +88,6 @@ export async function patch(ctx: UserCtx) { } } -export async function find(ctx: UserCtx): Promise { - const id = ctx.params.rowId - const tableId = utils.getTableId(ctx) - const row = await sdk.rows.external.getRow(tableId, id, { - relationships: true, - }) - - if (!row) { - ctx.throw(404) - } - - const table = await sdk.tables.getTable(tableId) - // Preserving links, as the outputProcessing does not support external rows yet and we don't need it in this use case - return await outputProcessing(table, row, { - squash: true, - preserveLinks: true, - }) -} - export async function destroy(ctx: UserCtx) { const tableId = utils.getTableId(ctx) const _id = ctx.request.body._id diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 760b73f404..f3165f7f86 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -117,7 +117,9 @@ export async function fetch(ctx: any) { export async function find(ctx: UserCtx) { const tableId = utils.getTableId(ctx) - ctx.body = await pickApi(tableId).find(ctx) + const rowId = ctx.params.rowId + + ctx.body = await sdk.rows.find(tableId, rowId) } function isDeleteRows(input: any): input is DeleteRows { @@ -278,7 +280,8 @@ export async function downloadAttachment(ctx: UserCtx) { const { columnName } = ctx.params const tableId = utils.getTableId(ctx) - const row = await pickApi(tableId).find(ctx) + const rowId = ctx.params.rowId + const row = await sdk.rows.find(tableId, rowId) const table = await sdk.tables.getTable(tableId) const columnSchema = table.schema[columnName] diff --git a/packages/server/src/api/controllers/row/internal.ts b/packages/server/src/api/controllers/row/internal.ts index fe09526c33..b2982a3542 100644 --- a/packages/server/src/api/controllers/row/internal.ts +++ b/packages/server/src/api/controllers/row/internal.ts @@ -96,15 +96,6 @@ export async function patch(ctx: UserCtx) { return { ...result, oldRow } } -export async function find(ctx: UserCtx): Promise { - const tableId = utils.getTableId(ctx), - rowId = ctx.params.rowId - const table = await sdk.tables.getTable(tableId) - let row = await utils.findRow(tableId, rowId) - row = await outputProcessing(table, row) - return row -} - export async function destroy(ctx: UserCtx) { const db = context.getAppDB() const tableId = utils.getTableId(ctx) diff --git a/packages/server/src/sdk/app/rows/external.ts b/packages/server/src/sdk/app/rows/external.ts index 7ad5ea37ff..dc1e368f41 100644 --- a/packages/server/src/sdk/app/rows/external.ts +++ b/packages/server/src/sdk/app/rows/external.ts @@ -9,7 +9,7 @@ import { import cloneDeep from "lodash/fp/cloneDeep" import isEqual from "lodash/fp/isEqual" -export async function getRow( +async function getRow( tableId: string, rowId: string, opts?: { relationships?: boolean } @@ -53,7 +53,7 @@ export async function save( const rowId = response.row._id if (rowId) { - const row = await sdk.rows.external.getRow(tableId, rowId, { + const row = await getRow(tableId, rowId, { relationships: true, }) return { @@ -67,3 +67,16 @@ export async function save( return response } } + +export async function find(tableId: string, rowId: string): Promise { + const row = await getRow(tableId, rowId, { + relationships: true, + }) + + const table = await sdk.tables.getTable(tableId) + // Preserving links, as the outputProcessing does not support external rows yet and we don't need it in this use case + return await outputProcessing(table, row, { + squash: true, + preserveLinks: true, + }) +} diff --git a/packages/server/src/sdk/app/rows/internal.ts b/packages/server/src/sdk/app/rows/internal.ts index 14e771b36e..c21d3465a7 100644 --- a/packages/server/src/sdk/app/rows/internal.ts +++ b/packages/server/src/sdk/app/rows/internal.ts @@ -1,10 +1,15 @@ -import { db } from "@budibase/backend-core" +import { context, db } from "@budibase/backend-core" import { Row } from "@budibase/types" import sdk from "../../../sdk" import cloneDeep from "lodash/fp/cloneDeep" import { finaliseRow } from "../../../api/controllers/row/staticFormula" -import { inputProcessing } from "../../../utilities/rowProcessor" +import { + inputProcessing, + outputProcessing, +} from "../../../utilities/rowProcessor" import * as linkRows from "../../../db/linkedRows" +import { InternalTables } from "../../../db/utils" +import { getFullUser } from "../../../utilities/users" export async function save( tableId: string, @@ -47,3 +52,26 @@ export async function save( updateFormula: true, }) } + +export async function find(tableId: string, rowId: string): Promise { + const table = await sdk.tables.getTable(tableId) + let row = await findRow(tableId, rowId) + + row = await outputProcessing(table, row) + return row +} + +async function findRow(tableId: string, rowId: string) { + const db = context.getAppDB() + let row: Row + // TODO remove special user case in future + if (tableId === InternalTables.USER_METADATA) { + row = await getFullUser(rowId) + } else { + row = await db.get(rowId) + } + if (row.tableId !== tableId) { + throw "Supplied tableId does not match the rows tableId" + } + return row +} diff --git a/packages/server/src/sdk/app/rows/rows.ts b/packages/server/src/sdk/app/rows/rows.ts index bfd84a715c..ef03210800 100644 --- a/packages/server/src/sdk/app/rows/rows.ts +++ b/packages/server/src/sdk/app/rows/rows.ts @@ -34,3 +34,7 @@ export async function save( ) { return pickApi(tableId).save(tableId, row, userId) } + +export async function find(tableId: string, rowId: string) { + return pickApi(tableId).find(tableId, rowId) +} From 41698420180a0984e8c97622cb25b6db9be62d76 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 23 Jul 2024 15:22:26 +0200 Subject: [PATCH 11/27] Fix get --- packages/server/src/api/controllers/row/external.ts | 8 ++++++-- packages/server/src/sdk/app/rows/external.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/row/external.ts b/packages/server/src/api/controllers/row/external.ts index 18c88923e0..06013d230c 100644 --- a/packages/server/src/api/controllers/row/external.ts +++ b/packages/server/src/api/controllers/row/external.ts @@ -57,7 +57,9 @@ export async function patch(ctx: UserCtx) { throw { validation: validateResult.errors } } - const beforeRow = await sdk.rows.external.find(tableId, _id) + const beforeRow = await sdk.rows.external.getRow(tableId, _id, { + relationships: true, + }) const response = await handleRequest(Operation.UPDATE, tableId, { id: breakRowIdField(_id), @@ -67,7 +69,9 @@ export async function patch(ctx: UserCtx) { // The id might have been changed, so the refetching would fail. Recalculating the id just in case const updatedId = generateIdForRow({ ...beforeRow, ...dataToUpdate }, table) || _id - const row = await sdk.rows.external.find(tableId, updatedId) + const row = await sdk.rows.external.getRow(tableId, updatedId, { + relationships: true, + }) const [enrichedRow, oldRow] = await Promise.all([ outputProcessing(table, row, { diff --git a/packages/server/src/sdk/app/rows/external.ts b/packages/server/src/sdk/app/rows/external.ts index dc1e368f41..7cf28300ed 100644 --- a/packages/server/src/sdk/app/rows/external.ts +++ b/packages/server/src/sdk/app/rows/external.ts @@ -9,7 +9,7 @@ import { import cloneDeep from "lodash/fp/cloneDeep" import isEqual from "lodash/fp/isEqual" -async function getRow( +export async function getRow( tableId: string, rowId: string, opts?: { relationships?: boolean } From 8a8633b43b981d54b904990c2de34eeeb687c435 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 23 Jul 2024 15:27:35 +0200 Subject: [PATCH 12/27] Fix throwing 404 --- packages/server/src/sdk/app/rows/external.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/server/src/sdk/app/rows/external.ts b/packages/server/src/sdk/app/rows/external.ts index 7cf28300ed..9ab1362606 100644 --- a/packages/server/src/sdk/app/rows/external.ts +++ b/packages/server/src/sdk/app/rows/external.ts @@ -1,4 +1,5 @@ import { IncludeRelationship, Operation, Row } from "@budibase/types" +import { HTTPError } from "@budibase/backend-core" import { handleRequest } from "../../../api/controllers/row/external" import { breakRowIdField } from "../../../integrations/utils" import sdk from "../../../sdk" @@ -73,6 +74,10 @@ export async function find(tableId: string, rowId: string): Promise { relationships: true, }) + if (!row) { + throw new HTTPError("Row not found", 404) + } + const table = await sdk.tables.getTable(tableId) // Preserving links, as the outputProcessing does not support external rows yet and we don't need it in this use case return await outputProcessing(table, row, { From 18777b6fb2f8f34ce526ac4127e9ba27f9c17725 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 23 Jul 2024 14:55:38 +0100 Subject: [PATCH 13/27] Removed explicit bindings prop from draggable list as it was overriding bindings added via the listTypeProps. Updated grid config to use listTypeProps instead --- .../settings/controls/DraggableList/DraggableList.svelte | 2 -- .../GridColumnConfiguration/GridColumnConfiguration.svelte | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/DraggableList/DraggableList.svelte b/packages/builder/src/components/design/settings/controls/DraggableList/DraggableList.svelte index 2bfa7d39fd..0ba7de42c2 100644 --- a/packages/builder/src/components/design/settings/controls/DraggableList/DraggableList.svelte +++ b/packages/builder/src/components/design/settings/controls/DraggableList/DraggableList.svelte @@ -12,7 +12,6 @@ export let listItemKey export let draggable = true export let focus - export let bindings = [] let zoneType = generate() @@ -127,7 +126,6 @@ anchor={anchors[draggableItem.id]} item={draggableItem.item} {...listTypeProps} - {bindings} on:change={onItemChanged} /> diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte index 87a4174e60..17cb171da5 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte @@ -64,7 +64,9 @@ items={columns.sortable} listItemKey={"_id"} listType={FieldSetting} - {bindings} + listTypeProps={{ + bindings, + }} />