Skip to content

Commit

Permalink
updated fetch next query for pagination (#1706)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadakchap authored May 12, 2021
1 parent 4cbc78d commit 597a0ed
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ 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);

Expand Down Expand Up @@ -438,37 +446,38 @@ class Browser extends DashboardView {
let className = this.props.params.className;
let source = this.state.relation || className;
let query = queryFromFilters(source, this.state.filters);
if (this.state.ordering !== '-createdAt') {
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') {
// 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 (field === 'objectId' || field === '-objectId') {
comp = this.state.data[this.state.data.length - 1].id;
}
if (field[0] === '-') {
field = field.substr(1);

if (sortDir === '-') {
query.lessThan(field, comp);
ascending = false;
equalityQuery.lessThan('objectId', this.state.data[this.state.data.length - 1].id);
} else {
query.greaterThan(field, comp);
equalityQuery.greaterThan('objectId', this.state.data[this.state.data.length - 1].id);
}
if (field === 'createdAt') {
equalityQuery.greaterThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt'));
} else {
equalityQuery.lessThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt'));
equalityQuery.equalTo(field, comp);
}
equalityQuery.equalTo(field, comp);
query = Parse.Query.or(query, equalityQuery);
if (ascending) {
query.ascending(this.state.ordering);
if (sortDir === '-') {
query.descending(field);
query.addDescending('objectId');
} else {
query.descending(this.state.ordering.substr(1));
query.ascending(field);
query.addAscending('objectId');
}
} else {
query.lessThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt'));
query.addDescending('createdAt');
if (sortDir === '-') {
query.lessThan('objectId', this.state.data[this.state.data.length - 1].id);
query.addDescending('objectId');
} else {
query.greaterThan('objectId', this.state.data[this.state.data.length - 1].id);
query.addAscending('objectId');
}
}
query.limit(MAX_ROWS_FETCHED);
this.excludeFields(query, source);
Expand Down

0 comments on commit 597a0ed

Please sign in to comment.