-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(dashboard): use client-side navigation in pagination to prevent full page reloads (#2305) #2307
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { readFileSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import React from "react"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { CapPagination } from "@/app/(org)/dashboard/caps/components/CapPagination"; | ||
| import { | ||
| Pagination, | ||
| PaginationContent, | ||
| PaginationItem, | ||
| PaginationLink, | ||
| PaginationNext, | ||
| PaginationPrevious, | ||
| } from "@cap/ui"; | ||
|
|
||
| describe("CapPagination and Client Navigation (Issue #2305)", () => { | ||
| it("verifies CapPagination imports Link from next/link and passes asChild", () => { | ||
| const filePath = join( | ||
| process.cwd(), | ||
| "app/(org)/dashboard/caps/components/CapPagination.tsx", | ||
| ); | ||
| const content = readFileSync(filePath, "utf-8"); | ||
|
|
||
| expect(content).toContain('import Link from "next/link";'); | ||
| expect(content).toContain("asChild"); | ||
| expect(content).toContain("scroll={false}"); | ||
| }); | ||
|
|
||
| it("verifies @cap/ui Pagination.tsx supports asChild via Radix Slot", () => { | ||
| const filePath = join( | ||
| process.cwd(), | ||
| "../../packages/ui/src/components/Pagination.tsx", | ||
| ); | ||
| const content = readFileSync(filePath, "utf-8"); | ||
|
|
||
| expect(content).toContain('import { Slot } from "@radix-ui/react-slot";'); | ||
| expect(content).toContain("asChild?: boolean;"); | ||
| expect(content).toContain('const Comp = asChild ? Slot : "a";'); | ||
| }); | ||
|
|
||
| it("renders client Link elements inside PaginationPrevious, PaginationLink, and PaginationNext", () => { | ||
| const element = CapPagination({ | ||
| currentPage: 2, | ||
| totalPages: 5, | ||
| }) as React.ReactElement<{ children: React.ReactElement<{ children: React.ReactNode[] }> }>; | ||
|
|
||
| expect(element).toBeDefined(); | ||
| expect(element.type).toBe(Pagination); | ||
|
|
||
| const content = element.props.children; | ||
| expect(content.type).toBe(PaginationContent); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comments here and at lines 59 and 78 merely narrate the immediately following assertions. The repository requires defaulting to no code comments and explicitly prohibits comments that only describe what the code does. Remove these comments or replace them with genuinely non-obvious context; this repository requirement must be satisfied before merging. Context Used: AGENTS.md (source) Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/web/__tests__/unit/cap-pagination.test.ts
Line: 50
Comment:
**Comments Narrate Assertions**
The comments here and at lines 59 and 78 merely narrate the immediately following assertions. The repository requires defaulting to no code comments and explicitly prohibits comments that only describe what the code does. Remove these comments or replace them with genuinely non-obvious context; 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.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! |
||
|
|
||
| const items = React.Children.toArray(content.props.children) as React.ReactElement[]; | ||
| expect(items.length).toBeGreaterThan(0); | ||
|
|
||
| // First item should be PaginationPrevious with asChild | ||
| const prevItem = items[0].props.children as React.ReactElement<{ asChild?: boolean; children: React.ReactElement<{ href: string; scroll: boolean }> }>; | ||
| expect(prevItem.type).toBe(PaginationPrevious); | ||
| expect(prevItem.props.asChild).toBe(true); | ||
| expect(prevItem.props.children.props.href).toBe("/dashboard/caps?page=1"); | ||
| expect(prevItem.props.children.props.scroll).toBe(false); | ||
|
|
||
| // Last item should be PaginationNext with asChild | ||
| const nextItem = items[items.length - 1].props.children as React.ReactElement<{ asChild?: boolean; children: React.ReactElement<{ href: string; scroll: boolean }> }>; | ||
| expect(nextItem.type).toBe(PaginationNext); | ||
| expect(nextItem.props.asChild).toBe(true); | ||
| expect(nextItem.props.children.props.href).toBe("/dashboard/caps?page=3"); | ||
| expect(nextItem.props.children.props.scroll).toBe(false); | ||
| }); | ||
|
Comment on lines
+40
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/web/__tests__/unit/cap-pagination.test.ts
Line: 40-68
Comment:
**Links Are Never Rendered**
Calling `CapPagination` directly only inspects unevaluated React element props; it never executes `PaginationPrevious`, `PaginationNext`, or Radix `Slot`. The test can therefore remain green if the final anchors lose their href, labels, icons, or delegated props. Render the component in a DOM environment and assert the resulting links.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. |
||
|
|
||
| it("respects custom hrefForPage generator with client navigation", () => { | ||
| const customHref = (page: number) => `/custom/route?p=${page}`; | ||
| const element = CapPagination({ | ||
| currentPage: 1, | ||
| totalPages: 3, | ||
| hrefForPage: customHref, | ||
| }) as React.ReactElement<{ children: React.ReactElement<{ children: React.ReactNode[] }> }>; | ||
|
|
||
| const content = element.props.children; | ||
| const items = React.Children.toArray(content.props.children) as React.ReactElement[]; | ||
|
|
||
| // On page 1, first link is page 1 (no Previous) | ||
| const firstLink = items[0].props.children as React.ReactElement<{ asChild?: boolean; children: React.ReactElement<{ href: string; scroll: boolean }> }>; | ||
| expect(firstLink.type).toBe(PaginationLink); | ||
| expect(firstLink.props.asChild).toBe(true); | ||
| expect(firstLink.props.children.props.href).toBe("/custom/route?p=1"); | ||
| expect(firstLink.props.children.props.scroll).toBe(false); | ||
| }); | ||
| }); | ||
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.
The new pagination test is absent from the explicit web-test lists executed by CI, so these assertions can regress without a required check failing. Add this file to the relevant CI test invocation or run the complete web unit-test suite.
Prompt To Fix With AI
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!