frontend:table: fix the rows-per-page settings persist among views#4668
frontend:table: fix the rows-per-page settings persist among views#4668ChayanDass wants to merge 1 commit intokubernetes-sigs:mainfrom
Conversation
|
HI @illume .. I think we can remove const storeRowsPerPageOptions = useSettings('tableRowsPerPageOptions');
const rowsPerPageOptions = rowsPerPage || storeRowsPerPageOptions;
const defaultRowsPerPage = getTablesRowsPerPage(rowsPerPageOptions[0]);Also, we can set |
3205aa6 to
1350b80
Compare
|
I removed unnecessary useMemo usage and now pass reflectInURL from parent components. I also noticed that perPage is omitted from the URL when it matches the local default, but defaults can differ between users(if the perpage value already updated and stored in localstorage). This can cause shared links to render different table views, so it may be better to always include perPage in the URL when URL reflection is enabled. |
c6eb8bd to
cc98748
Compare
illume
left a comment
There was a problem hiding this comment.
If you want, you could improve the git message subject body. By including some of the explanation from the PR description and your comment.
illume
left a comment
There was a problem hiding this comment.
Can you please add some steps to test in the PR description?
There was a problem hiding this comment.
Pull request overview
This PR adds persistent rows-per-page functionality to tables by storing the selected value in localStorage. When users change the number of rows displayed, their preference is saved using the tables_rows_per_page key and automatically restored on future page visits. The implementation uses new helper functions getTablesRowsPerPage and setTablesRowsPerPage to manage localStorage operations.
Changes:
- Added localStorage persistence for rows per page using helper functions
- Modified Table component to call setTablesRowsPerPage when pagination changes
- Removed useMemo optimizations from defaultRowsPerPage, initialState, and state objects
- Changed ResourceTable default reflectInURL value to always enable URL reflection when id is present
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| frontend/src/components/common/Table/Table.tsx | Added localStorage persistence call in onPaginationChange; modified URL state handling to always use 'perPage' key; removed useMemo optimizations |
| frontend/src/components/common/Resource/ResourceTable.tsx | Changed default reflectInURL from undefined to template literal using id |
| frontend/src/components/common/Table/snapshots/Table.ReflectInURL.stories.storyshot | Updated snapshot to include perPage=5 parameter in URL |
| frontend/src/components/common/Table/snapshots/Table.ReflectInURLWithPrefix.stories.storyshot | Updated snapshot to include mySuperTable.perPage=5 parameter in URL |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cc98748 to
dc1c1a2
Compare
|
updated, PTAL! |
|
nit, you could fix the first letter of the subject after the context to be capitalized. Also add some of the Changes part of the PR description into the git message body, and any Why you can think of that may help people.
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ChayanDass, illume The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
5e84142 to
1d4f3e7
Compare
- Persist rows-per-page in localStorage (key tables_rows_per_page) when the user changes it; value is restored on reload or when switching views/tabs. - Call setTablesRowsPerPage on pagination change so the preference is saved from the main Table component. - Default page size to lowest option (storeRowsPerPageOptions[0]); remove getTablesRowsPerPage useMemo and unused import from Table. - ResourceTable: default reflectInURL to true (no prefix) so page/perPage in the URL stay short; using the table id would make the URL too long. Why: Users expect their chosen table density to persist across reloads and navigation; storing the value in localStorage avoids losing the selection and keeps the UI consistent.
1d4f3e7 to
c8b8fe2
Compare
|
updated, Thanks! |
Summary
This PR adds persistent rows per page functionality to tables by storing the selected rows per page value in localStorage . Users can now change the number of rows displayed per page, and their preference is automatically saved and restored on page refresh.
Related Issue
Fixes #3227
Changes
tables_rows_per_page.useMemofor fetchinggetTablesRowsPerPageperPagevalue in the URL to match thestoreRowsPerPageOptions[0]value, ensuring shared links reflect the actual table state.Steps to Test
Note: We should avoid using an id for
reflectInURL, as it makes the URL unnecessarily long, for example:http://localhost:3000/c/minikube/?headlamp-cluster.overview.events.perPage=25&headlamp-cluster.overview.events.p=3