Repository navigation
fix(citations): default date preset to 24h and add period-aware empty state (#485) - #489
Conversation
gkhngyk
left a comment
There was a problem hiding this comment.
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:
getCitationsTotalcounts allprompt_resultsrows, 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-emptycitationsarray (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'sloadDataand 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:
|
gkhngyk
left a comment
There was a problem hiding this comment.
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!
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.tsgetCitationsTotal(brandId)— a cheap unfiltered existence check that countsprompt_resultsrows for a brand with no date or filter constraints, usinghead: trueso Supabase returns only the count and no row data. Mirrors thegetBrandResultsTotalpattern already used by the Insights page intracking.ts.web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsxDEFAULT_FILTERS.datePresetfrom'all'to'24h', matching the Insights page default.getCitationsTotalto the named imports from@/lib/actions/citations.EmptyRowscomponent with a period-aware version that distinguishes three states:DEFAULT_FILTERS.filters: UIFiltersandonResetFilters: () => voidprops toDomainsTableandUrlsTableso the empty state can read the active date preset and trigger a reset.filters={filters}andonResetFilters={() => setFilters(DEFAULT_FILTERS)}through both table call sites inCitationsPage.Acceptance criteria
/dashboard/citationsshows the 24h window selected and 24h-scoped datayarn lintpasses (0 errors)yarn typecheckpasses (0 errors)yarn format:checkpassesTesting
/dashboard/citationson 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.Allselected and data visible.