Repository navigation
fix(paginator): clamp current page when item count shrinks - #1078
Open
Alifarid0011 wants to merge 1 commit into
Open
Alifarid0011 wants to merge 1 commit into
Alifarid0011 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Keep the current page within the new page count when
SetTotalPagesrecalculates pagination for a smaller, positive number of items.For example, start with six items and two items per page, navigate to page index 2, then replace the data with one item and call
SetTotalPages(1). Previously the page stayed at 2,GetSliceBounds(1)returned(4, 1), andItemsOnPage(1)returned-3. Slicing with those bounds, as shown in the method's documentation, panicked.The current page now moves to the new last page. In the example it becomes 0, the bounds are
(0, 1), and forward navigation stops there. Valid pages are preserved when the item count grows or stays unchanged. The existing no-op behavior for zero and negative item counts is unchanged.The fix adds one clamp in
SetTotalPagesand documents that behavior; no dependencies or public signatures change.Validation
main(e04077d) and pass with the fix.go test -race -count=1 -covermode=atomic -coverprofile=coverage.out ./...passes across the complete repository.SetTotalPageshas 100% statement coverage (overall repository coverage: 56.0%).go test -shuffle=on ./...passes; the new paginator tests also pass across 100 repetitions.go build ./...andgo vet ./...pass.golangci-lint run ./...andgolangci-lint fmt --diffpass with the CI-pinned v2.13.1 and the existing repository configuration.Local validation: Go 1.26.8, linux/amd64. Other platforms and Go versions are left to the CI matrix.