Skip to content

feat(insights): added csv export button on the answer engine insights page header - #73

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
sourabh-31:feat/insights-csv-export
May 22, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
sourabh-31:feat/insights-csv-export

Conversation

@sourabh-31

@sourabh-31 sourabh-31 commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

  • Added an Export CSV button to the Insights page header.
  • The export button is now always visible in both cloud and self-host modes.
  • Refactored the action button cluster so Test Single Prompt and Run All remain self-host-only while Export CSV is shared across environments.
  • Added a lightweight CSV helper utility to generate properly escaped CSV output without introducing a new dependency.
  • Export uses the already-loaded results state, so active filters (date range, region, model, topic, etc.) are automatically reflected in the downloaded file.
  • Added disabled handling for empty/loading states to prevent exporting invalid datasets.

How to test the change

  1. Open /dashboard/insights with a brand that has prompt results.

  2. Verify the Export CSV button appears in the top-right header area.

  3. Click the button and confirm a CSV file downloads with the format:
    ansvisor_<brand-slug>_results_<YYYY-MM-DD>.csv

  4. Open the CSV in Excel or Google Sheets and verify:

    • columns are aligned correctly
    • rows are not broken
    • citations and competitor mentions are flattened properly
  5. Apply filters (date range, region, model, topic) and re-export.

  6. Confirm the exported rows match the currently visible filtered dataset.

  7. Verify the button is disabled when:

    • results are empty
    • the page is loading
  8. Verify cloud mode only shows Export CSV, while self-host mode still shows:

    • Test Single Prompt
    • Run All

Screenshot

image

This closes issue #38

@gkhngyk

gkhngyk commented May 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution, @sourabh-31! The CSV export itself looks good — it reuses the shared toCsv util and mirrors the existing prompts-page export (filename convention, blob + download), and the button visibility is right (Export always on, Run All / Test Single Prompt kept self-host only).

One thing to sort out before merge: the diff shows +287/−102, but most of it is unrelated Prettier reformatting of code the feature doesn't touch (whole-file multi-line rewrapping). This makes the change hard to review and risks merge conflicts, since insights/page.tsx is a hot file that other in-flight PRs also touch.

Could you revert the formatting-only changes and keep just the feature hunks — the Download import, INSIGHT_EXPORT_HEADERS, the toCsv import, handleExportCsv, and the header button? It looks like your editor may have reformatted the file on save with a different Prettier config; running the repo's Prettier/yarn lint config (or resetting the untouched lines) should clean it up.

Once the diff is just the feature, this is good to merge. Thanks again! 🙌

@sourabh-31

Copy link
Copy Markdown
Contributor Author

Thanks for the contribution, @sourabh-31! The CSV export itself looks good — it reuses the shared toCsv util and mirrors the existing prompts-page export (filename convention, blob + download), and the button visibility is right (Export always on, Run All / Test Single Prompt kept self-host only).

One thing to sort out before merge: the diff shows +287/−102, but most of it is unrelated Prettier reformatting of code the feature doesn't touch (whole-file multi-line rewrapping). This makes the change hard to review and risks merge conflicts, since insights/page.tsx is a hot file that other in-flight PRs also touch.

Could you revert the formatting-only changes and keep just the feature hunks — the Download import, INSIGHT_EXPORT_HEADERS, the toCsv import, handleExportCsv, and the header button? It looks like your editor may have reformatted the file on save with a different Prettier config; running the repo's Prettier/yarn lint config (or resetting the untouched lines) should clean it up.

Once the diff is just the feature, this is good to merge. Thanks again! 🙌

Thanks for the review! I reverted almost all of the unrelated formatting changes — around 98% of them are gone now. A few tiny formatting diffs may still remain in the file because my editor auto-formatted some touched sections while saving.

I also think it would help a lot if we add a shared Prettier config to the repo (and possibly enforce it through lint-staged/CI), so everyone’s editor follows the exact same formatting rules and we can avoid noisy diffs like this in future PRs.

The actual feature changes are now isolated to the CSV export additions only. 🙌

@gkhngyk

gkhngyk commented May 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for the update, @sourabh-31 — the diff is much smaller now (287 → 117) and the feature itself looks good. 🙌

It's almost there, but a few formatting-only changes are still mixed in, and the manual cleanup introduced some new whitespace issues. Could you revert those back to main so the PR contains only the CSV-export feature?

⚠️ Heads-up: please don't run Prettier on this file — the repo isn't Prettier-formatted (the existing code is hand-formatted), so a formatter is exactly what produced the original noise. The goal is just to match main everywhere except the feature.

New whitespace issues to fix:

  • import { Table, TableBody, ... } — trailing spaces after { and after each item
  • groupResultsByPlatform( items: ...) — stray space after (
  • e.stopPropagation();onViewResult(r); — missing space after ;
  • ... {group.results.length - 1}{' '} previous runs. — the {' '} plus a literal space renders a double space; revert to the original single line
  • .sort((a, b) => — trailing space

Still-unrelated reformatting to revert to main: the Table import wrapping, the InsightsSkeleton indentation, the </CardContent>/</Card> closings around the competitor cards, and the DeltaBadge block under "Share of Voice by Platform".

Feature hunks to keep: the Download import, INSIGHT_EXPORT_HEADERS, the toCsv import, handleExportCsv, and the header button block.

Once those are the only changes left, this is good to merge. Thanks again! 🙏

@gkhngyk
gkhngyk merged commit d8e2642 into ansvisor:main May 22, 2026
@gkhngyk

gkhngyk commented May 22, 2026

Copy link
Copy Markdown
Contributor

🚀

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants