-
Notifications
You must be signed in to change notification settings - Fork 39
fix: atomic-pager showing non-existent page on last page #6818
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR fixes an off-by-one indexing bug in atomic-pager that caused a non-existent page button to appear on the last page. The root cause was an inconsistent index conversion between Search Headless (1-indexed) and the pager utility functions (0-indexed).
Key Changes:
- Fixed
getCurrentPagesRangecall to convertmaxPagefrom 1-indexed to 0-indexed - Aligned with existing conversions for
currentPageparameter in the same function call - Ensures consistency with
atomic-commerce-pagerpattern (which doesn't need conversion as Commerce Headless is already 0-indexed)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot add a unit tests that for a given number of results (and a given result per page number), the pager displays the right number of page button. |
Added unit tests in commit 7f471d3 that verify the pager displays the correct number of page buttons for various combinations of total results and results per page:
Each test calculates |
Problem
atomic-pagerdisplayed an extra non-existent page button on the last page. With 10 total pages, the last page showed buttons [7, 8, 9, 10, 11], where clicking page 11 resulted in an empty results page.Root Cause
Index mismatch: Search Headless uses 1-indexed pages (currentPage: 1-10, maxPage: 10), while
pager-utilsexpects 0-indexed internally (0-9). The code convertedcurrentPagebut notmaxPage.Changes
atomic-pager.tsline 147:Unit Tests Added:
Added comprehensive unit tests in
atomic-pager.spec.tsthat verify the pager displays the correct number of page buttons for various combinations of total results and results per page:Each test calculates
maxPage = Math.ceil(totalResults / resultsPerPage)and verifies that on the last page, only valid page buttons are displayed without showing non-existent pages. This prevents regression of the off-by-one bug.Note:
atomic-commerce-pagerunaffected—Commerce Headless uses 0-indexing throughout.https://coveord.atlassian.net/browse/KIT-5338
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.