Skip to content

feat(web): Dashboard and Alerts pages backed by live data - #67

Merged
vianbas merged 5 commits into
mainfrom
feat/66-dashboard-alerts-pages
Nov 19, 2026
Merged

vianbas merged 5 commits into
mainfrom
feat/66-dashboard-alerts-pages

Conversation

@vianbas

@vianbas vianbas commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #65. This PR targets the #65 branch so the diff shows only this work. After #65 merges, retarget it to main; GitHub does this automatically if the #65 branch is deleted.

Summary

This replaces the placeholder Dashboard and Alerts pages with real views over the existing REST API, so the realtime invalidation from #65 now visibly refreshes the UI. Frontend only: there are no contract or backend changes.

Closes #66

Architecture summary

  • Data layer:
    • lib/apiError.ts parses the canonical {"error":{"code","message"}} envelope into a typed ApiError.
    • requestJson sends every call through useApiFetch, which attaches the bearer token and logs out on 401.
    • The query hooks are useAlerts(status) (useInfiniteQuery with cursor "Load more"), useAlertPage, useTransactions and useAlertTransition.
    • Every key extends queryKeys.alerts or queryKeys.transactions, so transaction.observed / alert.raised events refresh every view.
  • Alerts page:
    • A semantic table with a caption and a status filter stored in ?status=. Unknown values fall back to "all".
    • Acknowledge is shown only for open alerts and Resolve only for acknowledged ones. Each row has its own pending state.
    • Transitions invalidate the alerts queries on success and on error, so a 409 INVALID_TRANSITION shows a dismissible role="alert" message and the stale list is refreshed.
  • Dashboard:
    • Open and acknowledged tiles come from a single limit=200 page and show "200+" when nextCursor is set, so there are no unbounded scans.
    • A Recharts bar chart of open alerts by severity (all four severities, zero-filled). The chart is aria-hidden and paired with a visible severity table as its text equivalent. Chart colours are tokens in index.css for light and dark themes.
    • A table of the 10 most recent transactions.
  • Money and time:
    • formatMoney scales integer minor units through bigint into an exact decimal string and uses the currency's minor-unit digits from Intl (e.g. JPY has 0). There is no float division and no summing across currencies.
    • formatTimestamp renders RFC 3339 values in UTC only at render time, inside <time dateTime>.

Security considerations

  • Synthetic data only; test fixtures use generated ids and ACC-* accounts.
  • No new dependencies and no secrets.
  • All requests use the existing bearer-token path. Error messages shown to users come from the API's display-safe message field, with a generic fallback.

Testing evidence

$ cd apps/web && npm run lint && npm run typecheck && npm test && npm run build
 Test Files  13 passed (13)
      Tests  69 passed (69)
✓ built in 1.87s
$ git diff --check claude/keen-hawking-qpa724   # clean
  • New tests:
    • The money formatter: USD, JPY, large values, bigint and string input.
    • Time formatting and error parsing.
    • The hooks: query params, cursor pagination, invalidation on success and on 409.
    • Actions shown per status, acknowledge success, the 409 message, and the filter updating both the URL and the request.
    • The "200+" tile, the severity table, and dashboard empty and error states.
  • Manual check in a real browser (headless Chromium against the real API, PostgreSQL and the Vite dev server):
    • Logged in through the UI, and the dashboard rendered with seeded synthetic data: tiles, chart, severity table and the transactions table with per-currency formatting.
    • Filtered alerts to open and clicked Acknowledge: the open rows went from 14 to 13 and the URL showed ?status=open.
    • With the dashboard open, api seed -n 15 moved the "Open alerts" tile from 13 to 24 without a reload, through the realtime stream.
    • No failed HTTP requests.

Known limitations

  • Recharts pushes the main JS chunk to about 664 kB, which triggers Vite's 500 kB warning. Not code-split here.
  • The dashboard counts are capped at 200 ("200+"); exact counts would need an aggregate endpoint.
  • amountMinor is typed number, because JSON parsing loses precision above 2^53. The formatter itself is exact for bigint and string input.
  • Chart colours follow the app's .dark class; the app does not handle prefers-color-scheme yet.
  • Out of scope: the Ops page, alert detail, rule management and RBAC.

Follow-up issues

  • Code-split the dashboard chart (lazy-load Recharts).
  • An aggregate counts endpoint, if exact totals are needed.

Checklist

claude added 4 commits October 6, 2026 16:53
formatMoney scales integer minor units through bigint/decimal strings
using the currency's Intl minor-unit digits (no float division).
formatTimestamp renders RFC 3339 values in UTC at the edge. ApiError
parses the canonical error envelope.

Refs #66

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
useAlerts (infinite, cursor), useAlertPage, useTransactions and
useAlertTransition, all via useApiFetch with keys built on the shared
queryKeys prefixes so realtime invalidation refreshes them.

Refs #66

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
Semantic table with status filter in the URL, Load more pagination,
per-status Acknowledge/Resolve actions and a non-fatal inline message
for 409 INVALID_TRANSITION.

Refs #66

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
…nt transactions

Open/acknowledged tiles ("200+" when truncated), a Recharts column
chart of open alerts by severity with an equivalent table, and the 10
most recent transactions.

Refs #66

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
@vianbas
vianbas merged commit d552cbd into main Nov 19, 2026
7 checks passed
@vianbas
vianbas deleted the feat/66-dashboard-alerts-pages branch November 19, 2026 00:30
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.

feat(web): Dashboard and Alerts pages backed by live data

2 participants