Skip to content

Commit

Permalink
🐛 Fix pagination effects - for client tables, use filteredItems ins…
Browse files Browse the repository at this point in the history
…tead of `items` length for `totalItemCount` (#1625)

Made the same fix in the new react-table-batteries code as well. Note to
self: Perhaps we should rename the `totalItemCount` to
`filteredItemCount` in the new version, since it really should be the
count of all items just before pagination (after filtering), not the
total number of items in the unfiltered collection.

For client-side tables, the `totalItemCount` is derived internally
inside `getLocalTableControlDerivedState`, and it was incorrectly using
`items.length`. Changing that to `filteredItems.length` makes the logic
in `usePaginationEffects` behave as intended, which means if the user
ends up on an invalid pagination page (e.g. they are on page 2 and they
apply a filter that has results on one page), it will kick them back to
the last valid page.

cc @ibolton336 

<!--
## PR Title Prefix

Every **PR Title** should be prefixed with :text: to indicate its type.

- Breaking change: ⚠️ (`⚠️`)
- Non-breaking feature: ✨ (`✨`)
- Patch fix: 🐛 (`🐛`)
- Docs: 📖 (`📖`)
- Infra/Tests/Other: 🌱 (`🌱`)
- No release note: 👻 (`👻`)

For example, a pull request containing breaking changes might look like
`⚠️ My pull request contains breaking changes`.

Since GitHub supports emoji aliases (ie. `👻`), there is no need to
include
the emoji directly in the PR title -- **please use the alias**. It used
to be
the case that projects using emojis for PR typing had to include the
emoji
directly because GitHub didn't render the alias. Given that `⚠️`
is
easy enough to read as text, easy to parse in release tooling, and
rendered in
GitHub well, we prefer to standardize on the alias.

For more information, please see the Konveyor
[Versioning
Doc](https://github.com/konveyor/release-tools/blob/main/VERSIONING.md).
-->

Signed-off-by: Mike Turley <[email protected]>
Co-authored-by: Ian Bolton <[email protected]>
  • Loading branch information
mturley and ibolton336 authored Dec 15, 2023
1 parent 469e0b1 commit 045cc71
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const getLocalTableControlDerivedState = <
items: sortedItems,
});
return {
totalItemCount: items.length,
totalItemCount: filteredItems.length,
currentPageItems: isPaginationEnabled ? currentPageItems : sortedItems,
};
};
2 changes: 1 addition & 1 deletion client/src/app/hooks/table-controls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export type ITableControlDerivedState<TItem> = {
*/
currentPageItems: TItem[];
/**
* The total number of items in the entire un-filtered, un-paginated table (the size of the entire API collection being tabulated).
* The total number of items after filtering but before pagination.
*/
totalItemCount: number;
};
Expand Down

0 comments on commit 045cc71

Please sign in to comment.