feat(frontend/dashboard): Potential Monthly Savings card mirrors Recommendations-page range (closes #293)#295
Conversation
…mmendations-page range (closes #293) Dashboard's "Potential Monthly Savings" card previously read summary.potential_monthly_savings — a flat sum across every variant of every cell that overstates achievable savings by ~6x (the same bug class #272 closed on the Recommendations page). Frontend-only fix: loadDashboard now fetches /api/recommendations concurrently alongside /api/dashboard/summary and /api/upcoming via Promise.allSettled (failure of any individual fetch is isolated — the dashboard still renders with graceful fallbacks). The per-cell range is computed client-side via the existing groupRecsByCell / pageLevelRange / formatSavingsRange helpers already used by the Recommendations page. formatSavingsRange is newly exported from recommendations.ts to enable reuse. If getRecommendations fails, the savings card falls back to $0 and the other three cards (Active Commitments, Current Coverage, YTD Savings) render normally from the summary response. The backend change to /dashboard/summary is deferred; a future PR can move the range computation server-side if needed.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe dashboard now fetches recommendations and computes "Potential Monthly Savings" from per-cell recommendation ranges instead of using the static API summary value, with error isolation via ChangesDashboard Savings Range Computation
Sequence DiagramsequenceDiagram
participant Dashboard as Dashboard Component
participant API as API Layer
participant RecHelpers as Recommendation Helpers
participant UI as Rendered UI
Dashboard->>API: Promise.allSettled([summary, upcoming, recommendations])
API-->>Dashboard: { summary, recommendations }
alt Recommendations Fetch Success
Dashboard->>RecHelpers: groupRecsByCell(recs)
RecHelpers-->>Dashboard: grouped cells
Dashboard->>RecHelpers: pageLevelRange(grouped)
RecHelpers-->>Dashboard: {min, max}
Dashboard->>RecHelpers: formatSavingsRange(min, max)
RecHelpers-->>Dashboard: "$X–$Y"
Dashboard->>UI: render with computed range
else Recommendations Fetch Failure
Dashboard->>UI: render savings card with $0 fallback
end
Dashboard->>UI: render other cards from summary (isolated)
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related Issues
Possibly Related PRs
Suggested Labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
summary.potential_monthly_savings— a flat sum across every variant of every cell that overstates achievable savings by ~6x (same bug class as ux(frontend/recs): Potential Monthly Savings card sums all variants — should mirror Recommended range #272 on the Recommendations page)loadDashboardnow fetches/api/recommendationsconcurrently alongside the existing summary + upcoming calls, computes the per-cell range client-side usinggroupRecsByCell/pageLevelRange/formatSavingsRange(same helpers the Recommendations page uses), and renderssavingsMin – savingsMaxon the cardformatSavingsRangeis exported fromrecommendations.tsto enable reuseBehaviour change
Before:
$Xwhere X is the sum of every variant of every cell (overcounted)After:
$min – $max(or$Xif min == max) — matches the Recommendations-page cardImplementation notes
/api/dashboard/summaryis left unchanged. A future backend PR can move range computation server-sidePromise.allSettled: if/api/recommendationsfails, the savings card falls back to$0; Active Commitments, Current Coverage, YTD Savings still render from the summary responseTest plan
npm run typecheck— cleannpm test -- --testPathPattern=dashboard— 21/21 pass (+3 new tests)Potential Monthly Savings card renders per-cell range (#293)— asserts range shown, flat sum NOT shownfailure-isolation: rec fetch failure leaves other cards rendered (#293)— asserts other cards intact, savings falls back to $0legacy summary.potential_monthly_savings is no longer read for the savings card (#293)— asserts $700 summary value not shown when recs give $300-$400Summary by CodeRabbit
New Features
Tests