Skip to content

Build the line analytics dashboard (W7-09) - #169

Merged
calebyhan merged 2 commits into
mainfrom
162/analytics-dashboard
Nov 19, 2026
Merged

calebyhan merged 2 commits into
mainfrom
162/analytics-dashboard

Conversation

@calebyhan

@calebyhan calebyhan commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Coordinators need numbers for grant reports and for deciding on hours (TDD 4.6.9). The line analytics API and CSV export landed in #167 (for #142), but /portal/admin/analytics was still a placeholder. This replaces it with a dashboard built on those endpoints.

Changes:

  • Added AnalyticsDashboard (components/admin/AnalyticsDashboard.tsx) and used it on the Analytics page, inside <Suspense> because it reads the URL with useSearchParams.
  • Controls: date range presets (last 7 days, last 30 days, this semester, custom) and a channel filter (All / Web / SMS). All of it is kept in the query string (?range=, start/end for custom only, channel=) and updated with router.replace. No params means last 30 days, which matches the API default. A custom range that's over 366 days, or has the start after the end, shows an inline error and sends no request.
  • "This semester" is hard-coded for now because there's no semester setting: spring is from Jan 1, summer from Jun 1, fall from Aug 1, each through today. "Today" is the browser's local date.
  • Summary tiles: total conversations, median and p90 time to first response, median conversation length, median message count, and after-hours attempts. Durations are formatted by a new formatDuration helper (lib/dates.ts), e.g. "2m 30s", "1h 5m", and "—" for null.
  • Charts: conversations per day (the API's series already includes zero days), topics, and outcomes, plus the average confidence shown as "x out of 5". Topics and outcomes use horizontal bars with the labels on the left: they're editable and can be long, and at 375px vertical bars dropped labels that didn't fit. Each chart is aria-hidden, with a visually hidden table that carries the same data for screen readers.
  • Small groups: when the range has any conversations, the topic and outcome charts note "Groups with fewer than N conversations are hidden", with N taken from suppression_threshold. The API drops those groups without listing them, so the note can't be shown only when something was actually dropped. A null confidence average gets its own note.
  • "Download CSV" links to /api/admin/analytics/line.csv with the current start/end. The CSV endpoint doesn't take channel, so the export always covers all channels, and the page says so when a channel is selected.
  • The website analytics link (Add privacy-safe website analytics (W7-11) #164) only renders when NEXT_PUBLIC_WEBSITE_ANALYTICS_URL is set. It's documented in .env.example so Add privacy-safe website analytics (W7-11) #164 can set it.
  • Added the LineAnalytics type and a useLineAnalytics hook to lib/portal/queries.ts. The type is written by hand, like the others there, because api-types.ts predates the analytics DTO.
  • No per-conversation drill-down. The page only shows the aggregates the API returns.

Charts: this adds Recharts (npm install recharts), confirming TDD open question 15.

Tests, with a mocked response: the tiles show formatted durations; the range and channel controls change both the request and the URL; a custom range is read from the URL, and one over 366 days is rejected without a request; the small-group and confidence notes appear; the CSV link carries the current range; the website analytics link stays hidden when it isn't configured. There are also unit tests for the new date helpers. Frontend lint, typecheck, format check, the full Vitest suite and next build pass. There are no backend changes.

Follow-up:

  • Replace the hard-coded semester boundaries with a coordinator setting if Peer2Peer wants different dates.
  • Add channel to the CSV endpoint if coordinators want per-channel exports.

Screenshots (also committed under docs/screenshots/analytics-dashboard/), using fixture data and a synthetic coordinator session:

Last 30 days, 1280px Last 30 days, 375px
Analytics dashboard, desktop Analytics dashboard, mobile
Custom range, SMS only
Custom range filtered to SMS, with small groups hidden

The last one shows the small-group notes, the suppressed confidence average, and the note that the CSV covers all channels. The header says "Reconnecting…" only because the portal socket was blocked during capture.

Closes #162

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Backend Test Results

713 tests  ±0   713 ✅ ±0   21s ⏱️ -3s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 08dcffc. ± Comparison against base commit 480809e.

♻️ This comment has been updated with latest results.

@MasonMines2006 MasonMines2006 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@calebyhan
calebyhan merged commit f435caa into main Nov 19, 2026
4 checks passed
@calebyhan
calebyhan deleted the 162/analytics-dashboard branch November 19, 2026 21:15
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.

Build the line analytics dashboard (W7-09)

2 participants