Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

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

Maqbool Ahmed568ee514f714
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx
index e2ca391d8..5e64d29f4 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx
@@ -28,6 +28,7 @@ import { addCompetitor } from '@/lib/actions/competitor';
import {
getCitationsOverview,
getCitationGaps,
+ getCitationsTotal,
type CitationsFilters,
type CitationsOverview,
type CitationDomainRow,
@@ -212,7 +213,7 @@ interface PlatformOption {
}
const DEFAULT_FILTERS: UIFilters = {
- datePreset: 'all',
+ datePreset: '24h',
dateFrom: '',
dateTo: '',
platform: '',
@@ -771,14 +772,28 @@ const DomainsTable = memo(function DomainsTable({
onAdded,
page,
onPage,
+ filters,
+ onResetFilters,
+ hasAnyCitations,
}: {
rows: CitationDomainRow[];
brandId: string;
onAdded: () => void;
page: number;
onPage: (p: number) => void;
+ filters: UIFilters;
+ onResetFilters: () => void;
+ hasAnyCitations: boolean | null;
}) {
- if (rows.length === 0) return <EmptyRows />;
+ if (rows.length === 0)
+ return (
+ <EmptyRows
+ isFiltered={filters.datePreset !== 'all'}
+ datePreset={filters.datePreset}
+ onShowAll={onResetFilters}
+ hasAnyCitations={hasAnyCitations}
+ />
+ );
const totalPages = Math.max(1, Math.ceil(rows.length / PAGE_SIZE));
const clampedPage = Math.min(page, totalPages - 1);
@@ -862,12 +877,26 @@ const UrlsTable = memo(function UrlsTable({
rows,
page,
onPage,
+ filters,
+ onResetFilters,
+ hasAnyCitations,
}: {
rows: CitationUrlRow[];
page: number;
onPage: (p: number) => void;
+ filters: UIFilters;
+ onResetFilters: () => void;
+ hasAnyCitations: boolean | null;
}) {
- if (rows.length === 0) return <EmptyRows />;
+ if (rows.length === 0)
+ return (
+ <EmptyRows
+ isFiltered={filters.datePreset !== 'all'}
+ datePreset={filters.datePreset}
+ onShowAll={onResetFilters}
+ hasAnyCitations={hasAnyCitations}
+ />
+ );
const totalPages = Math.max(1, Math.ceil(rows.length / PAGE_SIZE));
const clampedPage = Math.min(page, totalPages - 1);
@@ -940,7 +969,70 @@ const UrlsTable = memo(function UrlsTable({
);
});
-function EmptyRows() {
+/**
+ * Period-aware empty state for the Domains / URLs tables (#485).
+ *
+ * hasAnyCitations is fetched once in loadData (via getCitationsTotal) and
+ * passed down, so both keepMounted panels share a single server call instead
+ * of each firing their own (#313 action queue note).
+ *
+ * Three states:
+ * 1. Checking (null) — loadData is still in flight; shows a spinner.
+ * 2. Has data outside window — "No citations in the last Xh/d" + "Show all data" button.
+ * 3. No data at all — generic filter message (original behaviour).
+ *
+ * isFiltered / datePreset / onShowAll default to gap-safe values so
+ * ByCompetitorView / CompetitorGapsTab can render <EmptyRows /> with no props.
+ */
+function EmptyRows({
+ isFiltered = false,
+ datePreset = 'all',
+ onShowAll = () => {},
+ hasAnyCitations = null,
+}: {
+ isFiltered?: boolean;
+ datePreset?: CitationsDatePreset;
+ onShowAll?: () => void;
+ hasAnyCitations?: boolean | null;
+}) {
+ // ── 1. Checking ──────────────────────────────────────────────────────────────
+ if (hasAnyCitations === null) {
+ return (
+ <div className="flex flex-col items-center justify-center py-16 text-center">
+ <Loader2 className="h-6 w-6 animate-spin text-muted-foreground/60 mb-3" />
+ <p className="text-xs text-muted-foreground">Checking citation data…</p>
+ </div>
+ );
+ }
+
+ // ── 2. Period-aware: data exists outside this window ─────────────────────────
+ if (hasAnyCitations && isFiltered) {
+ const periodLabel =
+ datePreset === '24h'
+ ? 'the last 24 hours'
+ : datePreset === '7d'
+ ? 'the last 7 days'
+ : datePreset === '30d'
+ ? 'the last 30 days'
+ : datePreset === '90d'
+ ? 'the last 90 days'
+ : 'the selected period';
+
+ return (
+ <div className="flex flex-col items-center justify-center py-16 text-center">
+ <FilterIcon className="h-8 w-8 text-muted-foreground/40 mb-3" />
+ <p className="text-sm font-medium">No citations in {periodLabel}</p>
+ <p className="mt-1 text-xs text-muted-foreground">
+ Citation data exists outside this window.
+ </p>
+ <Button variant="outline" size="sm" className="mt-4 text-xs" onClick={onShowAll}>
+ Show all data
+ </Button>
+ </div>
+ );
+ }
+
+ // ── 3. No data at all — original generic message ──────────────────────────────
return (
<div className="flex flex-col items-center justify-center py-16 text-center">
<FilterIcon className="h-8 w-8 text-muted-foreground/40 mb-3" />
@@ -1336,6 +1428,7 @@ export default function CitationsPage() {
const [filters, setFilters] = useState<UIFilters>(DEFAULT_FILTERS);
const [data, setData] = useState<CitationsOverview | null>(null);
+ const [hasAnyCitations, setHasAnyCitations] = useState<boolean | null>(null);
// Pagination — resets to page 0 whenever any filter changes
const filterKey = JSON.stringify(filters);
@@ -1408,8 +1501,12 @@ export default function CitationsPage() {
}
setIsLoading(true);
try {
- const overview = await getCitationsOverview(activeBrandId, apiFilters);
+ const [overview, total] = await Promise.all([
+ getCitationsOverview(activeBrandId, apiFilters),
+ getCitationsTotal(activeBrandId),
+ ]);
setData(overview);
+ setHasAnyCitations(total > 0);
// Surface filter options from the observed models/regions.
const platformOptions = buildPlatformOptions(overview.rows);
@@ -1632,6 +1729,9 @@ export default function CitationsPage() {
onAdded={loadData}
page={domainPager.page}
onPage={domainPager.setPage}
+ filters={filters}
+ onResetFilters={() => setFilters({ ...DEFAULT_FILTERS, datePreset: 'all' })}
+ hasAnyCitations={hasAnyCitations}
/>
</TabsContent>
<TabsContent value="urls" keepMounted className="mt-4">
@@ -1639,6 +1739,9 @@ export default function CitationsPage() {
rows={data?.urlRows ?? []}
page={urlPager.page}
onPage={urlPager.setPage}
+ filters={filters}
+ onResetFilters={() => setFilters({ ...DEFAULT_FILTERS, datePreset: 'all' })}
+ hasAnyCitations={hasAnyCitations}
/>
</TabsContent>
<TabsContent value="gaps" className="mt-4">
diff --git a/web/src/lib/actions/citations.ts b/web/src/lib/actions/citations.ts
index 9cfa4aa1d..ba7dfeeaa 100644
--- a/web/src/lib/actions/citations.ts
+++ b/web/src/lib/actions/citations.ts
@@ -667,3 +667,25 @@ export async function getCitationGaps(
return { gapDomains, byCompetitor, competitors, ourAnswerCount, totalAnswers, lowVisibility };
}
+
+// ─── Existence check (#485) ───────────────────────────────────────────────────
+
+/**
+ * Cheap unfiltered existence check — counts prompt_results rows for a brand
+ * with no date/filter constraints, so the Citations page can distinguish
+ * "no data in this window" from "no data at all".
+ *
+ * Mirrors getBrandResultsTotal in tracking.ts (used by the Insights page).
+ * Uses `head: true` so Supabase returns only the count, not any rows.
+ */
+export async function getCitationsTotal(brandId: string): Promise<number> {
+ const supabase = await createClient();
+ const { count, error } = await supabase
+ .from('prompt_results')
+ .select('id', { count: 'exact', head: true })
+ .eq('brand_id', brandId)
+ .neq('platform', 'chatgpt-shopping')
+ .neq('citations', '[]');
+ if (error) throw new Error(error.message);
+ return count ?? 0;
+}