From ce9feed5f2a9f5e240a93cf8b636fba78542c4d5 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 17 Nov 2022 14:15:24 +0000 Subject: [PATCH] Ensure all search requests specify a sort field to avoid random sorting --- packages/frontend-core/src/fetch/DataFetch.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/frontend-core/src/fetch/DataFetch.js b/packages/frontend-core/src/fetch/DataFetch.js index 31007121f1..37e300e354 100644 --- a/packages/frontend-core/src/fetch/DataFetch.js +++ b/packages/frontend-core/src/fetch/DataFetch.js @@ -117,7 +117,7 @@ export default class DataFetch { * Fetches a fresh set of data from the server, resetting pagination */ async getInitialData() { - const { datasource, filter, sortColumn, paginate } = this.options + const { datasource, filter, paginate } = this.options // Fetch datasource definition and determine feature flags const definition = await this.getDefinition(datasource) @@ -135,6 +135,17 @@ export default class DataFetch { return } + // If no sort order, default to descending + if (!this.options.sortOrder) { + this.options.sortOrder = "ascending" + } + + // If no sort column, use the first field in the schema + if (!this.options.sortColumn) { + this.options.sortColumn = Object.keys(schema)[0] + } + const { sortColumn } = this.options + // Determine what sort type to use let sortType = "string" if (sortColumn) {