Skip to content

Commit 6890bc8

Browse files
committed
feat: add show/hide analysis toggle to Usage page
1 parent 3b1f5f2 commit 6890bc8

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

frontend/src/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,8 @@
765765
"statusErrorDetails": "Error Details",
766766
"statusErrorEmpty": "No detailed error message recorded",
767767
"clearFilters": "Clear Filters",
768+
"showAnalysis": "Show Analysis",
769+
"hideAnalysis": "Hide Analysis",
768770
"modelStatsTitle": "Model Statistics",
769771
"modelStatsDesc": "Aggregated by retained logs for requests, tokens, and amount.",
770772
"noModelStats": "No model statistics yet",

frontend/src/locales/zh.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,8 @@
765765
"statusErrorDetails": "错误详情",
766766
"statusErrorEmpty": "未记录具体错误信息",
767767
"clearFilters": "清除筛选",
768+
"showAnalysis": "显示分析",
769+
"hideAnalysis": "隐藏分析",
768770
"modelStatsTitle": "模型统计",
769771
"modelStatsDesc": "按当前保留日志聚合请求、Token 与金额。",
770772
"noModelStats": "暂无模型统计",

frontend/src/pages/Usage.tsx

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ function getStatusBadgeClassName(statusCode: number): string {
5555

5656
const TIME_RANGE_OPTIONS: TimeRangeKey[] = ['1h', '6h', '24h', '7d', '30d']
5757

58+
const USAGE_ANALYSIS_VISIBILITY_KEY = 'usage_analysis_visible'
59+
60+
function getInitialAnalysisVisibility(): boolean {
61+
try {
62+
return window.localStorage.getItem(USAGE_ANALYSIS_VISIBILITY_KEY) !== 'false'
63+
} catch {
64+
return true
65+
}
66+
}
67+
68+
function persistAnalysisVisibility(visible: boolean) {
69+
try {
70+
window.localStorage.setItem(USAGE_ANALYSIS_VISIBILITY_KEY, visible ? 'true' : 'false')
71+
} catch {}
72+
}
73+
5874
function formatAPIKeyOptionLabel(apiKey: APIKeyRow): string {
5975
return apiKey.name ? `${apiKey.name} · ${apiKey.key}` : apiKey.key
6076
}
@@ -789,6 +805,7 @@ export default function Usage() {
789805
const searchTimer = useRef<ReturnType<typeof setTimeout>>(null)
790806
const [visibleColumns, setVisibleColumns] = useState<Record<UsageTableColumn, boolean>>(getInitialUsageVisibleColumns)
791807
const [columnSettingsOpen, setColumnSettingsOpen] = useState(false)
808+
const [showAnalysis, setShowAnalysis] = useState(getInitialAnalysisVisibility)
792809

793810
// 搜索防抖:输入停止 400ms 后触发查询
794811
const handleSearchChange = useCallback((value: string) => {
@@ -887,6 +904,10 @@ export default function Usage() {
887904
persistUsageVisibleColumns(visibleColumns)
888905
}, [visibleColumns])
889906

907+
useEffect(() => {
908+
persistAnalysisVisibility(showAnalysis)
909+
}, [showAnalysis])
910+
890911
const { stats } = data
891912
const totalPages = Math.max(1, Math.ceil(logsTotal / pageSize))
892913
const currentPage = Math.min(page, totalPages)
@@ -936,6 +957,16 @@ export default function Usage() {
936957
title={t('usage.title')}
937958
description={t('usage.description')}
938959
onRefresh={() => { void reload(); void loadLogs(); void loadAPIKeys() }}
960+
actions={
961+
<Button
962+
variant="outline"
963+
aria-pressed={showAnalysis}
964+
onClick={() => setShowAnalysis((v) => !v)}
965+
>
966+
<BarChart3 className="size-3.5" />
967+
{showAnalysis ? t('usage.hideAnalysis') : t('usage.showAnalysis')}
968+
</Button>
969+
}
939970
/>
940971

941972
<div className="space-y-6">
@@ -1041,15 +1072,19 @@ export default function Usage() {
10411072
</Card>
10421073
</div>
10431074

1044-
<div className="grid grid-cols-[minmax(0,0.5fr)_minmax(360px,0.5fr)] gap-3 max-lg:grid-cols-1">
1045-
<ModelStatsPanel stats={modelStats} />
1046-
<FeatureStatsPanel stats={featureStats} totalRequests={totalRequests} />
1047-
</div>
1075+
{showAnalysis && (
1076+
<>
1077+
<div className="grid grid-cols-[minmax(0,0.5fr)_minmax(360px,0.5fr)] gap-3 max-lg:grid-cols-1">
1078+
<ModelStatsPanel stats={modelStats} />
1079+
<FeatureStatsPanel stats={featureStats} totalRequests={totalRequests} />
1080+
</div>
10481081

1049-
<div className="grid grid-cols-2 gap-3 max-lg:grid-cols-1">
1050-
<EndpointStatsPanel stats={endpointStats} totalRequests={totalRequests} />
1051-
<APIKeyStatsPanel stats={apiKeyStats} totalRequests={totalRequests} />
1052-
</div>
1082+
<div className="grid grid-cols-2 gap-3 max-lg:grid-cols-1">
1083+
<EndpointStatsPanel stats={endpointStats} totalRequests={totalRequests} />
1084+
<APIKeyStatsPanel stats={apiKeyStats} totalRequests={totalRequests} />
1085+
</div>
1086+
</>
1087+
)}
10531088

10541089
{/* Logs table */}
10551090
<Card>

0 commit comments

Comments
 (0)