feat: lead dashboard with status history (conversion = WON) #29

Merged
ngqile merged 14 commits from add-lead-dashboard into main 2026-12-01 02:51:22 +00:00
Owner

OpenSpec change add-lead-dashboard. Design: docs/superpowers/specs/2026-12-01-lead-dashboard-design.md.

What it does

  • Status history: every event-lead status change is recorded (service-counter.event_lead_status_change) with time and user; capture records the first status. Existing leads are backfilled with approximate times.
  • Dashboard on the portal home page for users with the new BO_DASHBOARD module (others keep the welcome):
    • period: this month (default), last month, or a custom range up to 731 days, in Malaysian time; trend by day up to 62 days, else by month;
    • tiles: captures, new leads, won in period, conversion rate, median days to win, overdue follow-ups;
    • status funnel, captures/wins trend (recharts), breakdowns by event (drill-down to event leads), salesperson (incl. Unassigned) and interest;
    • company scope as everywhere: staff see their company, super admins all or the picked one.
  • Dashboard appears first in the sidebar (module id 40050000); super admins grant it under Roles.

Layers

  • services-counter: history writes in capture/update; POST /counter/dashboard/leads — three bound-parameter native queries, aggregation in a pure unit-tested calculator (ponytail: ceiling noted).
  • mobile-api: GET /api/admin/dashboard/leads (BO_DASHBOARD, period validation and defaults, company scope, salesperson names).
  • portal: recharts 3.10.1 + shadcn chart.tsx (allow-listed in the HTML-sink sweep, as in babyboo: its <style> is built from code constants only), proxy app/api/dashboard/leads, LeadDashboard, phone cards.
  • SQL in openspec/changes/add-lead-dashboard/sql/, mirrored in local/seed/03-colite.sql; docs/deployment.md lists them. Run 01–03 before the new images go live (services-counter writes the new table on every capture and status edit).

Verification

  • services-counter 168, mobile-api 731, portal 1375 tests green; lint 0 errors; tsc clean.
  • Per-task Opus reviews (2 tasks needed one fix round) and a whole-branch Opus review: PASS.
  • Live check against the local stack and Playwright at 1280 and 360 px: super admin all / CV; INS staff scoped (asking for CV still gets INS); staff without the module see the welcome and the API is never called (403 if called); reversed and >731-day ranges 400 with a message; wins, median and overdue correct after real status edits; history rows correct; drill-down link.
  • The live check found three bugs the tests missed, each fixed test-first: mobile-api did not start (two constructors, no @Autowired), the sidebar showed BO_DASHBOARD, the last phone card lost its border.

Known / accepted

  • Backfilled history times are approximate.
  • Event with a missing event row shows a blank name (local test data only).
  • An empty bearer token gives 500 instead of 401 (pre-existing, HttpReqRespUtils.getJwtToken).
  • Salesperson names are looked up one call per distinct salesperson (existing pattern).
  • Even number of wins: median is the lower middle value (per design).

🤖 Generated with Claude Code

https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM

OpenSpec change `add-lead-dashboard`. Design: `docs/superpowers/specs/2026-12-01-lead-dashboard-design.md`. ## What it does - **Status history:** every event-lead status change is recorded (`service-counter.event_lead_status_change`) with time and user; capture records the first status. Existing leads are backfilled with approximate times. - **Dashboard** on the portal home page for users with the new `BO_DASHBOARD` module (others keep the welcome): - period: this month (default), last month, or a custom range up to 731 days, in Malaysian time; trend by day up to 62 days, else by month; - tiles: captures, new leads, won in period, conversion rate, median days to win, overdue follow-ups; - status funnel, captures/wins trend (recharts), breakdowns by event (drill-down to event leads), salesperson (incl. Unassigned) and interest; - company scope as everywhere: staff see their company, super admins all or the picked one. - `Dashboard` appears first in the sidebar (module id 40050000); super admins grant it under Roles. ## Layers - services-counter: history writes in capture/update; `POST /counter/dashboard/leads` — three bound-parameter native queries, aggregation in a pure unit-tested calculator (`ponytail:` ceiling noted). - mobile-api: `GET /api/admin/dashboard/leads` (`BO_DASHBOARD`, period validation and defaults, company scope, salesperson names). - portal: `recharts` 3.10.1 + shadcn `chart.tsx` (allow-listed in the HTML-sink sweep, as in babyboo: its `<style>` is built from code constants only), proxy `app/api/dashboard/leads`, `LeadDashboard`, phone cards. - SQL in `openspec/changes/add-lead-dashboard/sql/`, mirrored in `local/seed/03-colite.sql`; `docs/deployment.md` lists them. **Run 01–03 before the new images go live** (services-counter writes the new table on every capture and status edit). ## Verification - services-counter 168, mobile-api 731, portal 1375 tests green; lint 0 errors; tsc clean. - Per-task Opus reviews (2 tasks needed one fix round) and a whole-branch Opus review: PASS. - Live check against the local stack and Playwright at 1280 and 360 px: super admin all / CV; INS staff scoped (asking for CV still gets INS); staff without the module see the welcome and the API is never called (403 if called); reversed and >731-day ranges 400 with a message; wins, median and overdue correct after real status edits; history rows correct; drill-down link. - The live check found three bugs the tests missed, each fixed test-first: mobile-api did not start (two constructors, no `@Autowired`), the sidebar showed `BO_DASHBOARD`, the last phone card lost its border. ## Known / accepted - Backfilled history times are approximate. - Event with a missing `event` row shows a blank name (local test data only). - An empty bearer token gives 500 instead of 401 (pre-existing, `HttpReqRespUtils.getJwtToken`). - Salesperson names are looked up one call per distinct salesperson (existing pattern). - Even number of wins: median is the lower middle value (per design). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
ngqile added 14 commits 2026-12-01 02:51:19 +00:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
recharts 3.10.1 (same as babyboo's portal) for the lead dashboard trend.
The chart wrapper's <style> is built from its colour config only, so it
joins the HTML-sink allow list as in babyboo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Capture and status edits append to event_lead_status_change. POST
/counter/dashboard/leads aggregates captures, wins, overdue follow-ups
and the breakdowns for a Malaysian-day period (at most 731 days).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
BO_DASHBOARD-gated lead dashboard: Malaysian-month default period, at
most 731 days, DAY or MONTH buckets, company scope, salesperson names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Users with BO_DASHBOARD get period presets, capture and win tiles, the
status funnel, a captures/wins trend and breakdowns by event,
salesperson and interest; everyone else keeps the welcome.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
With a second, package-private constructor for a test clock, Spring found
no default constructor and mobile-api failed to start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
The sidebar shows a module by its name as a message key; BO_DASHBOARD had
no default, so the raw code showed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
A second run after go-live no longer adds a fake OPEN->status row for a
lead captured with another status, which would move its win date.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
ngqile merged commit a8d42a8a25 into main 2026-12-01 02:51:22 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ngqile/co-lite#29