From 41683c1f6d4b0403f2b4c82a5d75f52bf3b4b523 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 1 Aug 2022 17:40:35 +0100 Subject: [PATCH 1/2] Fix for #6737 - making it so that if a column is deleted externally tables can be re-fetched and this will be fixed. --- packages/server/src/integrations/utils.ts | 2 +- packages/server/yarn.lock | 35 +++++++++++++---------- packages/worker/yarn.lock | 35 +++++++++++++---------- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index 7e4efad84f..e662d83d52 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -225,7 +225,7 @@ function shouldCopySpecialColumn( FieldTypes.FORMULA, ] if (column && !fetchedColumn) { - return true + return false } const fetchedIsNumber = !fetchedColumn || fetchedColumn.type === FieldTypes.NUMBER diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 38ee626c11..f8ad9f58e1 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -1094,12 +1094,12 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@1.1.25": - version "1.1.25" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.1.25.tgz#2ae3de9f2e49c8431de23bd1ce8f8040ab46b7d1" - integrity sha512-t95qEYuxLcl/kzZJ90/D9imuG63IpTPY1f2Wrex6JtvgBYh+jvFh1/t6XDPv0NuSWVd5/OILzX6322pq2ak5GQ== +"@budibase/backend-core@1.1.31": + version "1.1.31" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.1.31.tgz#914283af0928ced36303ad4919e52314a8f68022" + integrity sha512-Uo2CxX87u8Lq5MyYOVAXw/wmawUAAUnWkJ648RR1v8CikjOpOixjIiIwb8fXOr1No2SwD4HjY/V/xZGXCgxilQ== dependencies: - "@budibase/types" "^1.1.25" + "@budibase/types" "^1.1.31" "@techpass/passport-openidconnect" "0.3.2" aws-sdk "2.1030.0" bcrypt "5.0.1" @@ -1177,13 +1177,13 @@ svelte-flatpickr "^3.2.3" svelte-portal "^1.0.0" -"@budibase/pro@1.1.25": - version "1.1.25" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.1.25.tgz#a9fd58b6bd80b9bf523f4e21a32e537b26bb3c92" - integrity sha512-4QvlMW6nqaXIYzpU9iQH54LPFGxdjiQUZGoRfPSdNoj1tKB57iQe0Gz39PopGyzOfVdytAlpJdD22Wfdb378jQ== +"@budibase/pro@1.1.31": + version "1.1.31" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.1.31.tgz#cf2dc86643c52cb5655ffcc0f6a0f18125b032fd" + integrity sha512-Pvjd9DgEArFMe275GTC6q1sPuh/SNp9YPD0ckLkLsuNo3jp8f+FXjj5596dFbOxf7r2+Hg/v+f8tQFeslx1RFQ== dependencies: - "@budibase/backend-core" "1.1.25" - "@budibase/types" "1.1.25" + "@budibase/backend-core" "1.1.31" + "@budibase/types" "1.1.31" node-fetch "^2.6.1" "@budibase/standard-components@^0.9.139": @@ -1204,10 +1204,15 @@ svelte-apexcharts "^1.0.2" svelte-flatpickr "^3.1.0" -"@budibase/types@1.1.25", "@budibase/types@^1.1.25": - version "1.1.25" - resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.25.tgz#4d52ac31368de37500a2ae8f8dc02a662d58d49a" - integrity sha512-K74BqAZiM+4URVvGPXhAVE3r+lLQoQ/LOFY30fAvAOv6WMJsw5r7NpF4m1l7bevPxZ6+ku1q/RnoI9aRGqdLlg== +"@budibase/types@1.1.31": + version "1.1.31" + resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.31.tgz#1bc323261627bdb2db06868a8666877cdd8d2e86" + integrity sha512-Nhv9xO24gWbCyBaLbndmh/uVliPIKGMDiQq/o2mub6gvFa8cMHmHZQ+j34qMxfVaMD3bSLQy5rPJptLxTs2XQg== + +"@budibase/types@^1.1.31": + version "1.1.32" + resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.32.tgz#b03acb9f287457c6ac51afbbf31da9f6e74ae70b" + integrity sha512-/e21ZtIkI/ks16RKQjMtfFUL5P3YQdSJBtqaCPlEiBQkIilFku+lc3GFB5rlvlBYqlzkJuq+ZQFII2oNFyJdYw== "@bull-board/api@3.7.0": version "3.7.0" diff --git a/packages/worker/yarn.lock b/packages/worker/yarn.lock index 54ea03d3b0..28af6fb948 100644 --- a/packages/worker/yarn.lock +++ b/packages/worker/yarn.lock @@ -291,12 +291,12 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@1.1.25": - version "1.1.25" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.1.25.tgz#2ae3de9f2e49c8431de23bd1ce8f8040ab46b7d1" - integrity sha512-t95qEYuxLcl/kzZJ90/D9imuG63IpTPY1f2Wrex6JtvgBYh+jvFh1/t6XDPv0NuSWVd5/OILzX6322pq2ak5GQ== +"@budibase/backend-core@1.1.31": + version "1.1.31" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.1.31.tgz#914283af0928ced36303ad4919e52314a8f68022" + integrity sha512-Uo2CxX87u8Lq5MyYOVAXw/wmawUAAUnWkJ648RR1v8CikjOpOixjIiIwb8fXOr1No2SwD4HjY/V/xZGXCgxilQ== dependencies: - "@budibase/types" "^1.1.25" + "@budibase/types" "^1.1.31" "@techpass/passport-openidconnect" "0.3.2" aws-sdk "2.1030.0" bcrypt "5.0.1" @@ -324,19 +324,24 @@ uuid "8.3.2" zlib "1.0.5" -"@budibase/pro@1.1.25": - version "1.1.25" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.1.25.tgz#a9fd58b6bd80b9bf523f4e21a32e537b26bb3c92" - integrity sha512-4QvlMW6nqaXIYzpU9iQH54LPFGxdjiQUZGoRfPSdNoj1tKB57iQe0Gz39PopGyzOfVdytAlpJdD22Wfdb378jQ== +"@budibase/pro@1.1.31": + version "1.1.31" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.1.31.tgz#cf2dc86643c52cb5655ffcc0f6a0f18125b032fd" + integrity sha512-Pvjd9DgEArFMe275GTC6q1sPuh/SNp9YPD0ckLkLsuNo3jp8f+FXjj5596dFbOxf7r2+Hg/v+f8tQFeslx1RFQ== dependencies: - "@budibase/backend-core" "1.1.25" - "@budibase/types" "1.1.25" + "@budibase/backend-core" "1.1.31" + "@budibase/types" "1.1.31" node-fetch "^2.6.1" -"@budibase/types@1.1.25", "@budibase/types@^1.1.25": - version "1.1.25" - resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.25.tgz#4d52ac31368de37500a2ae8f8dc02a662d58d49a" - integrity sha512-K74BqAZiM+4URVvGPXhAVE3r+lLQoQ/LOFY30fAvAOv6WMJsw5r7NpF4m1l7bevPxZ6+ku1q/RnoI9aRGqdLlg== +"@budibase/types@1.1.31": + version "1.1.31" + resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.31.tgz#1bc323261627bdb2db06868a8666877cdd8d2e86" + integrity sha512-Nhv9xO24gWbCyBaLbndmh/uVliPIKGMDiQq/o2mub6gvFa8cMHmHZQ+j34qMxfVaMD3bSLQy5rPJptLxTs2XQg== + +"@budibase/types@^1.1.31": + version "1.1.32" + resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.32.tgz#b03acb9f287457c6ac51afbbf31da9f6e74ae70b" + integrity sha512-/e21ZtIkI/ks16RKQjMtfFUL5P3YQdSJBtqaCPlEiBQkIilFku+lc3GFB5rlvlBYqlzkJuq+ZQFII2oNFyJdYw== "@cspotcode/source-map-consumer@0.8.0": version "0.8.0" From 5aea08fdced9f785f86cd1905b95dd43eb06e7b3 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 1 Aug 2022 18:56:59 +0100 Subject: [PATCH 2/2] Adding mechanism to allow displaying an error on data retrieval for tables. --- .../backend/DataTable/DataTable.svelte | 15 ++++++- packages/frontend-core/src/fetch/DataFetch.js | 20 +++++++--- .../frontend-core/src/fetch/TableFetch.js | 1 + .../src/api/controllers/row/external.js | 40 ++++++++++++------- packages/server/src/integrations/utils.ts | 1 + 5 files changed, 56 insertions(+), 21 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 1f461ebad3..37742626cd 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -14,7 +14,13 @@ import Table from "./Table.svelte" import { TableNames } from "constants" import CreateEditRow from "./modals/CreateEditRow.svelte" - import { Pagination, Heading, Body, Layout } from "@budibase/bbui" + import { + Pagination, + Heading, + Body, + Layout, + notifications, + } from "@budibase/bbui" import { fetchData } from "@budibase/frontend-core" import { API } from "api" @@ -29,6 +35,13 @@ $: fetch = createFetch(id) $: hasCols = checkHasCols(schema) $: hasRows = !!$fetch.rows?.length + $: showError($fetch.error) + + const showError = error => { + if (error) { + notifications.error(error?.message || "Unable to fetch data.") + } + } const enrichSchema = schema => { let tempSchema = { ...schema } diff --git a/packages/frontend-core/src/fetch/DataFetch.js b/packages/frontend-core/src/fetch/DataFetch.js index ecd5313af5..338e6e0405 100644 --- a/packages/frontend-core/src/fetch/DataFetch.js +++ b/packages/frontend-core/src/fetch/DataFetch.js @@ -170,6 +170,7 @@ export default class DataFetch { rows: page.rows, info: page.info, cursors: paginate && page.hasNextPage ? [null, page.cursor] : [null], + error: page.error, })) } @@ -182,7 +183,7 @@ export default class DataFetch { const features = get(this.featureStore) // Get the actual data - let { rows, info, hasNextPage, cursor } = await this.getData() + let { rows, info, hasNextPage, cursor, error } = await this.getData() // If we don't support searching, do a client search if (!features.supportsSearch) { @@ -204,6 +205,7 @@ export default class DataFetch { info, hasNextPage, cursor, + error, } } @@ -345,8 +347,14 @@ export default class DataFetch { return } this.store.update($store => ({ ...$store, loading: true })) - const { rows, info } = await this.getPage() - this.store.update($store => ({ ...$store, rows, info, loading: false })) + const { rows, info, error } = await this.getPage() + this.store.update($store => ({ + ...$store, + rows, + info, + loading: false, + error, + })) } /** @@ -386,7 +394,7 @@ export default class DataFetch { cursor: nextCursor, pageNumber: $store.pageNumber + 1, })) - const { rows, info, hasNextPage, cursor } = await this.getPage() + const { rows, info, hasNextPage, cursor, error } = await this.getPage() // Update state this.store.update($store => { @@ -400,6 +408,7 @@ export default class DataFetch { info, cursors, loading: false, + error, } }) } @@ -421,7 +430,7 @@ export default class DataFetch { cursor: prevCursor, pageNumber: $store.pageNumber - 1, })) - const { rows, info } = await this.getPage() + const { rows, info, error } = await this.getPage() // Update state this.store.update($store => { @@ -430,6 +439,7 @@ export default class DataFetch { rows, info, loading: false, + error, } }) } diff --git a/packages/frontend-core/src/fetch/TableFetch.js b/packages/frontend-core/src/fetch/TableFetch.js index cf0e124020..a13b1bd186 100644 --- a/packages/frontend-core/src/fetch/TableFetch.js +++ b/packages/frontend-core/src/fetch/TableFetch.js @@ -37,6 +37,7 @@ export default class TableFetch extends DataFetch { return { rows: [], hasNextPage: false, + error, } } } diff --git a/packages/server/src/api/controllers/row/external.js b/packages/server/src/api/controllers/row/external.js index b1c322b8b6..c9f6aa2f78 100644 --- a/packages/server/src/api/controllers/row/external.js +++ b/packages/server/src/api/controllers/row/external.js @@ -128,25 +128,35 @@ exports.search = async ctx => { [params.sort]: direction, } } - const rows = await handleRequest(DataSourceOperation.READ, tableId, { - filters: query, - sort, - paginate: paginateObj, - }) - let hasNextPage = false - if (paginate && rows.length === limit) { - const nextRows = await handleRequest(DataSourceOperation.READ, tableId, { + try { + const rows = await handleRequest(DataSourceOperation.READ, tableId, { filters: query, sort, - paginate: { - limit: 1, - page: bookmark * limit + 1, - }, + paginate: paginateObj, }) - hasNextPage = nextRows.length > 0 + let hasNextPage = false + if (paginate && rows.length === limit) { + const nextRows = await handleRequest(DataSourceOperation.READ, tableId, { + filters: query, + sort, + paginate: { + limit: 1, + page: bookmark * limit + 1, + }, + }) + hasNextPage = nextRows.length > 0 + } + // need wrapper object for bookmarks etc when paginating + return { rows, hasNextPage, bookmark: bookmark + 1 } + } catch (err) { + if (err.message && err.message.includes("does not exist")) { + throw new Error( + `Table updated externally, please re-fetch - ${err.message}` + ) + } else { + throw err + } } - // need wrapper object for bookmarks etc when paginating - return { rows, hasNextPage, bookmark: bookmark + 1 } } exports.validate = async () => { diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index e662d83d52..a0f2b764bc 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -224,6 +224,7 @@ function shouldCopySpecialColumn( FieldTypes.ARRAY, FieldTypes.FORMULA, ] + // column has been deleted, remove if (column && !fetchedColumn) { return false }