From 25178d430e98a5a67c3f7eb955cbc722e307d3c1 Mon Sep 17 00:00:00 2001 From: christopherbrookes Date: Thu, 16 Sep 2021 00:35:42 +0200 Subject: [PATCH] feat: revert PR#1706 on scroll sorting --- CHANGELOG.md | 3 +- src/dashboard/Data/Browser/Browser.react.js | 49 +++++++++------------ 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c86214bada..db70dc4581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,13 +8,14 @@ ## Improvements - Update sass to 5.0.0 and make docker image use node:lts-alpine (Corey Baker) [#1792](https://github.com/parse-community/parse-dashboard/pull/1792) -- Docker image use now node 12 version [#1788](https://github.com/parse-community/parse-dashboard/pull/1788) +- Docker image use now node 12 version (Christopher Brookes) [#1788](https://github.com/parse-community/parse-dashboard/pull/1788) - CI now pushes docker images to Docker Hub (Corey Baker) [#1781](https://github.com/parse-community/parse-dashboard/pull/1781) - Add CI check to add changelog entry (Manuel Trezza) [#1764](https://github.com/parse-community/parse-dashboard/pull/1764) - Refactor: uniform issue templates across repos (Manuel Trezza) [#1767](https://github.com/parse-community/parse-dashboard/pull/1767) - fix: date cell value not selected on double clicks (fn-faisal) [#1730](https://github.com/parse-community/parse-dashboard/pull/1730) ## Fixes +- Revert PR [#1706](https://github.com/parse-community/parse-dashboard/pull/1706) on new default sorting columns on initial load and pagination (It could lead to performance issues without new database indices (Christopher Brookes) [#1798](https://github.com/parse-community/parse-dashboard/pull/1798) - Fixed bug after creating new class, wrong CLP was shown for that class [#1784](https://github.com/parse-community/parse-dashboard/issues/1784) (Prerna Mehra) [#1785](https://github.com/parse-community/parse-dashboard/pull/1785) - Fixed bug when opening a big modal, modal content is not visible due to Sidebar (Prerna Mehra) [#1777](https://github.com/parse-community/parse-dashboard/pull/1778) - Fixed UI for a field containing an array of pointers (Prerna Mehra) [#1776](https://github.com/parse-community/parse-dashboard/pull/1776) diff --git a/src/dashboard/Data/Browser/Browser.react.js b/src/dashboard/Data/Browser/Browser.react.js index f02436c3d0..cafc17921f 100644 --- a/src/dashboard/Data/Browser/Browser.react.js +++ b/src/dashboard/Data/Browser/Browser.react.js @@ -647,14 +647,6 @@ class Browser extends DashboardView { query.ascending(field) } - if (field !== 'objectId') { - if (sortDir === '-') { - query.addDescending('objectId'); - } else { - query.addAscending('objectId'); - } - } - query.limit(MAX_ROWS_FETCHED); this.excludeFields(query, source); @@ -732,38 +724,37 @@ class Browser extends DashboardView { let className = this.props.params.className; let source = this.state.relation || className; let query = queryFromFilters(source, this.state.filters); - let field = this.state.ordering; - let sortDir = field[0] === '-' ? '-' : '+'; - field = field[0] === '-' ? field.slice(1) : field; - if (this.state.ordering !== '-objectId' && this.state.ordering !== 'objectId') { + if (this.state.ordering !== '-createdAt') { // Construct complex pagination query let equalityQuery = queryFromFilters(source, this.state.filters); + let field = this.state.ordering; + let ascending = true; let comp = this.state.data[this.state.data.length - 1].get(field); - - if (sortDir === '-') { + if (field === 'objectId' || field === '-objectId') { + comp = this.state.data[this.state.data.length - 1].id; + } + if (field[0] === '-') { + field = field.substr(1); query.lessThan(field, comp); - equalityQuery.lessThan('objectId', this.state.data[this.state.data.length - 1].id); + ascending = false; } else { query.greaterThan(field, comp); - equalityQuery.greaterThan('objectId', this.state.data[this.state.data.length - 1].id); } - equalityQuery.equalTo(field, comp); - query = Parse.Query.or(query, equalityQuery); - if (sortDir === '-') { - query.descending(field); - query.addDescending('objectId'); + if (field === 'createdAt') { + equalityQuery.greaterThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt')); } else { - query.ascending(field); - query.addAscending('objectId'); + equalityQuery.lessThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt')); + equalityQuery.equalTo(field, comp); } - } else { - if (sortDir === '-') { - query.lessThan('objectId', this.state.data[this.state.data.length - 1].id); - query.addDescending('objectId'); + query = Parse.Query.or(query, equalityQuery); + if (ascending) { + query.ascending(this.state.ordering); } else { - query.greaterThan('objectId', this.state.data[this.state.data.length - 1].id); - query.addAscending('objectId'); + query.descending(this.state.ordering.substr(1)); } + } else { + query.lessThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt')); + query.addDescending('createdAt'); } query.limit(MAX_ROWS_FETCHED); this.excludeFields(query, source);