From 65c5aefe0fca7f6d348fc7b4959c64c954e6ac6b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 2 May 2024 12:51:21 +0100 Subject: [PATCH] Fix issue where IDs were stripped from rows in grids that were using a link datasource --- .../grid/overlays/MenuOverlay.svelte | 6 +++--- .../src/components/grid/stores/datasource.js | 6 +++--- .../src/components/grid/stores/rows.js | 19 +++++++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/frontend-core/src/components/grid/overlays/MenuOverlay.svelte b/packages/frontend-core/src/components/grid/overlays/MenuOverlay.svelte index 13430a3f7d..b11d42f52d 100644 --- a/packages/frontend-core/src/components/grid/overlays/MenuOverlay.svelte +++ b/packages/frontend-core/src/components/grid/overlays/MenuOverlay.svelte @@ -18,7 +18,7 @@ focusedCellAPI, focusedRowId, notifications, - isDatasourcePlus, + hasBudibaseIdentifiers, } = getContext("grid") let anchor @@ -82,7 +82,7 @@ copyToClipboard($focusedRow?._id)} on:click={menu.actions.close} > @@ -90,7 +90,7 @@ copyToClipboard($focusedRow?._rev)} on:click={menu.actions.close} > diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 7b95fe7430..b3584d5ad4 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -75,14 +75,14 @@ export const deriveStores = context => { } ) - const isDatasourcePlus = derived(datasource, $datasource => { - return ["table", "viewV2"].includes($datasource?.type) + const hasBudibaseIdentifiers = derived(datasource, $datasource => { + return ["table", "viewV2", "link"].includes($datasource?.type) }) return { schema, enrichedSchema, - isDatasourcePlus, + hasBudibaseIdentifiers, } } diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.js index fc941ecc7f..6193b59d1d 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -83,7 +83,7 @@ export const createActions = context => { error, notifications, fetch, - isDatasourcePlus, + hasBudibaseIdentifiers, refreshing, } = context const instanceLoaded = writable(false) @@ -196,9 +196,16 @@ export const createActions = context => { // Handles validation errors from the rows API and updates local validation // state, storing error messages against relevant cells const handleValidationError = (rowId, error) => { + let errorString + if (typeof error === "string") { + errorString = error + } else if (typeof error?.message === "string") { + errorString = error.message + } + // If the server doesn't reply with a valid error, assume that the source // of the error is the focused cell's column - if (!error?.json?.validationErrors && error?.message) { + if (!error?.json?.validationErrors && errorString) { const focusedColumn = get(focusedCellId)?.split("-")[1] if (focusedColumn) { error = { @@ -261,7 +268,7 @@ export const createActions = context => { focusedCellId.set(`${rowId}-${erroredColumns[0]}`) } } else { - get(notifications).error(error?.message || "An unknown error occurred") + get(notifications).error(errorString || "An unknown error occurred") } } @@ -458,14 +465,14 @@ export const createActions = context => { } let rowsToAppend = [] let newRow - const $isDatasourcePlus = get(isDatasourcePlus) + const $hasBudibaseIdentifiers = get(hasBudibaseIdentifiers) for (let i = 0; i < newRows.length; i++) { newRow = newRows[i] // Ensure we have a unique _id. // This means generating one for non DS+, overwriting any that may already // exist as we cannot allow duplicates. - if (!$isDatasourcePlus) { + if (!$hasBudibaseIdentifiers) { newRow._id = Helpers.uuid() } @@ -510,7 +517,7 @@ export const createActions = context => { const cleanRow = row => { let clone = { ...row } delete clone.__idx - if (!get(isDatasourcePlus)) { + if (!get(hasBudibaseIdentifiers)) { delete clone._id } return clone