Skip to content

Commit 2b71614

Browse files
fix(usage): display cumulative spend on zero event days (#87243)
For reserved budget categories, we always display the usage chart in spend mode. When you switch type to cumulative it'd only show the cumulative spend on days that had spend. This PR fixes that so that on days without spend, we just use the previous day's spend. For periodic usage, behavior remains the same as before (only show spend for that day, in which case days without spend will have 0). # before ![image](https://github.com/user-attachments/assets/65bbdad1-c2c9-46c4-9538-954f8a2452c1) # after ![image](https://github.com/user-attachments/assets/e89494ee-f2fd-4ec8-9087-12c721b849ce)
1 parent bdfa32f commit 2b71614

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

static/gsApp/views/subscriptionPage/reservedUsageChart.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ export function mapReservedBudgetStatsToChart({
361361
return chartData;
362362
}
363363

364+
let previousReservedForDate = 0;
365+
let previousOnDemandForDate = 0;
364366
Object.entries(statsByDateAndCategory).forEach(([date, statsByCategory]) => {
365367
let reservedForDate = 0;
366368
let onDemandForDate = 0;
@@ -408,13 +410,26 @@ export function mapReservedBudgetStatsToChart({
408410
}
409411
});
410412
});
413+
// if cumulative and there was no new spend on this date, use the previous date's spend
414+
if (
415+
reservedForDate === 0 &&
416+
isCumulative &&
417+
moment(date).isSameOrBefore(moment().toDate())
418+
) {
419+
reservedForDate = previousReservedForDate;
420+
}
421+
if (onDemandForDate === 0 && isCumulative) {
422+
onDemandForDate = previousOnDemandForDate;
423+
}
411424
const dateKey = getDateFromMoment(moment(date));
412425
chartData.reserved!.push({
413426
value: [dateKey, reservedForDate],
414427
});
428+
previousReservedForDate = reservedForDate;
415429
chartData.onDemand!.push({
416430
value: [dateKey, onDemandForDate],
417431
});
432+
previousOnDemandForDate = onDemandForDate;
418433
});
419434

420435
return chartData;

0 commit comments

Comments
 (0)