Skip to content
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

Pagination - fix issue when step size changes and current page isn't visible #7237

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jcfilben
Copy link
Collaborator

What does this PR do?

Fixes an issue in Pagination when you are on a page and then change the step size in such a way that the current page you are on no longer exists. The current behavior is that no page will be selected, this PR changes the behavior so that the user lands on the last page (this is so that they will be closest to the data they were previously viewing before changing the step size).

Where should the reviewer start?

What testing has been done on this PR?

Added jest test and tested with existing storybook stories

How should this be manually tested?

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

Closes #7215

Screenshots (if appropriate)

Do the grommet docs need to be updated?

no

Should this PR be mentioned in the release notes?

yes

Is this change backwards compatible or is it a breaking change?

backwards compatible

@jcfilben jcfilben requested review from taysea and britt6612 May 21, 2024 16:18
@britt6612
Copy link
Collaborator

more of a question.. should the user be put back to page one? after re-selecting items per page

Screen.Recording.2024-05-21.at.2.09.00.PM.mov

@jcfilben
Copy link
Collaborator Author

more of a question.. should the user be put back to page one? after re-selecting items per page

I put them on the last page because then they would be closer to the data that they were previously viewing before changing the step

@britt6612
Copy link
Collaborator

more of a question.. should the user be put back to page one? after re-selecting items per page

I put them on the last page because then they would be closer to the data that they were previously viewing before changing the step

gotcha just wanted to make sure that was the correct pattern!

@taysea
Copy link
Collaborator

taysea commented May 22, 2024

To just speak out loud, is it correct to say our logic is "as step changes, we keep the previously active page active. For example, if user was on page 5 and they change from step of 10 to 25, we'll stay on step 5. In cases where the page no longer exists because there are less total pages, we'll fallback to the last page"?

I'm trying to figure out what I'd expect in a scenario like this where I was on page 14, then increased the step, and then was on the last page of data.

Screen.Recording.2024-05-22.at.3.17.04.PM.mov

@halocline any thoughts on behavior?

@halocline
Copy link
Collaborator

To just speak out loud, is it correct to say our logic is "as step changes, we keep the previously active page active. For example, if user was on page 5 and they change from step of 10 to 25, we'll stay on step 5. In cases where the page no longer exists because there are less total pages, we'll fallback to the last page"?

I'm trying to figure out what I'd expect in a scenario like this where I was on page 14, then increased the step, and then was on the last page of data.

@halocline any thoughts on behavior?

I agree that we should pause and think through this a bit further. The page 14 to last page scenario isn't right - because last page is much further away.

We are either "smart" and do something like ensure the index of the first item in the current page is in the resulting subset in the next page.

Or, always go back to page 1.

We also need to consider the controlled scenario as well.

@jcfilben
Copy link
Collaborator Author

I agree that we should pause and think through this a bit further. The page 14 to last page scenario isn't right - because last page is much further away.

I'm confused by the statement 'last page is much further away', if we have a scenario where we are on page 14 and the step changes in such a way that page 14 no longer exists and we are moved to the last page then the data on the last page will include data from page 14

@MikeKingdom
Copy link
Collaborator

I agree that we should pause and think through this a bit further. The page 14 to last page scenario isn't right - because last page is much further away.

I'm confused by the statement 'last page is much further away', if we have a scenario where we are on page 14 and the step changes in such a way that page 14 no longer exists and we are moved to the last page then the data on the last page will include data from page 14

I think point is that isn't necessarily true. You probably could do the math to figure out what page in the new step size contains the top item from the previous current page. But we do need to think a little more about the various cases and if we're screwing up the controlled situations (ie. not letting the caller control where it ends up when step changes.)

@jcfilben
Copy link
Collaborator Author

I think point is that isn't necessarily true. You probably could do the math to figure out what page in the new step size contains the top item from the previous current page. But we do need to think a little more about the various cases and if we're screwing up the controlled situations (ie. not letting the caller control where it ends up when step changes.)

Ah okay I was thinking of page 14 as the last page, but if page 14 is a middle page I see what you are saying.

@jcfilben
Copy link
Collaborator Author

jcfilben commented May 23, 2024

Slow brain haha sorry, should we just default to going back to the first page? Unless Pagination is in a controlled state then we wouldn't do anything

@jcfilben
Copy link
Collaborator Author

Writing out logic for going back to Page 1

If the current page no longer exists
  If `pageProp` and `onChange` are defined
    Do nothing, Pagination is in a controlled state
  Else set page to the first page

If a different behavior is desired then it can be achieved through a controlled version of Pagination

@taysea
Copy link
Collaborator

taysea commented May 30, 2024

Writing out logic for keeping previously visible data visible

If the current page no longer exists or the data that was visible has moved to a different page
  Determine what was the "first" record that was previously visible
  Set page to the page that now contains record
  If `pageProp` and `onChange` are defined
    Do nothing, Pagination is in a controlled state

If a different behavior is desired then it can be achieved through a controlled version of Pagination

@jcfilben jcfilben marked this pull request as draft June 17, 2024 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pagination - handle when step change causes page to no longer exist
5 participants