From 61cfcfd984f53643c7ad4cdccdd3ad18297ca44a Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 12 Nov 2026 11:31:36 -0800 Subject: [PATCH] fix(billing): V3-06b Top workspaces adds the W-number to workspaces that share a title --- .../plan-billing-usage-history.test.ts | 17 ++++++++++++++ .../billing/plan-billing-usage-history.ts | 22 +++++++++++++++++++ .../billing/use-plan-billing-usage-history.ts | 13 ++++++----- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/components/billing/plan-billing-usage-history.test.ts b/src/renderer/src/components/billing/plan-billing-usage-history.test.ts index aa74937c60a..838753fb29b 100644 --- a/src/renderer/src/components/billing/plan-billing-usage-history.test.ts +++ b/src/renderer/src/components/billing/plan-billing-usage-history.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest' import { translate } from '@/i18n/i18n' import { USAGE_NAMED_ROWS, + usageWorkspaceNames, topMemberRows, topWorkspaceRows, usageBarPercent, @@ -144,3 +145,19 @@ describe('V3-06: at most five named workspaces, then the buckets', () => { expect(USAGE_NAMED_ROWS).toBe(5) }) }) + +describe('V3-06b: workspaces with the same title', () => { + it('adds the workspace number only to titles that repeat', () => { + const names = usageWorkspaceNames([ + { id: 's1', title: 'orca', number: 512 }, + { id: 's2', title: 'orca', number: 498 }, + { id: 's3', title: 'Hello-World', number: 7 }, + { id: 's4', title: 'orca', number: null } + ]) + expect(names.get('s1')).toBe('orca · W-512') + expect(names.get('s2')).toBe('orca · W-498') + expect(names.get('s3')).toBe('Hello-World') + // No number from an older control plane: the title stays as is. + expect(names.get('s4')).toBe('orca') + }) +}) diff --git a/src/renderer/src/components/billing/plan-billing-usage-history.ts b/src/renderer/src/components/billing/plan-billing-usage-history.ts index bfa29de7b2e..91267b28288 100644 --- a/src/renderer/src/components/billing/plan-billing-usage-history.ts +++ b/src/renderer/src/components/billing/plan-billing-usage-history.ts @@ -3,6 +3,7 @@ import type { Translate } from '@/i18n/use-translate' import type { OrcaBillingUsageHistory, OrcaBillingUsageTop } from '../../../../shared/orca-billing' import { formatHours, formatHoursUsed } from './plan-billing-format' +import { formatWorkspaceNumber } from '../../../../shared/cloud-workspaces/cloud-workspaces-wire' const HOUR = 3600 @@ -50,6 +51,27 @@ export type UsageNames = { /** V3-06: at most this many named rows; billing sends more so deleted ones don't crowd out live ones. */ export const USAGE_NAMED_ROWS = 5 +/** + * V3-06b: workspace names for Top workspaces by sandbox id. Two workspaces with the same title would + * read alike, so duplicates get their number ("orca · W-512"); unique titles stay as they are. + */ +export function usageWorkspaceNames( + workspaces: readonly { id: string; title: string; number?: number | null }[] +): Map { + const counts = new Map() + for (const workspace of workspaces) { + counts.set(workspace.title, (counts.get(workspace.title) ?? 0) + 1) + } + return new Map( + workspaces.map((workspace) => [ + workspace.id, + (counts.get(workspace.title) ?? 0) > 1 && workspace.number + ? `${workspace.title} · ${formatWorkspaceNumber(workspace.number)}` + : workspace.title + ]) + ) +} + function share(seconds: number, total: number): number { return total > 0 ? Math.min(100, (seconds / total) * 100) : 0 } diff --git a/src/renderer/src/components/billing/use-plan-billing-usage-history.ts b/src/renderer/src/components/billing/use-plan-billing-usage-history.ts index 332875f1211..46f6623bd96 100644 --- a/src/renderer/src/components/billing/use-plan-billing-usage-history.ts +++ b/src/renderer/src/components/billing/use-plan-billing-usage-history.ts @@ -4,7 +4,7 @@ import type { CloudWorkspace } from '../../../../shared/cloud-workspaces/cloud-w import { useTranslate } from '@/i18n/use-translate' import { cloudWorkspaceTitle } from '../cloud-workspaces/open-cloud-workspace' import { useOrgRoster } from './team/use-org-roster' -import type { UsageNames } from './plan-billing-usage-history' +import { usageWorkspaceNames, type UsageNames } from './plan-billing-usage-history' export type PlanBillingUsageState = | { status: 'loading' } @@ -131,10 +131,13 @@ export function usePlanBillingUsageHistory( } } } - const titles = new Map() - for (const workspace of workspaces ?? []) { - titles.set(workspace.id, cloudWorkspaceTitle(workspace, t)) - } + const titles = usageWorkspaceNames( + (workspaces ?? []).map((workspace) => ({ + id: workspace.id, + title: cloudWorkspaceTitle(workspace, t), + number: workspace.number + })) + ) return { state: { status: 'ok',