Repository navigation
Description
What
Add a Prompt select filter to the citations page filter bar
(/dashboard/citations), alongside the existing Date / Topic /
Platform / Region filters. When a prompt is picked, citations should
narrow down to only those that came from that specific prompt's
tracked results.
Why
A marketer often wants to ask: "what URLs are AI engines citing
when answering this particular prompt?" Right now the citations
view can be filtered by topic (a coarse cluster) but not by an
individual prompt. The new filter unlocks drilling into the citation
shape for a single research question — useful for content gap
analysis and competitor URL discovery.
Where to fix
Two surfaces:
1. UI — web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx
Three small edits, all following the existing Topic filter as the
template (around lines 431–461):
a. Extend the UIFilters interface (line 149) and DEFAULT_FILTERS
(line 160) with prompt: string.
b. Build an available prompts list. Two options — pick whichever
you prefer:
- Derived (matches the Platform / Region filter pattern):
iterate overoverview.rowsand collect unique prompt ids and
texts. Pros: consistent with the page's current filter shape,
no extra fetch. - Fetched (matches the Topic filter pattern): call
getBrandPrompts(activeBrandId)once. Pros: shows every prompt
even if it has no citations yet (useful for empty-state
diagnosis).
Either is acceptable — note the trade-off in your PR description.
Default suggestion: derived, since "filter to a prompt that
has no citations" is rarely useful on this page.
c. Render the dropdown immediately after the Topic filter
(before Platform), with the same <Select> shape:
{prompts.length > 0 && (
<div>
<label className="mb-1.5 block text-xs font-medium text-muted-foreground">
Prompt
</label>
<Select
value={filters.prompt || null}
onValueChange={(v) =>
onChange({ prompt: !v || v === '__all__' ? '' : v })
}
>
<SelectTrigger className="h-8 w-56 text-xs">
{/* slightly wider than the others because prompt text is longer */}
<SelectValue placeholder="All Prompts">
{(value) =>
value && value !== '__all__'
? (prompts.find((p) => p.id === value)?.text ?? 'All Prompts')
: 'All Prompts'
}
</SelectValue>
</SelectTrigger>
<SelectContent>
<SelectItem value="__all__">All Prompts</SelectItem>
{prompts.map((p) => (
<SelectItem key={p.id} value={p.id}>
{p.text.length > 60 ? `${p.text.slice(0, 60)}…` : p.text}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
)}Truncate long prompt text to ~60 chars in dropdown items (full
text shows in the trigger when selected) so the menu doesn't
stretch the screen.
d. In the apiFilters builder (around line 762), pass the new
filter through:
promptIds: filters.prompt ? [filters.prompt] : undefined,And add filters.prompt to the dependency array of the loader
useCallback (around line 801).
2. Backend — web/src/lib/actions/citations.ts
a. Extend CitationsFilters (line 24) with promptIds?: string[].
b. In the prompt_results query (around line 142), add:
if (filters.promptIds && filters.promptIds.length > 0) {
query = query.in('prompt_id', filters.promptIds);
}Place it next to the existing platforms / regions filters for
consistency.
How to verify
- On a brand with multiple tracked prompts, the Prompt filter
appears between Topic and Platform - Selecting a prompt narrows the citations table to just that
prompt's URLs / domains - Clearing the filter (or picking "All Prompts") restores the
full view - Prompt text >60 chars renders truncated with
…in the
dropdown, full text appears in the trigger when selected - A brand with zero citations (or zero prompts in the derived
case) gracefully hides the filter - The active filter survives a page reload if other filters do
(test parity with the Topic filter)
Out of scope
- Search-in-dropdown / combobox UX (prompts can be 200+ on big
brands; we'll switch to a combobox in a follow-up if the simple
Select feels cramped) - Multi-select (pick multiple prompts at once) — single selection
matches the current filter pattern - Backend support for filter-by-prompt-text rather than id
Contribution guide
See CONTRIBUTING.md for branch naming, commit
conventions, and PR workflow.
Activity
feat(citations): add prompt filter with a searchable combobox (#55)