mirror of
https://github.com/stablyai/orca.git
synced 2026-11-15 18:37:24 +00:00
fix(billing): V3-06b Top workspaces adds the W-number to workspaces that share a title
This commit is contained in:
@@ -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')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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<string, string> {
|
||||
const counts = new Map<string, number>()
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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<string, string>()
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user