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

Fix data table pagination #5059

Merged
merged 11 commits into from
Oct 4, 2024
Merged

Fix data table pagination #5059

merged 11 commits into from
Oct 4, 2024

Conversation

gwwar
Copy link
Contributor

@gwwar gwwar commented Oct 3, 2024

If we render a component, then rerender it with different defaultPageIndex and pageCount, we can see values like Page -2, Page -1, Page 0. The defaultPageIndex is also not respected when this value is updated.

Changes here:

  • Update playground so we can see pager, set page size, and default index
  • Component state only uses initial state on first render. To detect when defaults change, I use more component state to store initial state, and trigger related events when we detect these values have changed. An example would be updating defaultIndex
  • I also expanded test coverage to catch these rerender cases.

Feel free to suggest alternatives, if folks can think of anything cleaner.

before after
before.mp4
playground.mp4

While testing I found an odd corner case for truncation. This is also present in main. I fixed this by doing a bounds check when setting offset.

before after
truncation bug after truncation

Closes https://github.com/github/meao/issues/2720

Changelog

New

Changed

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

…mponent state for total pages and current page
@gwwar gwwar self-assigned this Oct 3, 2024
Copy link

changeset-bot bot commented Oct 3, 2024

🦋 Changeset detected

Latest commit: 480dfe0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Oct 3, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 96.73 KB (0%)
packages/react/dist/browser.umd.js 97 KB (0%)

@github-actions github-actions bot temporarily deployed to storybook-preview-5059 October 3, 2024 22:52 Inactive
@gwwar gwwar marked this pull request as ready for review October 3, 2024 22:55
@gwwar gwwar requested a review from a team as a code owner October 3, 2024 22:55
@gwwar gwwar requested a review from joshblack October 3, 2024 22:55
@github-actions github-actions bot temporarily deployed to storybook-preview-5059 October 3, 2024 23:12 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-5059 October 4, 2024 00:07 Inactive
@camertron camertron self-requested a review October 4, 2024 17:26
Copy link
Collaborator

@camertron camertron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, thank you! 🎉 Could you add a changeset? Run npx changeset and follow the prompts 😄

@gwwar gwwar added this pull request to the merge queue Oct 4, 2024
Merged via the queue into main with commit 682e787 Oct 4, 2024
32 checks passed
@gwwar gwwar deleted the fix_table_paging branch October 4, 2024 21:17
@primer primer bot mentioned this pull request Oct 4, 2024
@primer primer bot mentioned this pull request Oct 18, 2024
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.

2 participants