Ensure paginate option is respected in DataFetch models

This commit is contained in:
Andrew Kingston 2022-01-07 11:30:47 +00:00
parent ee2a3515e8
commit 8bebf8db01
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 * Fetches a fresh set of data from the server, resetting pagination
*/ */
async getInitialData() { async getInitialData() {
const { datasource, filter, sortColumn } = this.options const { datasource, filter, sortColumn, paginate } = this.options
const tableId = datasource?.tableId const tableId = datasource?.tableId
// Ensure table ID exists // Ensure table ID exists
@ -124,7 +124,7 @@ export default class DataFetch {
this.featureStore.set({ this.featureStore.set({
supportsSearch: !!features?.supportsSearch, supportsSearch: !!features?.supportsSearch,
supportsSort: !!features?.supportsSort, supportsSort: !!features?.supportsSort,
supportsPagination: !!features?.supportsPagination, supportsPagination: paginate && !!features?.supportsPagination,
}) })
// Fetch and enrich schema // Fetch and enrich schema
@ -168,7 +168,7 @@ export default class DataFetch {
pageNumber: 0, pageNumber: 0,
rows: page.rows, rows: page.rows,
info: page.info, 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() { async getData() {
const { datasource, limit } = this.options const { datasource, limit, paginate } = this.options
const { supportsPagination } = get(this.featureStore) const { supportsPagination } = get(this.featureStore)
const { cursor, definition } = get(this.store) const { cursor, definition } = get(this.store)
const { type } = definition.fields.pagination const { type } = definition.fields.pagination
@ -35,7 +35,7 @@ export default class QueryFetch extends DataFetch {
// Add pagination to query if supported // Add pagination to query if supported
let queryPayload = { queryId: datasource?._id, parameters } let queryPayload = { queryId: datasource?._id, parameters }
if (supportsPagination) { if (paginate && supportsPagination) {
const requestCursor = type === "page" ? parseInt(cursor || 1) : cursor const requestCursor = type === "page" ? parseInt(cursor || 1) : cursor
queryPayload.pagination = { page: requestCursor, limit } queryPayload.pagination = { page: requestCursor, limit }
} }
@ -46,7 +46,7 @@ export default class QueryFetch extends DataFetch {
// Derive pagination info from response // Derive pagination info from response
let nextCursor = null let nextCursor = null
let hasNextPage = false let hasNextPage = false
if (supportsPagination) { if (paginate && supportsPagination) {
if (type === "page") { if (type === "page") {
// For "page number" pagination, increment the existing page number // For "page number" pagination, increment the existing page number
nextCursor = queryPayload.pagination.page + 1 nextCursor = queryPayload.pagination.page + 1