Adding mechanism to allow displaying an error on data retrieval for tables.
This commit is contained in:
parent
41683c1f6d
commit
5aea08fdce
|
@ -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 }
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ export default class TableFetch extends DataFetch {
|
|||
return {
|
||||
rows: [],
|
||||
hasNextPage: false,
|
||||
error,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
|
@ -224,6 +224,7 @@ function shouldCopySpecialColumn(
|
|||
FieldTypes.ARRAY,
|
||||
FieldTypes.FORMULA,
|
||||
]
|
||||
// column has been deleted, remove
|
||||
if (column && !fetchedColumn) {
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue