Skip to content

fix(citations): default date preset to 24h and add period-aware empty state (#485) - #489

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
Maqbool61:fix/citations-default-date-24h
Jul 21, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
Maqbool61:fix/citations-default-date-24h

Conversation

@Maqbool61

Copy link
Copy Markdown
Contributor

Summary

Closes #485

The Citations page opened with datePreset: 'all' by default while the Insights page opened with '24h'. This caused two problems: numbers across the two most-visited analytical pages didn't line up, and every first load triggered the most expensive possible query — a full scan of the brand's entire citation history.

This PR fixes both problems with a minimal, self-contained change to two files.


Changes

web/src/lib/actions/citations.ts

  • Added getCitationsTotal(brandId) — a cheap unfiltered existence check that counts prompt_results rows for a brand with no date or filter constraints, using head: true so Supabase returns only the count and no row data. Mirrors the getBrandResultsTotal pattern already used by the Insights page in tracking.ts.

web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx

  • Changed DEFAULT_FILTERS.datePreset from 'all' to '24h', matching the Insights page default.
  • Added getCitationsTotal to the named imports from @/lib/actions/citations.
  • Replaced the generic EmptyRows component with a period-aware version that distinguishes three states:
    • Loading — while the unfiltered existence check runs, shows a small spinner so the table area doesn't jump.
    • Data exists outside this window — shows "No citations in the last 24 hours" (or the relevant period label) with a one-click Show all data button that resets filters to DEFAULT_FILTERS.
    • No data at all — falls back to the original generic "No citations match your filters" message so the brand-level empty state is unchanged.
  • Added filters: UIFilters and onResetFilters: () => void props to DomainsTable and UrlsTable so the empty state can read the active date preset and trigger a reset.
  • Threaded filters={filters} and onResetFilters={() => setFilters(DEFAULT_FILTERS)} through both table call sites in CitationsPage.

Acceptance criteria

  • Cold load of /dashboard/citations shows the 24h window selected and 24h-scoped data
  • With citations outside the window but none inside it, the page shows the period-aware empty state with a working Show all data reset — not the generic filter message and not a bare empty table
  • With no citations at all, the existing brand-level empty state still shows
  • All other presets (7d / 30d / 90d / all / custom) keep working unchanged
  • yarn lint passes (0 errors)
  • yarn typecheck passes (0 errors)
  • yarn format:check passes

Testing

  1. Open /dashboard/citations on a brand with recent citation data — the 24h button should be selected on load and the table should show only citations from the last 24 hours.
  2. If the brand has no citations in the last 24 hours but has older data, the Domains and URLs tables should show "No citations in the last 24 hours" with a Show all data button. Clicking it should reload with All selected and data visible.
  3. Switch between all date presets (7d, 30d, 90d, All, Custom) and confirm each loads correct data and the empty state message matches the selected period.
  4. On a brand with zero citations ever, confirm the generic "No citations match your filters" message still appears.

@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.

Thanks — the structure is right (three-state empty component, cheap existence check, 24h default) and CI is green. One blocker before this can merge:

Blocker: "Show all data" doesn't actually switch to All time. onResetFilters calls setFilters(DEFAULT_FILTERS), and this PR changes DEFAULT_FILTERS.datePreset to '24h' — so clicking the button lands the user back in the same empty 24h window. It needs to force the preset:

onResetFilters={() => setFilters({ ...DEFAULT_FILTERS, datePreset: 'all' })}

Two smaller points, worth fixing in the same pass:

  • getCitationsTotal counts all prompt_results rows, including ones with no citations. A brand with tracking data but zero cited links would get the "Citation data exists outside this window" state incorrectly. Constrain the count to rows with a non-empty citations array (e.g. .neq('citations', '[]')).
  • The existence check runs inside each empty table, and the Domains + URLs panels are both keepMounted — so an empty cold load fires the same server action twice, serialized (see the #313 note in this file about the action queue). Lifting the check to the page's loadData and passing the result down as a prop does it once.

Nit: ByCompetitorView/CompetitorGapsTab pass dummy props (isFiltered={false} onShowAll={() => {}}) — optional props with defaults would read cleaner, no behavior change.

@Maqbool61
Maqbool61 requested a review from gkhngyk July 21, 2026 05:58
@Maqbool61

Copy link
Copy Markdown
Contributor Author

Thanks — the structure is right (three-state empty component, cheap existence check, 24h default) and CI is green. One blocker before this can merge:

Blocker: "Show all data" doesn't actually switch to All time. onResetFilters calls setFilters(DEFAULT_FILTERS), and this PR changes DEFAULT_FILTERS.datePreset to '24h' — so clicking the button lands the user back in the same empty 24h window. It needs to force the preset:

onResetFilters={() => setFilters({ ...DEFAULT_FILTERS, datePreset: 'all' })}

Two smaller points, worth fixing in the same pass:

* `getCitationsTotal` counts all `prompt_results` rows, including ones with no citations. A brand with tracking data but zero cited links would get the "Citation data exists outside this window" state incorrectly. Constrain the count to rows with a non-empty `citations` array (e.g. `.neq('citations', '[]')`).

* The existence check runs inside each empty table, and the Domains + URLs panels are both `keepMounted` — so an empty cold load fires the same server action twice, serialized (see the #313 note in this file about the action queue). Lifting the check to the page's `loadData` and passing the result down as a prop does it once.

Nit: ByCompetitorView/CompetitorGapsTab pass dummy props (isFiltered={false} onShowAll={() => {}}) — optional props with defaults would read cleaner, no behavior change.

Thanks for the thorough review @gkhngyk — all points addressed in the latest push:

  • Blocker: onResetFilters now does setFilters({ ...DEFAULT_FILTERS, datePreset: 'all' }) on both table call sites, so "Show all data" correctly lands on the All window instead of bouncing back to 24h.
  • getCitationsTotal: added .neq('citations', '[]') to constrain the count to rows with actual cited links, so brands with tracking data but zero citations no longer trigger the false "data exists outside this window" state.
  • Double fetch: lifted the existence check out of EmptyRows entirely — getCitationsTotal now runs once in Promise.all alongside getCitationsOverview inside loadData, result stored as hasAnyCitations state and passed down as a prop to both tables.
  • Nit: all three EmptyRows props now have defaults, so the ByCompetitorView / CompetitorGapsTab call sites are back to bare <EmptyRows />.
    yarn typecheck, yarn lint, and yarn format:check all pass. Ready for another look whenever you get a chance!

@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.

All feedback addressed cleanly — the reset now lands on All time, the existence check counts only citation-bearing rows, and the single fetch in loadData removes the duplicate call. Thanks for the quick turnaround!

@gkhngyk
gkhngyk merged commit 568ee51 into ansvisor:main Jul 21, 2026
3 checks passed
@Maqbool61
Maqbool61 deleted the fix/citations-default-date-24h branch July 21, 2026 13:50
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.

Citations: default the date filter to 24h instead of All

2 participants