From 8bebf8db017fb7b2cd33f165e0aa4cef74d4fdaa Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 7 Jan 2022 11:30:47 +0000 Subject: [PATCH] Ensure paginate option is respected in DataFetch models --- packages/client/src/utils/fetch/DataFetch.js | 6 +++--- packages/client/src/utils/fetch/QueryFetch.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/client/src/utils/fetch/DataFetch.js b/packages/client/src/utils/fetch/DataFetch.js index f56e50dde6..2333991ac9 100644 --- a/packages/client/src/utils/fetch/DataFetch.js +++ b/packages/client/src/utils/fetch/DataFetch.js @@ -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], })) } diff --git a/packages/client/src/utils/fetch/QueryFetch.js b/packages/client/src/utils/fetch/QueryFetch.js index 4e7067a694..6f1418f3bd 100644 --- a/packages/client/src/utils/fetch/QueryFetch.js +++ b/packages/client/src/utils/fetch/QueryFetch.js @@ -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