Skip to content

Commit

Permalink
Fixed Admin UI to use offset and filter mutually exclusively dependin…
Browse files Browse the repository at this point in the history
…g on comparison flag
  • Loading branch information
mackcheesman committed Feb 7, 2025
1 parent 693ec53 commit 9deb397
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ export const EntityList = <TData extends object>() => {

const handleFetchNextPage = async () => {
const nextPage = Math.ceil((data?.result.length ?? 0) / PAGE_SIZE);
const offset = providerComparisonSupported ? 0 : nextPage * PAGE_SIZE;

const filterVar = variables.filter ?? {};
const filter = providerComparisonSupported ? addStabilizationToFilter(filterVar, sort, data?.result?.[data.result.length - 1]) : filterVar;
fetchMore({
variables: {
...variables,
pagination: {
...variables.pagination,
offset: nextPage * PAGE_SIZE,
offset
},
filter: providerComparisonSupported ? variables.filter ?? {} : addStabilizationToFilter(variables.filter ?? {}, sort, data?.result?.[0]),
filter
},
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/packages/apollo-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const generateTypePolicies = (entities: Entity[]) => {
export const addStabilizationToFilter = <TData>(
filter: Record<string, unknown>,
sort: SortEntity,
firstElement: TData
lastElement: TData
) => {
const filters = {
...filter,
Expand All @@ -98,7 +98,7 @@ export const addStabilizationToFilter = <TData>(

filters[stabilizationKeys] = filters[stabilizationKeys] ?? [];
filters[stabilizationKeys].push(`${key}_${operationKey}`);
filters[`${key}_${operationKey}`] = firstElement[key as keyof TData];
filters[`${key}_${operationKey}`] = lastElement[key as keyof TData];
}

return filters;
Expand Down

0 comments on commit 9deb397

Please sign in to comment.