Skip to content

feat(prompts): add CSV export button on the All Prompts tab #41

Closed

Description

@gkhngyk

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"> wrapping TabsList and 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: Download from lucide-react

What to export

The page already loads three related data structures:

  1. allPrompts: Prompt[] — the prompt inventory (line 215)
  2. volumeByPromptId: Map<string, PromptVolume> — optional estimated
    demand per prompt (line 419)
  3. 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=all with 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, intent are empty strings (not
    undefined)
  • A prompt with no 30-day runs → avg_visibility_30d,
    total_mentions_30d, runs_30d, last_run_at are 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

  1. added
    enhancement
    good first issue
    help wanted
    on May 18, 2026
  2. sourabh-31 commented on May 19, 2026

    @sourabh-31
    Contributor

    Hi, I would like to work on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions