mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
refactor(i18n): render the usage charts in their test and read useTranslate there (#39737)
The usage chart test called both charts as plain functions, which kept them on translate() and getIntlLocale(). Render them instead and convert the charts. The pull request page's back label moves from a parameter default into the render. Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -226,7 +226,6 @@
|
||||
2 src/renderer/src/components/provider-accounts/AntigravityProviderSignInArea.tsx
|
||||
2 src/renderer/src/components/provider-accounts/ProviderHostScopeControl.tsx
|
||||
1 src/renderer/src/components/provider-accounts/UnsealedCredentialNotice.tsx
|
||||
1 src/renderer/src/components/pull-request-page/page/surface.tsx
|
||||
5 src/renderer/src/components/quick-open-install-rg-guidance.tsx
|
||||
9 src/renderer/src/components/repo/CreateFromPicker.tsx
|
||||
5 src/renderer/src/components/repo/NestedRepoChecklist.tsx
|
||||
@@ -249,8 +248,6 @@
|
||||
2 src/renderer/src/components/sparse/SparseSelectedDirectoryList.tsx
|
||||
15 src/renderer/src/components/ssh-authentication/SshPassphraseDialog.tsx
|
||||
10 src/renderer/src/components/star-nag/StarNagToastHost.tsx
|
||||
12 src/renderer/src/components/stats/ClaudeUsageDailyChart.tsx
|
||||
12 src/renderer/src/components/stats/CodexUsageDailyChart.tsx
|
||||
1 src/renderer/src/components/tab-group/TabGroupDropOverlay.tsx
|
||||
3 src/renderer/src/components/tab-group/TabGroupPaneActionsMenu.tsx
|
||||
1 src/renderer/src/components/tab-group/TabGroupPanel.tsx
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
resolveGitHubLinkCopyState
|
||||
} from '@/components/github-link-copy-state'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import type { GitHubWorkItem } from '../../../../../shared/github/work-item-types'
|
||||
import type { PullRequestPageProps } from '../page-types'
|
||||
import { GitHubWorkItemTargetContext } from '@/components/github-item-dialog/load-item-details/github-work-item-target-context'
|
||||
@@ -47,12 +48,15 @@ function PullRequestPageItem({
|
||||
repoId,
|
||||
sourceContext,
|
||||
initialTab,
|
||||
backLabel = translate('auto.components.TaskPage.backToPullRequests', 'Pull requests'),
|
||||
backLabel: backLabelOverride,
|
||||
projectOrigin,
|
||||
onUse,
|
||||
onReviewRequestsChange,
|
||||
onClose
|
||||
}: PullRequestPageProps): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const backLabel =
|
||||
backLabelOverride ?? t('auto.components.TaskPage.backToPullRequests', 'Pull requests')
|
||||
const workItemId = workItem?.id
|
||||
const [localState, setLocalState] = useState<GitHubWorkItem['state']>(workItem?.state ?? 'open')
|
||||
const [localLabels, setLocalLabels] = useState<string[]>(workItem?.labels ?? [])
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip'
|
||||
import type { ClaudeUsageDailyPoint } from '../../../../shared/claude-usage-types'
|
||||
import { getIntlLocale, translate } from '@/i18n/i18n'
|
||||
import { getIntlLocale } from '@/i18n/i18n'
|
||||
import { useIntlLocale, useTranslate } from '@/i18n/use-translate'
|
||||
|
||||
function formatTokens(value: number, intlLocale: string = getIntlLocale()): string {
|
||||
if (value >= 1_000_000) {
|
||||
@@ -30,16 +31,18 @@ type ClaudeUsageDailyChartProps = {
|
||||
}
|
||||
|
||||
export function ClaudeUsageDailyChart({ daily }: ClaudeUsageDailyChartProps): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const intlLocale = useIntlLocale()
|
||||
const maxDailyTotal = getMaxDailyTotal(daily)
|
||||
|
||||
return (
|
||||
<section className="rounded-lg border border-border/60 bg-card/40 p-4">
|
||||
<div className="mb-3">
|
||||
<h4 className="text-sm font-semibold text-foreground">
|
||||
{translate('auto.components.stats.ClaudeUsageDailyChart.c9f7cd30e9', 'Daily usage')}
|
||||
{t('auto.components.stats.ClaudeUsageDailyChart.c9f7cd30e9', 'Daily usage')}
|
||||
</h4>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{translate(
|
||||
{t(
|
||||
'auto.components.stats.ClaudeUsageDailyChart.059945f71d',
|
||||
'Input, output, cache read, and cache write totals by day.'
|
||||
)}
|
||||
@@ -51,31 +54,25 @@ export function ClaudeUsageDailyChart({ daily }: ClaudeUsageDailyChartProps): Re
|
||||
const segments = [
|
||||
{
|
||||
key: 'cache-write',
|
||||
label: translate(
|
||||
'auto.components.stats.ClaudeUsageDailyChart.2a6360c7cb',
|
||||
'Cache write'
|
||||
),
|
||||
label: t('auto.components.stats.ClaudeUsageDailyChart.2a6360c7cb', 'Cache write'),
|
||||
value: entry.cacheWriteTokens,
|
||||
className: 'bg-fuchsia-500/70'
|
||||
},
|
||||
{
|
||||
key: 'cache-read',
|
||||
label: translate(
|
||||
'auto.components.stats.ClaudeUsageDailyChart.61c58f8976',
|
||||
'Cache read'
|
||||
),
|
||||
label: t('auto.components.stats.ClaudeUsageDailyChart.61c58f8976', 'Cache read'),
|
||||
value: entry.cacheReadTokens,
|
||||
className: 'bg-amber-500/70'
|
||||
},
|
||||
{
|
||||
key: 'output',
|
||||
label: translate('auto.components.stats.ClaudeUsageDailyChart.7d2efeff5e', 'Output'),
|
||||
label: t('auto.components.stats.ClaudeUsageDailyChart.7d2efeff5e', 'Output'),
|
||||
value: entry.outputTokens,
|
||||
className: 'bg-emerald-500/80'
|
||||
},
|
||||
{
|
||||
key: 'input',
|
||||
label: translate('auto.components.stats.ClaudeUsageDailyChart.d7fb787e6b', 'Input'),
|
||||
label: t('auto.components.stats.ClaudeUsageDailyChart.d7fb787e6b', 'Input'),
|
||||
value: entry.inputTokens,
|
||||
className: 'bg-sky-500/80'
|
||||
}
|
||||
@@ -83,7 +80,7 @@ export function ClaudeUsageDailyChart({ daily }: ClaudeUsageDailyChartProps): Re
|
||||
return (
|
||||
<div key={entry.day} className="flex h-full min-w-0 flex-col justify-end gap-2">
|
||||
<span className="text-center text-[11px] text-muted-foreground">
|
||||
{formatTokens(total)}
|
||||
{formatTokens(total, intlLocale)}
|
||||
</span>
|
||||
<div className="flex min-h-0 flex-1 items-end justify-center">
|
||||
<div className="flex h-full w-full max-w-12 overflow-hidden rounded-t-sm bg-muted/60">
|
||||
@@ -102,8 +99,8 @@ export function ClaudeUsageDailyChart({ daily }: ClaudeUsageDailyChartProps): Re
|
||||
<div className="text-xs">
|
||||
<div>{entry.day}</div>
|
||||
<div>
|
||||
{segment.label}: {segment.value.toLocaleString(getIntlLocale())}{' '}
|
||||
{translate(
|
||||
{segment.label}: {segment.value.toLocaleString(intlLocale)}{' '}
|
||||
{t(
|
||||
'auto.components.stats.ClaudeUsageDailyChart.a7902d3c1d',
|
||||
'tokens'
|
||||
)}
|
||||
@@ -127,19 +124,19 @@ export function ClaudeUsageDailyChart({ daily }: ClaudeUsageDailyChartProps): Re
|
||||
<div className="mt-3 flex flex-wrap gap-4 text-xs text-muted-foreground">
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="size-2 rounded-full bg-sky-500/80" />
|
||||
{translate('auto.components.stats.ClaudeUsageDailyChart.d7fb787e6b', 'Input')}
|
||||
{t('auto.components.stats.ClaudeUsageDailyChart.d7fb787e6b', 'Input')}
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="size-2 rounded-full bg-emerald-500/80" />
|
||||
{translate('auto.components.stats.ClaudeUsageDailyChart.7d2efeff5e', 'Output')}
|
||||
{t('auto.components.stats.ClaudeUsageDailyChart.7d2efeff5e', 'Output')}
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="size-2 rounded-full bg-amber-500/70" />
|
||||
{translate('auto.components.stats.ClaudeUsageDailyChart.61c58f8976', 'Cache read')}
|
||||
{t('auto.components.stats.ClaudeUsageDailyChart.61c58f8976', 'Cache read')}
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="size-2 rounded-full bg-fuchsia-500/70" />
|
||||
{translate('auto.components.stats.ClaudeUsageDailyChart.2a6360c7cb', 'Cache write')}
|
||||
{t('auto.components.stats.ClaudeUsageDailyChart.2a6360c7cb', 'Cache write')}
|
||||
</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip'
|
||||
import type { CodexUsageDailyPoint } from '../../../../shared/codex-usage-types'
|
||||
import { getIntlLocale, translate } from '@/i18n/i18n'
|
||||
import { getIntlLocale } from '@/i18n/i18n'
|
||||
import { useIntlLocale, useTranslate } from '@/i18n/use-translate'
|
||||
|
||||
function formatTokens(value: number, intlLocale: string = getIntlLocale()): string {
|
||||
if (value >= 1_000_000) {
|
||||
@@ -26,16 +27,18 @@ type CodexUsageDailyChartProps = {
|
||||
}
|
||||
|
||||
export function CodexUsageDailyChart({ daily }: CodexUsageDailyChartProps): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const intlLocale = useIntlLocale()
|
||||
const maxDailyTotal = getMaxDailyTotal(daily)
|
||||
|
||||
return (
|
||||
<section className="rounded-lg border border-border/60 bg-card/40 p-4">
|
||||
<div className="mb-3">
|
||||
<h4 className="text-sm font-semibold text-foreground">
|
||||
{translate('auto.components.stats.CodexUsageDailyChart.609aa96e8b', 'Daily usage')}
|
||||
{t('auto.components.stats.CodexUsageDailyChart.609aa96e8b', 'Daily usage')}
|
||||
</h4>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{translate(
|
||||
{t(
|
||||
'auto.components.stats.CodexUsageDailyChart.c756cda6a8',
|
||||
'Input, cached input, output, and reasoning totals by day.'
|
||||
)}
|
||||
@@ -46,31 +49,25 @@ export function CodexUsageDailyChart({ daily }: CodexUsageDailyChartProps): Reac
|
||||
const segments = [
|
||||
{
|
||||
key: 'input',
|
||||
label: translate('auto.components.stats.CodexUsageDailyChart.99a91d3143', 'Input'),
|
||||
label: t('auto.components.stats.CodexUsageDailyChart.99a91d3143', 'Input'),
|
||||
value: Math.max(0, entry.inputTokens - entry.cachedInputTokens),
|
||||
className: 'bg-sky-500/80'
|
||||
},
|
||||
{
|
||||
key: 'output',
|
||||
label: translate('auto.components.stats.CodexUsageDailyChart.7b596a88b2', 'Output'),
|
||||
label: t('auto.components.stats.CodexUsageDailyChart.7b596a88b2', 'Output'),
|
||||
value: entry.outputTokens,
|
||||
className: 'bg-emerald-500/80'
|
||||
},
|
||||
{
|
||||
key: 'cached-input',
|
||||
label: translate(
|
||||
'auto.components.stats.CodexUsageDailyChart.c646e1783c',
|
||||
'Cached input'
|
||||
),
|
||||
label: t('auto.components.stats.CodexUsageDailyChart.c646e1783c', 'Cached input'),
|
||||
value: entry.cachedInputTokens,
|
||||
className: 'bg-amber-500/70'
|
||||
},
|
||||
{
|
||||
key: 'reasoning',
|
||||
label: translate(
|
||||
'auto.components.stats.CodexUsageDailyChart.1e6f62d7e3',
|
||||
'Reasoning'
|
||||
),
|
||||
label: t('auto.components.stats.CodexUsageDailyChart.1e6f62d7e3', 'Reasoning'),
|
||||
value: entry.reasoningOutputTokens,
|
||||
className: 'bg-fuchsia-500/70'
|
||||
}
|
||||
@@ -78,7 +75,7 @@ export function CodexUsageDailyChart({ daily }: CodexUsageDailyChartProps): Reac
|
||||
return (
|
||||
<div key={entry.day} className="flex h-full min-w-0 flex-col justify-end gap-2">
|
||||
<span className="text-center text-[11px] text-muted-foreground">
|
||||
{formatTokens(entry.totalTokens)}
|
||||
{formatTokens(entry.totalTokens, intlLocale)}
|
||||
</span>
|
||||
<div className="flex min-h-0 flex-1 items-end justify-center">
|
||||
<div className="flex h-full w-full max-w-12 overflow-hidden rounded-t-sm bg-muted/60">
|
||||
@@ -97,8 +94,8 @@ export function CodexUsageDailyChart({ daily }: CodexUsageDailyChartProps): Reac
|
||||
<div className="text-xs">
|
||||
<div>{entry.day}</div>
|
||||
<div>
|
||||
{segment.label}: {segment.value.toLocaleString(getIntlLocale())}{' '}
|
||||
{translate(
|
||||
{segment.label}: {segment.value.toLocaleString(intlLocale)}{' '}
|
||||
{t(
|
||||
'auto.components.stats.CodexUsageDailyChart.e4bdcf0071',
|
||||
'tokens'
|
||||
)}
|
||||
@@ -122,19 +119,19 @@ export function CodexUsageDailyChart({ daily }: CodexUsageDailyChartProps): Reac
|
||||
<div className="mt-3 flex flex-wrap gap-4 text-xs text-muted-foreground">
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="size-2 rounded-full bg-sky-500/80" />
|
||||
{translate('auto.components.stats.CodexUsageDailyChart.99a91d3143', 'Input')}
|
||||
{t('auto.components.stats.CodexUsageDailyChart.99a91d3143', 'Input')}
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="size-2 rounded-full bg-emerald-500/80" />
|
||||
{translate('auto.components.stats.CodexUsageDailyChart.7b596a88b2', 'Output')}
|
||||
{t('auto.components.stats.CodexUsageDailyChart.7b596a88b2', 'Output')}
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="size-2 rounded-full bg-amber-500/70" />
|
||||
{translate('auto.components.stats.CodexUsageDailyChart.c646e1783c', 'Cached input')}
|
||||
{t('auto.components.stats.CodexUsageDailyChart.c646e1783c', 'Cached input')}
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="size-2 rounded-full bg-fuchsia-500/70" />
|
||||
{translate('auto.components.stats.CodexUsageDailyChart.1e6f62d7e3', 'Reasoning')}
|
||||
{t('auto.components.stats.CodexUsageDailyChart.1e6f62d7e3', 'Reasoning')}
|
||||
</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, render } from '@testing-library/react'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import type { ClaudeUsageDailyPoint } from '../../../../shared/claude-usage-types'
|
||||
import type { CodexUsageDailyPoint } from '../../../../shared/codex-usage-types'
|
||||
import { ClaudeUsageDailyChart } from './ClaudeUsageDailyChart'
|
||||
@@ -8,6 +10,8 @@ function makeDay(index: number): string {
|
||||
return new Date(Date.UTC(2026, 0, 1 + index)).toISOString().slice(0, 10)
|
||||
}
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
describe('usage daily charts', () => {
|
||||
it('renders Codex/OpenCode daily charts for very large histories', () => {
|
||||
const daily: CodexUsageDailyPoint[] = Array.from({ length: 130_000 }, (_, index) => ({
|
||||
@@ -19,7 +23,7 @@ describe('usage daily charts', () => {
|
||||
totalTokens: index + 1
|
||||
}))
|
||||
|
||||
expect(() => CodexUsageDailyChart({ daily })).not.toThrow()
|
||||
expect(() => render(<CodexUsageDailyChart daily={daily} />)).not.toThrow()
|
||||
})
|
||||
|
||||
it('renders Claude daily charts for very large histories', () => {
|
||||
@@ -31,6 +35,6 @@ describe('usage daily charts', () => {
|
||||
cacheWriteTokens: 0
|
||||
}))
|
||||
|
||||
expect(() => ClaudeUsageDailyChart({ daily })).not.toThrow()
|
||||
expect(() => render(<ClaudeUsageDailyChart daily={daily} />)).not.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user