feat(admin): finance dashboard on the home page (#47, slice 1) #148

Merged
amiryahaya merged 10 commits from feat/admin-dashboard into main 2026-11-03 03:26:01 +01:00
Owner

First slice of #47: a finance dashboard on the admin home page. Later slices add report pages for the other report APIs; the partner report waits for #51.

Design: docs/superpowers/specs/2026-11-03-admin-dashboard-design.md · Plan: docs/superpowers/plans/2026-11-03-admin-dashboard.md

What changes

  • API: GET /v1/admin/reports/dashboard

    • Needs admin_portal.reports.view at platform scope; rate class heavy; no-store; no parameters (today is the server's Nairobi day).
    • One REPEATABLE READ READ ONLY snapshot, 3 s timeout, which reads the per-day figures of the last 12 months:
      • sold: park-entry tickets of sales completed that day. Masters, vehicle tickets and top-up replacements are left out.
      • used: check-ins of non-master tickets that day.
      • used_value: the purchase_price of those check-ins, a used-ticket figure, not a sales figure.
      • collected: grand total less waivers, for every completed sale type.
    • reports.BuildDashboard (plain Go) builds 30 daily and 12 monthly buckets with no gaps. Today, this month and this year come from those buckets.
    • Money is per currency and never added across currencies or converted.
    • OpenAPI operation getDashboard, contract live test, rate class and CLAUDE.md updated.
  • @kws/ui LineChart:

    • an inline SVG with no chart library;
    • line styles differ by colour and dash pattern;
    • the data is also a hidden table for screen readers;
    • "No data" is shown when there is nothing to draw.
  • Admin home page: users with reports.view see:

    • a table with tickets sold, tickets used, money collected and value of tickets used for Today, This month and This year, one row per currency;
    • a Last 30 days / Last 12 months switch, a Refresh button, and the two charts;
    • links below as before.

    The query keeps a minute-old answer and is not retried. A 503 or 429 shows the fixed try-again texts. Money rows with no currency show "—". The page adds nothing up.

Verification

  • make cover: 91.6 % total (minimum 80 %).

  • make lint 0 issues; make contract passes.

  • Web unit tests: admin 407, ticket 304, ui 52, auth 45, all passing; typecheck is clean.

  • scripts/web-e2e.sh: ticket 207, admin 131. The admin count includes a new dashboard journey at 320, 768 and 1280 px, with axe checks and no sideways scrolling.

  • Store tests on PostgreSQL cover:

    • the Nairobi midnight boundary (20:59:59Z / 21:00:00Z);
    • masters and vehicles excluded;
    • a top-up counted once;
    • waived and mixed-currency sales;
    • pending and cancelled sales excluded.

    Builder tests cover gaps, 1 January and overflow.

  • Real local run against the dev DB: 25 sold and 10 used on 29 October, matching direct SQL counts. The run showed empty money sections for the dev data's free sales; these now show "—".

  • EXPLAIN on dev: the ranges use transactions_completed_idx and ticket_activities_created_idx.

  • Review:

    • Pass 1 (complexity): Ship.
    • Pass 2 (correctness): two Important findings fixed, each with a test that failed first:
      • the money groups shared one screen-reader header;
      • the home page refetched against the heavy rate budget, and a 429 showed as a load failure.
    • The Pass 1 re-check's should-fix was applied: the page reuses the shared call and failureText.

Open for the owner

  • 3 s on a year of legacy-sized data is not measured. There is no such data until the legacy import (#7). If it is too slow, the fix is pre-aggregating daily totals, not a longer timeout.
  • [verify]:
    1. Vehicles are excluded from tickets sold.
    2. Waived sales' tickets count in value of tickets used.
    3. Customer Service Officer and Operations see money figures.
    4. Money collected counts every sale type.

Deferred minors

  1. Once vehicle check-in exists, used would count vehicles while sold does not.
  2. All currencies share one y-axis on the money chart.
  3. The loading text has no role=status, and Retry and Refresh show no busy state.
  4. The 503 problem text says "narrow the filters", but the dashboard has none.
  5. "At a glance" is announced three times.
  6. The chart's "No data" is English from @kws/ui.
  7. The store's unused day-order slice; completedDay is a third way of writing the same SQL expression.

🤖 Generated with Claude Code

First slice of #47: a finance dashboard on the admin home page. Later slices add report pages for the other report APIs; the partner report waits for #51. Design: `docs/superpowers/specs/2026-11-03-admin-dashboard-design.md` · Plan: `docs/superpowers/plans/2026-11-03-admin-dashboard.md` ## What changes - **API: `GET /v1/admin/reports/dashboard`** - Needs `admin_portal.reports.view` at platform scope; rate class `heavy`; `no-store`; no parameters (today is the server's Nairobi day). - One `REPEATABLE READ READ ONLY` snapshot, 3 s timeout, which reads the per-day figures of the last 12 months: - **sold:** park-entry tickets of sales completed that day. Masters, vehicle tickets and top-up replacements are left out. - **used:** check-ins of non-master tickets that day. - **used_value:** the `purchase_price` of those check-ins, a used-ticket figure, not a sales figure. - **collected:** grand total less waivers, for every completed sale type. - `reports.BuildDashboard` (plain Go) builds 30 daily and 12 monthly buckets with no gaps. Today, this month and this year come from those buckets. - Money is per currency and never added across currencies or converted. - OpenAPI operation `getDashboard`, contract live test, rate class and `CLAUDE.md` updated. - **`@kws/ui` `LineChart`:** - an inline SVG with no chart library; - line styles differ by colour and dash pattern; - the data is also a hidden table for screen readers; - "No data" is shown when there is nothing to draw. - **Admin home page:** users with `reports.view` see: - a table with tickets sold, tickets used, money collected and value of tickets used for Today, This month and This year, one row per currency; - a Last 30 days / Last 12 months switch, a Refresh button, and the two charts; - links below as before. The query keeps a minute-old answer and is not retried. A 503 or 429 shows the fixed try-again texts. Money rows with no currency show "—". The page adds nothing up. ## Verification - `make cover`: **91.6 %** total (minimum 80 %). - `make lint` 0 issues; `make contract` passes. - Web unit tests: admin 407, ticket 304, ui 52, auth 45, all passing; typecheck is clean. - `scripts/web-e2e.sh`: ticket 207, admin 131. The admin count includes a new dashboard journey at 320, 768 and 1280 px, with axe checks and no sideways scrolling. - Store tests on PostgreSQL cover: - the Nairobi midnight boundary (`20:59:59Z` / `21:00:00Z`); - masters and vehicles excluded; - a top-up counted once; - waived and mixed-currency sales; - pending and cancelled sales excluded. Builder tests cover gaps, 1 January and overflow. - **Real local run against the dev DB:** 25 sold and 10 used on 29 October, matching direct SQL counts. The run showed empty money sections for the dev data's free sales; these now show "—". - EXPLAIN on dev: the ranges use `transactions_completed_idx` and `ticket_activities_created_idx`. - **Review:** - Pass 1 (complexity): Ship. - Pass 2 (correctness): two Important findings fixed, each with a test that failed first: - the money groups shared one screen-reader header; - the home page refetched against the heavy rate budget, and a 429 showed as a load failure. - The Pass 1 re-check's should-fix was applied: the page reuses the shared `call` and `failureText`. ## Open for the owner - **3 s on a year of legacy-sized data is not measured.** There is no such data until the legacy import (#7). If it is too slow, the fix is pre-aggregating daily totals, not a longer timeout. - **[verify]:** 1. Vehicles are excluded from tickets sold. 2. Waived sales' tickets count in value of tickets used. 3. Customer Service Officer and Operations see money figures. 4. Money collected counts every sale type. ## Deferred minors 1. Once vehicle check-in exists, `used` would count vehicles while `sold` does not. 2. All currencies share one y-axis on the money chart. 3. The loading text has no `role=status`, and Retry and Refresh show no busy state. 4. The 503 problem text says "narrow the filters", but the dashboard has none. 5. "At a glance" is announced three times. 6. The chart's "No data" is English from `@kws/ui`. 7. The store's unused day-order slice; `completedDay` is a third way of writing the same SQL expression. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EXPLAIN on the dev DB: transactions_completed_idx and
ticket_activities_created_idx serve the ranges; tickets is a seq scan
only because the dev table is tiny.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each money figure is its own tbody so screen readers head its currency
rows with it alone; a 429 shows the try-again text; the query keeps a
minute-old answer and is not retried (the route is in the heavy class).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
refactor(admin): dashboard uses the shared call and failureText (#47)
All checks were successful
ci / changes (pull_request) Successful in 19s
ci / clients (pull_request) Successful in 1m29s
ci / web (pull_request) Successful in 5m56s
ci / api (pull_request) Successful in 16m58s
ci / ci-gate (pull_request) Successful in 4s
75264c6a63
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!148
No description provided.