Repository navigation
Description
What
Add a Export CSV button to the All Prompts tab on the Prompts
page (/dashboard/prompts?tab=all). Clicking it downloads the
prompt inventory — text, targeting (platforms / models / regions),
estimated AI demand, and 30-day visibility health — as a CSV file.
Third of the CSV export rollout (see #38 for Insights, #39 for
Topics). Same pattern, different dataset and a richer column set
because three data sources are joined on this page.
Why
The All Prompts tab is where marketers see everything they're
tracking on a single brand. A CSV makes it easy to:
- Inventory the prompt set for a stakeholder review
- Spot inactive prompts, missing topics, or under-targeted
platforms - Cross-reference search demand vs. actual visibility in a
spreadsheet pivot
Where the button goes
The toolbar that sits alongside the tabs lives at:
web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
around line 450 — the<div className="flex items-center justify-between gap-4 flex-wrap">wrappingTabsListand the Manage prompts link.
Place the Export button immediately before the Manage prompts
link, in the same row, only when the All Prompts tab is active:
{tab === 'all' && (
<Button variant="outline" size="sm" onClick={handleExport} ...>
<Download className="h-4 w-4" />
Export CSV
</Button>
)}
<Link href={...}>Manage prompts</Link>Reason: on the Insights tab the data shape is different — an
Export button there would either confuse users or need a separate
export flow. Keep it scoped.
- Use
<Button>from@/components/ui/button,variant="outline",
size="sm" - Icon:
Downloadfromlucide-react
What to export
The page already loads three related data structures:
allPrompts: Prompt[]— the prompt inventory (line 215)volumeByPromptId: Map<string, PromptVolume>— optional estimated
demand per prompt (line 419)visibility: Record<string, PromptVisibilitySummary>— optional
last-30-day health per prompt
The CSV joins all three by prompt.id. Columns (in this order):
| Column | Source |
|---|---|
text |
p.text |
topic_id |
p.topicId ?? "" |
category |
p.category ?? "" |
platforms |
`p.platforms.join(" |
models |
`p.models.join(" |
regions |
`p.regions.join(" |
is_active |
p.isActive |
created_at |
p.createdAt |
est_ai_volume |
volumeByPromptId.get(p.id)?.estAiVolume ?? "" |
total_google_volume |
volumeByPromptId.get(p.id)?.totalGoogleVolume ?? "" |
intent |
volumeByPromptId.get(p.id)?.intent ?? "" |
avg_visibility_30d |
visibility[p.id]?.avgVisibility ?? "" |
total_mentions_30d |
visibility[p.id]?.totalMentions ?? "" |
runs_30d |
visibility[p.id]?.runs ?? "" |
last_run_at |
visibility[p.id]?.lastRunAt ?? "" |
Skip: id, promptSetId (internal IDs, not useful in the CSV).
Note topic_id is included but topic_name is not — the page
doesn't have topic names loaded, and adding a fetch is out of scope.
CSV builder
If #38 or #39 has already landed, import the helper from
web/src/lib/csv.ts — don't duplicate it. If neither has landed
yet, create the same helper following this pattern:
// web/src/lib/csv.ts
function escape(value: unknown): string {
if (value === null || value === undefined) return "";
const s = String(value);
if (/[",\n]/.test(s)) return `"${s.replace(/"/g, '""')}"`;
return s;
}
export function toCsv(rows: Record<string, unknown>[], headers: string[]): string {
const headerLine = headers.join(",");
const dataLines = rows.map((row) =>
headers.map((h) => escape(row[h])).join(","),
);
return [headerLine, ...dataLines].join("\n");
}Trigger the download client-side:
const csv = toCsv(rowsForExport, headerArray);
const blob = new Blob([csv], { type: "text/csv;charset=utf-8" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `ansvisor_${brand.slug}_prompts_${new Date().toISOString().slice(0, 10)}.csv`;
a.click();
URL.revokeObjectURL(url);File naming convention: ansvisor_<brand-slug>_prompts_<YYYY-MM-DD>.csv.
Disabled state
The button should be disabled when:
allPrompts.length === 0- The page is still loading (
loading === true)
Tooltip on hover when disabled: "No prompts to export — add prompts
to this brand first."
How to verify
- Navigate to
/dashboard/prompts?tab=allwith a brand that has
prompts → Export button visible top-right, immediately left
of Manage prompts - Switch to the Insights tab → Export button is gone (only
shown on the All tab) - Click on All tab → file downloads with the correct name pattern
- Open the CSV → 15 columns, headers match the table above
- A prompt with no volume data →
est_ai_volume,
total_google_volume,intentare empty strings (not
undefined) - A prompt with no 30-day runs →
avg_visibility_30d,
total_mentions_30d,runs_30d,last_run_atare empty - Pipe-separated array columns (
platforms,models,
regions) render cleanly in Excel — no extra quoting, no
broken cells - Brand with zero prompts → button disabled with tooltip
Out of scope
- Excel format (CSV only for now)
- Async / background export
- Joining topic names (would need an extra fetch — separate concern)
- Other tabs (Insights tab has its own data shape; if we ever want
to export it, it's a separate issue) - Plan gating / rate limiting
Contribution guide
See CONTRIBUTING.md for branch naming, commit
conventions, and PR workflow.
Activity
sourabh-31 commentedon May 19, 2026
Hi, I would like to work on this issue.