-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGrid] Fix overflow of maximum page #1583
Conversation
@@ -88,7 +88,7 @@ export const setGridRowCountStateUpdate = (state, payload): GridPaginationState | |||
...state, | |||
pageCount: newPageCount, | |||
rowCount: totalRowCount, | |||
page: state.page > newPageCount ? newPageCount - 1 : state.page, | |||
page: Math.min(state.page, newPageCount - 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that different 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
min is equivalent to:
page: Math.min(state.page, newPageCount - 1), | |
page: state.page > newPageCount -1 ? newPageCount - 1 : state.page,, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes of course!
IMO , it's easier and more common to read page: state.page > newPageCount -1 ? newPageCount - 1 : state.page,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have used min
because it makes it impossible for this error to happen, and since it went through two reviews unnoticed, I thought that we might as well enforce it. No real preference.
Arf, it doesn't seem to work, there is a regression in Argos-CI, with one of the test case |
It seems to be a regression from #1571 that the snapshot test catches by chance. |
the check was green in the other PR 🤔 |
I have added a proper test case for it in 4db548b (snapshots test are unreliable for this). It passes on HEAD and fails on these two PRs. |
f1fe3f0
to
4db548b
Compare
The issue is that the page value is out of range when applying this filter model |
Check https://codesandbox.io/s/material-demo-forked-87xex |
Thanks Olivier for fix. It's all happening I think because
Won't filtered data will always be less than the total initial count of rows. So page range won't exceed, right? Unless user adds a |
Test case failures looks related to auto controlling of page size. |
@ZeeshanTamboli True, I have a fix for it. Regarding the issue found by @dtassone in #1583 (comment), I think that we can open a new GitHub issue for it, it looks wrong as well but can be solved independently. |
dbe597e
to
51d5526
Compare
Alright, It seems to work correctly now. I went on refactoring the hook. I didn't need it to do it here, but while I was as it, why not. |
Doesn't this PR fully fix #1571 which we are including in |
@ZeeshanTamboli We ship at a fixed frequency, as long as there are no blockers on HEAD. #1571 is already an improvement by solving the case where the active page is above the last page + 1. Solving the +1 offset (#1583) is another improvement that can come independently. |
|
||
const PAGINATION_STATE_ID = 'pagination'; | ||
function computeState(state) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function computeState(state: GridPaginationState): GridPaginationState {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also rename computeState
to getUpdatedState
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the name of the function to better describe the use case. It's meant to compute derivative states. In theory, we could remove them from the state, it could be done inside a selector but I didn't want to refactor too much 🤷♂️
packages/grid/_modules_/grid/hooks/features/pagination/useGridPagination.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/pagination/useGridPagination.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/pagination/useGridPagination.ts
Outdated
Show resolved
Hide resolved
); | ||
logger.debug(`Setting page size to ${pageSize}`); | ||
|
||
setGridState((oldState) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename to oldState
to state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the codebase, I can find:
setGridState((state
x29setGridState((oldState
x16setGridState((previousState
x1setGridState((p
x1
OK, it would be great to do a follow-up to clean this up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setGridState((state ...
x29 👍
c1edb7a
to
66bc37f
Compare
updated with the review, see the last 2 commits
A continuation of #1571