Repository navigation
Description
What
Add a Export CSV button to the top-right of the Topics page
header, next to the existing Manage topics link. Clicking it
downloads the currently-displayed topic overview rows as a CSV file.
This is the second of several CSV export issues we're rolling out
(see #38 for the Answer Engine Insights page). Same pattern, different
dataset.
Why
Topics gives a marketer the highest-leverage roll-up of the data —
"which themes are working, which are bleeding, which competitor owns
which topic." Right now this view is read-only. A CSV makes it
shareable in a board deck, pivotable in Excel, and pipeable into
BI tools.
Where the button goes
The header lives at:
web/src/app/[locale]/(dashboard)/dashboard/topics/page.tsxaround
line 234 — the<div className="flex items-center justify-between gap-4 flex-wrap">wrapping the title + the Manage topics link.
Place the Export button immediately before the existing
Manage topics link inside that right-side cluster, with the same
visual weight:
- Use
<Button>from@/components/ui/button,variant="outline",
size="sm" - Icon:
Downloadfromlucide-react
What to export
The page already loads TopicOverviewRow[] into the topics state
(see line 151 of page.tsx, and the type at
web/src/lib/actions/topic.ts:113). Export the rows currently in
state — that automatically respects the page's "last 30 days"
window and active brand.
CSV columns (in this order):
| Column | Source |
|---|---|
topic |
t.name |
prompt_count |
t.promptCount |
avg_visibility_score |
t.avgVisibilityScore |
visibility_change |
t.visibilityChange ?? "" |
total_mentions |
t.totalMentions |
total_citations |
t.totalCitations |
share_of_voice |
t.shareOfVoice |
top_competitor |
t.topCompetitor?.name ?? "" |
top_competitor_sov |
t.topCompetitor?.sov ?? "" |
last_run_at |
t.lastRunAt ?? "" |
Skip id (internal) and trendSparkline (an array of numbers — not
useful in a flat CSV). If we ever want trend data, that's a separate
export with its own structure.
CSV builder
If #38 has already landed, import the helper from
web/src/lib/csv.ts — don't duplicate it. If #38 hasn't landed
yet, create the same helper following the pattern below:
// 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 (no API route needed for this scale):
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}_topics_${new Date().toISOString().slice(0, 10)}.csv`;
a.click();
URL.revokeObjectURL(url);File naming convention: ansvisor_<brand-slug>_topics_<YYYY-MM-DD>.csv.
Disabled state
The button should be disabled when:
topics.length === 0(nothing to export)- The page is still loading (
loading === true)
Show a subtle tooltip on hover when disabled: "No topics yet — add
topics or run a tracking job first."
How to verify
- Navigate to
/dashboard/topicswith a brand that has tracked
topics → Export button visible top-right, just left of
Manage topics - Click → file downloads with the correct name pattern
- Open the CSV → 10 columns, headers match the table above,
no broken rows - A topic with no
topCompetitor(null) exports empty strings
fortop_competitor/top_competitor_sov(notnull/undefined) - A topic with no
visibilityChangeexports empty string for
that column (not0, notnull) - Switch to a different brand → re-export → file reflects the
new brand's topics - Brand with zero topics → button disabled with tooltip
Out of scope
- Excel format (CSV only for now)
- Async / background export
- Other datasets (Citations, AI Traffic, etc. — separate issues)
- Plan gating / rate limiting
- Trend sparkline data (separate export shape if ever needed)
Contribution guide
See CONTRIBUTING.md for branch naming, commit
conventions, and PR workflow.
Activity
qorexdevs commentedon May 18, 2026
i can take this if it's still open. scope i plan to ship: add the export button in the topics header before 'Manage topics', reuse/create web/src/lib/csv.ts (same pattern as #38), export from current topics state with the disabled + tooltip behavior, and verify with the checklist in this issue. if that works for you, i'll open a focused PR.
gkhngyk commentedon May 18, 2026
Welcome to Ansvisor — and thanks for the clean scope outline before opening a PR, that's exactly the right way to start. Yes, please go for it.
A small note on the helper question since you flagged it: #38 is still open and untouched, so you'll be the first to create
web/src/lib/csv.ts. Whoever picks up #38 next will then just import it. No coordination needed on your end — just create the helper as part of this PR.The checklist in the issue is the canonical acceptance criteria — if all those pass and
yarn typecheckis clean, we're good to merge. Looking forward to the PR.qorexdevs commentedon May 19, 2026
quick update: this is on my queue for today. i'll start with the topics-header button plus csv helper and open a focused PR after yarn typecheck passes.
fix(tracking): read a fan-out an engine joined with semicolons as eac…