Skip to content

feat(reports): Simple Reports MVP — immutable snapshot reports with AI summary and vector PDF export - #390

Merged
gkhngyk merged 7 commits into
mainfrom
feature/simple-reports-mvp
Jul 10, 2026
Merged

gkhngyk merged 7 commits into
mainfrom
feature/simple-reports-mvp

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Simple Reports MVP: generate an immutable, shareable AI-visibility report for a brand over a chosen period, with an AI-written executive summary and a true vector PDF export.

Data & backend

  • reports table (migration 00023, already applied to the hosted DB) — immutable JSONB payload, org-membership RLS mirroring site_audits; no UPDATE policy on purpose. supabase/schema.sql regenerated.
  • POST /api/reports/summary — turns the metric snapshot into a 1–2 paragraph executive summary (content.js pattern: resolveModel + one generateText, assertBrandAccess-guarded).

Report generation (web/src/lib/actions/reports.ts)

  • createReport gathers insights KPIs, share of voice, competitor comparison, citations overview, daily visibility trend, best/worst prompts, and observed query fan-out — all in parallel — then saves the snapshot + AI summary as one payload. Prompt performance and fan-out aggregate over the report's own [dateFrom, dateTo] window (the existing helpers anchor to "now", which lies for historical ranges).
  • getReports / getReport / deleteReport.

UI

  • /dashboard/reports — generate dialog (7d/30d/90d/custom presets, optional title) + report library table (view/delete).
  • /dashboard/reports/[id] — renders purely from the saved payload: executive summary, KPI cards with deltas, Recharts visibility trend (reuses the insights TrendChart), SoV bars, competitor leaderboard, best/weakest prompts, query fan-out, top citation sources. Sections added after launch guard on their payload field, so older (immutable) reports render without them.
  • Vector PDF export via @react-pdf/renderer (loaded on demand): selectable text, exact layout, page numbers, trend chart drawn with PDF SVG primitives. Static Inter TTFs are embedded because the built-in Helvetica can't render ş/ğ/ı in brand names and prompt texts.
  • Soft launch: no sidebar entry yet — the page is reachable at /dashboard/reports directly.

Fixes that fell out of this

  • getVisibilityTrend rounded daily averages to integers, flattening realistic sub-2% averages into a constant 1; now keeps one decimal (roundTo1).
  • TrendChart pinned its Y axis to [0, 100]; it now uses the existing niceVisibilityYMax adaptive ceiling.

Related issue

—

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Navigate to /dashboard/reports (no sidebar entry yet).
  2. Generate Report → pick "Last 30 days" → Generate. You should land on the report detail page with the AI executive summary and all sections populated.
  3. Download PDF → check typography, the trend chart, page breaks, and non-ASCII characters in brand/prompt names.
  4. Back on the list page: the report appears in the library; delete works.
  5. Server tests: cd server && npm test (99 passing).

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

gkhngyk added 7 commits July 9, 2026 21:03
…I executive summary

- reports table (00023) with org-membership RLS, immutable JSONB payload
- POST /api/reports/summary: AI executive summary from the metric snapshot
- createReport gathers insights/SoV/competitors/citations via existing actions
- Reports library page: generate dialog (7d/30d/90d/custom) + list/view/delete
- Report detail page renders fully from the saved payload (no live queries)
- Sidebar nav item + en.json strings

PDF download ships separately once the report view is validated.
…source types, best/worst prompts

- payload gains visibilityTrend + promptPerformance (best/worst 5 by avg
  visibility, aggregated over the report's own [dateFrom, dateTo] window)
- render the platformBreakdown and sourceTypeBreakdown data that was
  already snapshotted but never displayed
- new sections guard on their payload field so pre-existing (immutable)
  reports render without them
… fan-out

- trend bars now sit in full-height column wrappers (bare percentage
  heights on flex items are unreliable) and normalize to the window's
  peak score so low-visibility periods still read as a curve
- remove the Platform Breakdown section per review
- new Query Fan-out section: top 10 observed sub-queries in the report
  period (windowed to [dateFrom, dateTo], mirroring fanout.ts grouping)
Replace the hand-rolled div bars with the insights page's TrendChart
(same VisibilityTrendPoint shape the payload already stores) — proper
area chart with adaptive axis and the avg-competitor overlay, loaded
client-only via next/dynamic like insights does.
… brands

Two resolution killers stacked up:
- getVisibilityTrend rounded daily averages to integers, crushing the
  realistic 0.3-1.5 band into a constant 1 (both brand and competitor
  series) — keep one decimal via roundTo1, matching getInsightsSummary
- TrendChart pinned its Y axis to [0, 100]; switch it to the existing
  niceVisibilityYMax adaptive ceiling the other charts already use
Replace the html2canvas screenshot approach (blurry, layout shifts,
raster text) with a real vector PDF document: selectable text, exact
layout, smart page breaks, trend chart drawn with PDF SVG primitives,
footer with page numbers.

Static Inter TTFs are embedded from /public/fonts because the built-in
Helvetica can't render Turkish characters (ş, ğ, ı) that appear in
brand names and prompt texts. Renderer + document load on demand.
- remove the sidebar entry — Reports stays reachable at /dashboard/reports
  while we keep the feature quiet for now
- drop the Source Type Breakdown bars from the citations card and the PDF
  (data stays in the payload, so re-enabling is a render-only change)
@gkhngyk
gkhngyk merged commit d1e9ac9 into main Jul 10, 2026
5 checks passed
@gkhngyk gkhngyk mentioned this pull request Jul 12, 2026
7 tasks done
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.

1 participant