Repository navigation
feat(citations): paginate Top Sources Domains/URLs tables (100 rows per page, closes #395) - #411
Conversation
|
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 ✅ 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 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
left a comment
There was a problem hiding this comment.
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!
Closes #395
Problem
On
/dashboard/citations, the Top Sources card was rendering the entire Domains and URLs result sets with no limit —DomainsTableandUrlsTableboth calledrows.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
keepMountedtab 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.
usePaginationhookA small hook that manages page state for a single table:
page,setPage,totalPages,start,endresetKey— when it changes (e.g. a filter is applied), the page resets back to 0 automaticallyJSON.stringify(filters)as the reset key so any filter change (date, platform, topic, prompt, region, own-domain toggles) resets both pagers independently2.
TablePagercomponentA minimal pager rendered below each table:
nullwhentotalPages <= 1(≤ 100 rows) so it's invisible for small datasets3.
DomainsTableandUrlsTableupdatedBoth tables now:
pageandonPagepropsrowsarray to 100 rows per page (rows.slice(start, end))start + i + 1for rank instead ofi + 1— so rank stays global across pages (page 2 starts at 101, not 1)<TablePager />below the table bodyPage state is independent per tab — navigating to Domains page 3 has no effect on the URLs tab's page.
How it solves the issue
All 5 pass locally.