Skip to content

feat(citations): paginate Top Sources Domains/URLs tables (100 rows per page, closes #395) - #411

Merged
gkhngyk merged 7 commits into
ansvisor:mainfrom
Maqbool61:feat/citations-paginate-top-sources
Jul 12, 2026
Merged

gkhngyk merged 7 commits into
ansvisor:mainfrom
Maqbool61:feat/citations-paginate-top-sources

Conversation

@Maqbool61

@Maqbool61 Maqbool61 commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #395

Problem

On /dashboard/citations, the Top Sources card was rendering the entire Domains and URLs result sets with no limit — DomainsTable and UrlsTable both called rows.map(...) over the full arrays. For brands with thousands of cited domains/URLs this made the page heavy to render and scroll.

This was made worse by the keepMounted tab optimization from #325: both full tables live in the DOM simultaneously (tab switching is a CSS visibility toggle), so the browser was holding and rendering all rows for both tabs at the same time.


What changed

Single file changed: web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx — no server or API changes.

1. usePagination hook

A small hook that manages page state for a single table:

ts
usePagination(totalRows: number, resetKey: unknown)
  • Returns page, setPage, totalPages, start, end
  • Accepts a resetKey — when it changes (e.g. a filter is applied), the page resets back to 0 automatically
  • The parent passes JSON.stringify(filters) as the reset key so any filter change (date, platform, topic, prompt, region, own-domain toggles) resets both pagers independently

2. TablePager component

A minimal pager rendered below each table:

  • Shows "1–100 of N" range on the left
  • Shows Previous / Next buttons and "page / totalPages" on the right
  • Returns null when totalPages <= 1 (≤ 100 rows) so it's invisible for small datasets

3. DomainsTable and UrlsTable updated

Both tables now:

  • Accept page and onPage props
  • Slice their rows array to 100 rows per page (rows.slice(start, end))
  • Use start + i + 1 for rank instead of i + 1 — so rank stays global across pages (page 2 starts at 101, not 1)
  • Render <TablePager /> below the table body

Page state is independent per tab — navigating to Domains page 3 has no effect on the URLs tab's page.


How it solves the issue

Requirement | How it's met -- | -- At most 100 rows per page | rows.slice(start, end) with PAGE_SIZE = 100 Global rank across pages | start + i + 1 instead of i + 1 Independent page state per tab | Two separate usePagination calls, one for domains, one for URLs Resets on filter change | resetKey = JSON.stringify(filters) passed to both hooks keepMounted preserved | Untouched — both panels stay mounted, now just 100 rows each so instant tab switching from #325 is preserved and actually faster No server/API changes | Data is already fully loaded client-side by getCitationsOverview — pagination is pure array slicing Pager hidden for small datasets | TablePager returns null when totalPages <= 1

All 5 pass locally.

@Maqbool61

Copy link
Copy Markdown
Contributor Author

I'm working through the CI failures and updating the implementation to satisfy the project's current ESLint/React Hooks rules while preserving the pagination behavior from #395. I'll push a follow-up commit once everything passes locally.

@Maqbool61

Copy link
Copy Markdown
Contributor Author

I'm working through the CI failures and updating the implementation to satisfy the project's current ESLint/React Hooks rules while preserving the pagination behavior from #395. I'll push a follow-up commit once everything passes locally.

All CI checks are now green ✅
Quick summary of what went into this PR across the commits:

Core feature: Added usePagination hook and TablePager component, updated DomainsTable and UrlsTable to slice to 100 rows per page with global rank (start + i + 1), independent page state per tab, and auto-reset on filter change via JSON.stringify(filters) as the reset key
ESLint fix: Replaced useEffect(() => setPage(0), [resetKey]) with a ref-based comparison during render — the React-approved pattern for derived state resets that avoids the "calling setState synchronously within an effect" warning
TypeScript fix: Moved pager initialization after the data useState declaration to fix TS2448: Block-scoped variable 'data' used before its declaration
Prettier fix: Auto-formatted page.tsx to match the project's Prettier config

All 5 unit tests pass covering: initial page state, global rank on page 2, filter reset, pager hidden for ≤ 100 rows, and page clamping when rows shrink.

@gkhngyk gkhngyk left a comment

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.

Solid implementation of #395 — and it covers every acceptance criterion: 100/page with a pager that shows 1–100 of N, global rank kept continuous across pages (start + i + 1), independent per-tab page state, reset to page 0 on any filter change (the JSON.stringify(filters) reset key covers all of them), page clamping when the row set shrinks, and keepMounted untouched so tab switching stays instant. No server changes, CI fully green. Nice touch hiding the pager entirely when there's a single page. Thanks!

@gkhngyk
gkhngyk merged commit 4e382ae into ansvisor:main Jul 12, 2026
3 checks passed
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.

feat(citations): paginate the Top Sources Domains/URLs tables (100 rows per page)

2 participants