fix(desktop): handle empty usage analytics totals

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Austin Pickett 2026-05-13 10:46:03 -04:00
parent bf196bb47b
commit 6f2e616d9f
2 changed files with 16 additions and 9 deletions

View file

@ -1098,6 +1098,10 @@ function formatCost(value: null | number | undefined): string {
return `$${num.toFixed(2)}`
}
function formatInteger(value: null | number | undefined): string {
return Number(value ?? 0).toLocaleString()
}
interface UsagePanelProps {
error: string
loading: boolean
@ -1152,9 +1156,12 @@ function UsagePanel({ error, loading, onPeriodChange, onRefresh, period, usage }
<OverlayCard className="p-3">
{totals ? (
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
<UsageStat label="Sessions" value={totals.total_sessions.toLocaleString()} />
<UsageStat label="API calls" value={totals.total_api_calls.toLocaleString()} />
<UsageStat label="Tokens in/out" value={`${formatTokens(totals.total_input)} / ${formatTokens(totals.total_output)}`} />
<UsageStat label="Sessions" value={formatInteger(totals.total_sessions)} />
<UsageStat label="API calls" value={formatInteger(totals.total_api_calls)} />
<UsageStat
label="Tokens in/out"
value={`${formatTokens(totals.total_input)} / ${formatTokens(totals.total_output)}`}
/>
<UsageStat
hint={totals.total_actual_cost > 0 ? `actual ${formatCost(totals.total_actual_cost)}` : undefined}
label="Est. cost"
@ -1204,7 +1211,7 @@ function UsagePanel({ error, loading, onPeriodChange, onRefresh, period, usage }
>
<div
className="w-full bg-[color:var(--dt-primary)]/50"
style={{ height: Math.max(inputH, total > 0 ? 1 : 0) }}
style={{ height: Math.max(inputH, entry.input_tokens > 0 ? 1 : 0) }}
/>
<div
className="w-full bg-emerald-500/60"

View file

@ -345,12 +345,12 @@ export interface AnalyticsSkillsSummary {
export interface AnalyticsTotals {
total_actual_cost: number
total_api_calls: number
total_cache_read: number
total_api_calls: null | number
total_cache_read: null | number
total_estimated_cost: number
total_input: number
total_output: number
total_reasoning: number
total_input: null | number
total_output: null | number
total_reasoning: null | number
total_sessions: number
}