Skip to content

Commit

Permalink
fix: items per page would not correctly work on some page change (#1801)
Browse files Browse the repository at this point in the history
* bugfix/AB#74313_ABC-items-per-page-is-not-working-correctly-on-page-size-change refactor: use the fetch functions for each table data in order to fix the current bug refactor: update data load flow and naming of properties in order to match common syntax for all tables containing data and pagination

* bugfix/AB#74313_ABC-items-per-page-is-not-working-correctly-on-page-size-change refactor: delete out of place loading property value set
  • Loading branch information
unai-reliefapp committed Sep 7, 2023
1 parent cee7aa0 commit 063391d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,13 @@ export class ApiConfigurationsComponent
) {
// Sets the new fetch quantity of data needed as the page size
// If the fetch is for a new page the page size is used
let neededSize = e.pageSize;
let first = e.pageSize;
// If the fetch is for a new page size, the old page size is subtracted from the new one
if (e.pageSize > this.pageInfo.pageSize) {
neededSize -= this.pageInfo.pageSize;
}
this.loading = true;
const variables = {
first: neededSize,
afterCursor: this.pageInfo.endCursor,
};
const cachedValues: GetApiConfigurationsQueryResponse = getCachedValues(
this.apollo.client,
GET_API_CONFIGURATIONS,
variables
);
if (cachedValues) {
this.updateValues(cachedValues, false);
} else {
this.apiConfigurationsQuery
.fetchMore({ variables })
.then(
(results: ApolloQueryResult<GetApiConfigurationsQueryResponse>) => {
this.updateValues(results.data, results.loading);
}
);
first -= this.pageInfo.pageSize;
}
this.pageInfo.pageSize = first;
this.fetchApiConfigurations();
} else {
this.dataSource = this.cachedApiConfigurations.slice(
e.pageSize * this.pageInfo.pageIndex,
Expand Down Expand Up @@ -371,6 +352,7 @@ export class ApiConfigurationsComponent
* @param refetch erase previous query results
*/
private fetchApiConfigurations(refetch?: boolean): void {
this.loading = true;
const variables = {
first: this.pageInfo.pageSize,
afterCursor: refetch ? null : this.pageInfo.endCursor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,13 @@ export class ReferenceDatasComponent
) {
// Sets the new fetch quantity of data needed as the page size
// If the fetch is for a new page the page size is used
let neededSize = e.pageSize;
let first = e.pageSize;
// If the fetch is for a new page size, the old page size is substracted from the new one
if (e.pageSize > this.pageInfo.pageSize) {
neededSize -= this.pageInfo.pageSize;
}
this.loading = true;
const variables = {
first: neededSize,
afterCursor: this.pageInfo.endCursor,
};
const cachedValues: GetReferenceDatasQueryResponse = getCachedValues(
this.apollo.client,
GET_REFERENCE_DATAS,
variables
);
if (cachedValues) {
this.updateValues(cachedValues, false);
} else {
this.referenceDatasQuery
.fetchMore({ variables })
.then((results) => this.updateValues(results.data, results.loading));
first -= this.pageInfo.pageSize;
}
this.pageInfo.pageSize = first;
this.fetchReferenceDatas();
} else {
this.dataSource = this.cachedReferenceDatas.slice(
e.pageSize * this.pageInfo.pageIndex,
Expand Down Expand Up @@ -341,6 +326,7 @@ export class ReferenceDatasComponent
* @param refetch erase previous query results
*/
private fetchReferenceDatas(refetch?: boolean): void {
this.loading = true;
const variables = {
first: this.pageInfo.pageSize,
afterCursor: refetch ? null : this.pageInfo.endCursor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export class ResourcesComponent
first -= this.pageInfo.pageSize;
}
this.pageInfo.pageSize = first;
this.loading = true;
this.fetchResources();
} else {
this.resources = this.cachedResources.slice(
Expand Down

0 comments on commit 063391d

Please sign in to comment.