Repository navigation
fix(home/kpi): unwrap recommendations envelope so Potential Monthly Savings reflects real total - #755
Conversation
Home showed $0 while Opportunities showed $212-$314 for the same
recommendation dataset. Root cause: the backend always returns the
envelope { recommendations: [...], summary: {...}, regions: [...] }
but loadDashboard() only checked Array.isArray(rawRecs), which is
false for an object, so recs was silently coerced to [] and the
pageLevelRange computation produced $0. The Opportunities page worked
because it cast the result to RecommendationsResponse and read
.recommendations directly. The Home KPI now unwraps .recommendations
from the envelope (with a flat-array fallback so test fixtures still
work), matching the Opportunities aggregator.
Closes #749.
|
Warning Review limit reached
More reviews will be available in 36 minutes and 48 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
QA exploratory testing found the Home page "Potential Monthly Savings" KPI showing $0 while the Opportunities page showed $212 - $314 for the same dataset (All Providers / All Accounts, 23 recommendations).
Root cause
/api/recommendationsalways returns an envelope:{ "recommendations": [...], "summary": {...}, "regions": [...] }The Opportunities page correctly read
.recommendations. The Home dashboard'sloadDashboard()instead guarded withArray.isArray(rawRecs), which isfalsefor an object, silently coercingrecsto[]. With an empty array,groupRecsByCellreturns an empty map,pageLevelRangereportscellCount: 0, and the savings display falls back toformatCurrency(0)=$0-- even though 23 recommendations with real savings were available.Fix
loadDashboard()now unwraps.recommendationsfrom the envelope when the result is a non-array object, accepting either shape (envelope or flat array) so existing test mocks remain valid.Files changed
frontend/src/dashboard.tsfrontend/src/__tests__/dashboard.test.tsTest plan
#749asserts the envelope shape produces a populated savings card, not$0.Closes #749.