Browse Source

Adding mechanism to allow displaying an error on data retrieval for tables.

master
mike12345567 4 years ago
parent
commit
5aea08fdce
  1. 15
      packages/builder/src/components/backend/DataTable/DataTable.svelte
  2. 20
      packages/frontend-core/src/fetch/DataFetch.js
  3. 1
      packages/frontend-core/src/fetch/TableFetch.js
  4. 40
      packages/server/src/api/controllers/row/external.js
  5. 1
      packages/server/src/integrations/utils.ts

15
packages/builder/src/components/backend/DataTable/DataTable.svelte

@ -14,7 +14,13 @@
import Table from "./Table.svelte" import Table from "./Table.svelte"
import { TableNames } from "constants" import { TableNames } from "constants"
import CreateEditRow from "./modals/CreateEditRow.svelte" 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 { fetchData } from "@budibase/frontend-core"
import { API } from "api" import { API } from "api"
@ -29,6 +35,13 @@
$: fetch = createFetch(id) $: fetch = createFetch(id)
$: hasCols = checkHasCols(schema) $: hasCols = checkHasCols(schema)
$: hasRows = !!$fetch.rows?.length $: hasRows = !!$fetch.rows?.length
$: showError($fetch.error)
const showError = error => {
if (error) {
notifications.error(error?.message || "Unable to fetch data.")
}
}
const enrichSchema = schema => { const enrichSchema = schema => {
let tempSchema = { ...schema } let tempSchema = { ...schema }

20
packages/frontend-core/src/fetch/DataFetch.js

@ -170,6 +170,7 @@ export default class DataFetch {
rows: page.rows, rows: page.rows,
info: page.info, info: page.info,
cursors: paginate && page.hasNextPage ? [null, page.cursor] : [null], cursors: paginate && page.hasNextPage ? [null, page.cursor] : [null],
error: page.error,
})) }))
} }
@ -182,7 +183,7 @@ export default class DataFetch {
const features = get(this.featureStore) const features = get(this.featureStore)
// Get the actual data // 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 we don't support searching, do a client search
if (!features.supportsSearch) { if (!features.supportsSearch) {
@ -204,6 +205,7 @@ export default class DataFetch {
info, info,
hasNextPage, hasNextPage,
cursor, cursor,
error,
} }
} }
@ -345,8 +347,14 @@ export default class DataFetch {
return return
} }
this.store.update($store => ({ ...$store, loading: true })) this.store.update($store => ({ ...$store, loading: true }))
const { rows, info } = await this.getPage() const { rows, info, error } = await this.getPage()
this.store.update($store => ({ ...$store, rows, info, loading: false })) this.store.update($store => ({
...$store,
rows,
info,
loading: false,
error,
}))
} }
/** /**
@ -386,7 +394,7 @@ export default class DataFetch {
cursor: nextCursor, cursor: nextCursor,
pageNumber: $store.pageNumber + 1, pageNumber: $store.pageNumber + 1,
})) }))
const { rows, info, hasNextPage, cursor } = await this.getPage() const { rows, info, hasNextPage, cursor, error } = await this.getPage()
// Update state // Update state
this.store.update($store => { this.store.update($store => {
@ -400,6 +408,7 @@ export default class DataFetch {
info, info,
cursors, cursors,
loading: false, loading: false,
error,
} }
}) })
} }
@ -421,7 +430,7 @@ export default class DataFetch {
cursor: prevCursor, cursor: prevCursor,
pageNumber: $store.pageNumber - 1, pageNumber: $store.pageNumber - 1,
})) }))
const { rows, info } = await this.getPage() const { rows, info, error } = await this.getPage()
// Update state // Update state
this.store.update($store => { this.store.update($store => {
@ -430,6 +439,7 @@ export default class DataFetch {
rows, rows,
info, info,
loading: false, loading: false,
error,
} }
}) })
} }

1
packages/frontend-core/src/fetch/TableFetch.js

@ -37,6 +37,7 @@ export default class TableFetch extends DataFetch {
return { return {
rows: [], rows: [],
hasNextPage: false, hasNextPage: false,
error,
} }
} }
} }

40
packages/server/src/api/controllers/row/external.js

@ -128,25 +128,35 @@ exports.search = async ctx => {
[params.sort]: direction, [params.sort]: direction,
} }
} }
const rows = await handleRequest(DataSourceOperation.READ, tableId, { try {
filters: query, const rows = await handleRequest(DataSourceOperation.READ, tableId, {
sort,
paginate: paginateObj,
})
let hasNextPage = false
if (paginate && rows.length === limit) {
const nextRows = await handleRequest(DataSourceOperation.READ, tableId, {
filters: query, filters: query,
sort, sort,
paginate: { paginate: paginateObj,
limit: 1,
page: bookmark * limit + 1,
},
}) })
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 () => { exports.validate = async () => {

1
packages/server/src/integrations/utils.ts

@ -224,6 +224,7 @@ function shouldCopySpecialColumn(
FieldTypes.ARRAY, FieldTypes.ARRAY,
FieldTypes.FORMULA, FieldTypes.FORMULA,
] ]
// column has been deleted, remove
if (column && !fetchedColumn) { if (column && !fetchedColumn) {
return false return false
} }

Loading…
Cancel
Save