Skip to content

fix(web): render complete pagination links including last page and neighbours (#3566) - #3575

Open
ghazy2001 wants to merge 1 commit into
CapSoftware:mainfrom
ghazy2001:fix/caps-pagination-last-page-and-neighbours-3566
Open

ghazy2001 wants to merge 1 commit into
CapSoftware:mainfrom
ghazy2001:fix/caps-pagination-last-page-and-neighbours-3566

Conversation

@ghazy2001

@ghazy2001 ghazy2001 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #3566
Linear: CAP-956

CapPagination did not link to totalPages, displayed trailing ellipses unconditionally when currentPage > 2, and rendered PaginationNext unconditionally on the last page.

Root Cause

CapPagination.tsx hardcoded page links for 1, currentPage, and currentPage + 1, followed by {currentPage > 2 && <PaginationEllipsis />}. It never rendered totalPages, leaving users unable to navigate to the last page directly or view missing intermediate page numbers. Furthermore, PaginationNext always rendered and linked to currentPage when on the final page.

Changes

  • Implemented getPaginationItems(currentPage, totalPages) in apps/web/lib/pagination-items.ts to compute:
    • All page links when totalPages <= 5 without ellipses.
    • First and last page anchors (1 and totalPages) alongside current page neighbours.
    • Properly positioned ellipses when gaps exceed 1 page, inserting bridging page numbers directly when the difference is 2.
  • Refactored CapPagination.tsx to map over getPaginationItems and render clean, responsive links.
  • Only rendered PaginationNext when currentPage < totalPages.
  • Added unit tests in apps/web/__tests__/unit/cap-pagination.test.ts verifying small counts, start, middle, and end positions, single page boundaries, and bridge insertions.

Test plan

  • Ran unit tests with Bun:
    • bun test apps/web/__tests__/unit/cap-pagination.test.ts (4 pass, 15 assertions)
    • bun test apps/web/__tests__/unit/pagination-params.test.ts (6 pass, 23 assertions)
    • bun test apps/web/__tests__/unit/activity-time-ago.test.ts (3 pass, 13 assertions)
    • bun test apps/web/__tests__/unit/video-thumbnail-duration.test.ts (4 pass, 17 assertions)
  • Verified with 4 pages: viewing page 1 shows [1, 2, 3, 4, Next], viewing page 4 shows [Prev, 1, 2, 3, 4] (no Next button, last page fully accessible).

RetriggerView in GreptileConfidence Score: 4/5

The comments rule must be satisfied before merging; the small-screen layout also deserves a follow-up fix.

Findings

  1. P2 Page links exceed phone width ▶
  2. P2 Test comments break repository rules ▶
Fix with agent prompt
### Issue 1
apps/web/app/(org)/dashboard/caps/components/CapPagination.tsx:38-47
`CapPagination` now renders all five numbered links when `totalPages` is 5, but the row cannot wrap. On a 320px-wide phone, those links, gaps, and `Next` exceed the dashboard's padded width and can leave links clipped. The old first-page row had only two numbered links. Add a narrow-screen layout so the extra links stay within view.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
apps/web/__tests__/unit/cap-pagination.test.ts:19
The new `Viewing start`, `Viewing middle`, and `Viewing end` comments repeat the page positions already shown by the assertions. `AGENTS.md` explicitly bans comments that merely narrate the code. Remove these comments or split the groups into named tests. This repository requirement must be satisfied before merging.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR adds getPaginationItems and uses it to show first, last, and neighboring pages.

  • Cap pagination shows nearby pages and stops Next at the last page.

Reviews (1) · Last reviewed commit: "fix(web): render complete pagination lin..." · Reviewed by Greptile

…ighbours (CapSoftware#3566)

CapPagination only rendered page 1, current page, and current + 1 with an arbitrary trailing ellipsis, never linking to totalPages or allowing users to jump to the last page. In addition, PaginationNext rendered unconditionally, linking back to currentPage when on the last page.

Added getPaginationItems in apps/web/lib/pagination-items.ts to compute the first and last page links, neighbouring active pages, and appropriately placed ellipses. Hid Next button on the last page. Added comprehensive unit tests.

Closes CapSoftware#3566
@vercel

vercel Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Oct 29, 2026 10:19pm UTC

Comment on lines +38 to +47
{items.map((item, index) =>
item === "ellipsis" ? (
<PaginationEllipsis key={`ellipsis-${index}`} />
) : (
<PaginationItem key={item}>
<PaginationLink
className={
item === currentPage
? "h-10 min-w-10"
: "h-10 min-w-10 hover:bg-gray-3"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Page links exceed phone width

CapPagination now renders all five numbered links when totalPages is 5, but the row cannot wrap. On a 320px-wide phone, those links, gaps, and Next exceed the dashboard's padded width and can leave links clipped. The old first-page row had only two numbered links. Add a narrow-screen layout so the extra links stay within view.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/app/(org)/dashboard/caps/components/CapPagination.tsx
Line: 38-47

Comment:
**Page links exceed phone width**

`CapPagination` now renders all five numbered links when `totalPages` is 5, but the row cannot wrap. On a 320px-wide phone, those links, gaps, and `Next` exceed the dashboard's padded width and can leave links clipped. The old first-page row had only two numbered links. Add a narrow-screen layout so the extra links stay within view.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

});

it("always links first and last page with ellipses for large page counts", () => {
// Viewing start

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Test comments break repository rules

The new Viewing start, Viewing middle, and Viewing end comments repeat the page positions already shown by the assertions. AGENTS.md explicitly bans comments that merely narrate the code. Remove these comments or split the groups into named tests. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/__tests__/unit/cap-pagination.test.ts
Line: 19

Comment:
**Test comments break repository rules**

The new `Viewing start`, `Viewing middle`, and `Viewing end` comments repeat the page positions already shown by the assertions. `AGENTS.md` explicitly bans comments that merely narrate the code. Remove these comments or split the groups into named tests. This repository requirement must be satisfied before merging.

**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

This branch was previously deployed

1 inactive deployment
Preview – cap-status — cc606596 Deployed Oct 29, 2026 by vercel[bot]
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.

Caps pagination never links to the last page

1 participant