Skip to content

Commit 2119ffb

Browse files
committed
fix(web): usage hourly breakdown lists every hour chronologically
1 parent a354dd9 commit 2119ffb

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

‎apps/web/src/components/usage/UsagePage.tsx‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ export function UsagePage() {
6868
: enumerateHourStarts(window.sinceTime, window.untilTime),
6969
[window.sinceTime, window.untilTime],
7070
);
71-
// Newest first: the window can run 90 periods, so the interesting end
72-
// belongs at the top of the table.
73-
const breakdownPeriods = useMemo<readonly (DailyTotals | HourlyTotals)[]>(
74-
() => (isPast24Hours ? merged.hourly : merged.daily).toReversed(),
75-
[isPast24Hours, merged.daily, merged.hourly],
76-
);
71+
// The hourly window is small enough to render every period: the table then
72+
// reads chronologically like the chart, instead of jumping between the hours
73+
// that happened to have activity. Daily windows can run 90 periods, so those
74+
// stay newest-first with the interesting end on top.
75+
const breakdownPeriods = useMemo<readonly (DailyTotals | HourlyTotals)[]>(() => {
76+
if (!isPast24Hours) return merged.daily.toReversed();
77+
const byHour = new Map(merged.hourly.map((entry) => [entry.hourStart, entry]));
78+
return hours.map((hourStart) => byHour.get(hourStart) ?? zeroHour(hourStart));
79+
}, [isPast24Hours, merged.daily, merged.hourly, hours]);
7780

7881
const selectWindow = (days: number) => {
7982
setWindowSelection({
@@ -435,6 +438,17 @@ export function UsagePage() {
435438
);
436439
}
437440

441+
/** A zero-filled hourly period so the breakdown lists every hour in the window. */
442+
function zeroHour(hourStart: string): HourlyTotals {
443+
return {
444+
day: "",
445+
hourStart,
446+
costUsd: 0,
447+
totalTokens: 0,
448+
byProvider: new Map<UsageProviderKind, { costUsd: number; totalTokens: number }>(),
449+
};
450+
}
451+
438452
/** Brand mark for the harness a row belongs to. */
439453
function ProviderMark({
440454
provider,

0 commit comments

Comments
 (0)