refactor: consolidate stat-card markup in static analytics template (#4923) - #4931
refactor: consolidate stat-card markup in static analytics template (#4923)#4931frano-m wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request refactors the shared static analytics template to consolidate duplicated “stat card” HTML into a single statCard() helper with an options object, while also tightening up change-percentage calculation and the access-requests stats/table rendering logic.
Changes:
- Expanded
statCard(value, label, { change, gridClass, tooltip })to support optional change rows, optional grid classes, tooltips, and multi-line labels. - Updated the top stats grid (
renderStats) and key metrics (renderEventCounts) to reusestatCard()andpctChange(). - Reworked access-requests rendering to accept pre-fetched JSON, compute per-service counts generically, and render per-service cards dynamically.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Follow-up review pass ( The defect: Also in this commit:
One item deliberately not applied, flagged for a call: Verified: display parity against real AnVIL fixture data (−19.9% / −23.7% / −31.7% / +7.1% identical before and after), all three card families, table change cells still coloured, tooltips working, malformed-payload path intact, zero JS errors. 🤖 Generated with Claude Code |
Closes #4923
What changed
The stat-card markup in the shared static analytics template was hand-written in three places and had diverged (tooltip/change-row/grid-class combinations). This PR consolidates all three onto the existing
statCard()helper, extended with an options object:statCard(value, label, { change, gridClass, tooltip })— omittingchangeomits the change row;nullrenders "N/A vs prior month"; multi-line labels (\n) render as line breaks;gridClassis omitted when the container sizes cards itself (access-requests grid).renderStats): output byte-identical (verified by string comparison across all change states: positive, negative, null, zero).renderEventCounts): inline copy deleted; now also reusespctChange()instead of hand-rolling the same formula (?? 0preserves its old "+0%" default exactly).pctChange()hardened with aNumber.isFiniteguard (a non-finite result now renders "N/A vs prior month" instead of "NaN%" — pre-existing, practically unreachable edge).One deliberate visual delta: event-count and access-request labels now sit in the same
stat-label-wrapwrapper as the top stats, which adds a few pixels of label height on those cards — that's the unification working as intended, flagged here for anyone pixel-comparing.How verified
statCard()vs the legacy markup for all three shapes and every change-value path;pctChange()unit cases including the NaN guard.fui-grid-item-6), access-request cards (no change rows), plus the full fix: generalize access-request service classification and stat cards in static analytics template #4922 regression suite (multi-service, single-service, malformed payloads) — zero JS errors./code-reviewat high effort: no correctness bugs; the two cleanup findings it raised are applied in this PR, the label-wrap geometry note is the deliberate delta above.🤖 Generated with Claude Code