1
0
Fork 0
mirror of synced 2024-10-03 19:43:32 +13:00

Ensure paginate option is respected in DataFetch models

This commit is contained in:
Andrew Kingston 2022-01-07 11:30:47 +00:00
parent e187e8f2b1
commit 53b601ec9b
2 changed files with 6 additions and 6 deletions

View file

@ -110,7 +110,7 @@ export default class DataFetch {
* Fetches a fresh set of data from the server, resetting pagination
*/
async getInitialData() {
const { datasource, filter, sortColumn } = this.options
const { datasource, filter, sortColumn, paginate } = this.options
const tableId = datasource?.tableId
// Ensure table ID exists
@ -124,7 +124,7 @@ export default class DataFetch {
this.featureStore.set({
supportsSearch: !!features?.supportsSearch,
supportsSort: !!features?.supportsSort,
supportsPagination: !!features?.supportsPagination,
supportsPagination: paginate && !!features?.supportsPagination,
})
// Fetch and enrich schema
@ -168,7 +168,7 @@ export default class DataFetch {
pageNumber: 0,
rows: page.rows,
info: page.info,
cursors: page.hasNextPage ? [null, page.cursor] : [null],
cursors: paginate && page.hasNextPage ? [null, page.cursor] : [null],
}))
}

View file

@ -20,7 +20,7 @@ export default class QueryFetch extends DataFetch {
}
async getData() {
const { datasource, limit } = this.options
const { datasource, limit, paginate } = this.options
const { supportsPagination } = get(this.featureStore)
const { cursor, definition } = get(this.store)
const { type } = definition.fields.pagination
@ -35,7 +35,7 @@ export default class QueryFetch extends DataFetch {
// Add pagination to query if supported
let queryPayload = { queryId: datasource?._id, parameters }
if (supportsPagination) {
if (paginate && supportsPagination) {
const requestCursor = type === "page" ? parseInt(cursor || 1) : cursor
queryPayload.pagination = { page: requestCursor, limit }
}
@ -46,7 +46,7 @@ export default class QueryFetch extends DataFetch {
// Derive pagination info from response
let nextCursor = null
let hasNextPage = false
if (supportsPagination) {
if (paginate && supportsPagination) {
if (type === "page") {
// For "page number" pagination, increment the existing page number
nextCursor = queryPayload.pagination.page + 1