fix: add shared number formatting utilities (formatMetric, formatCount, formatPercent)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-09 18:43:52 +02:00
parent 605c8ad270
commit 7ec56f3bd0
2 changed files with 19 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ import { useMemo } from 'react';
import { useGlobalFilters } from '@cameleer/design-system';
import { useExecutionStats } from '../api/queries/executions';
import type { Scope } from '../hooks/useScope';
import { formatPercent } from '../utils/format-utils';
import styles from './TabKpis.module.css';
interface TabKpisProps {
@@ -20,10 +21,6 @@ function formatMs(ms: number): string {
return `${Math.round(ms)}ms`;
}
function formatPct(pct: number): string {
return `${pct.toFixed(1)}%`;
}
type Trend = 'up' | 'down' | 'flat';
function trend(current: number, previous: number): Trend {
@@ -74,7 +71,7 @@ export function TabKpis({ scope }: TabKpisProps) {
return [
{ label: 'Total', value: formatNum(total), trend: trend(total, prevTotal) },
{ label: 'Err%', value: formatPct(errorRate), trend: trend(errorRate, prevErrorRate), upIsBad: true },
{ label: 'Err%', value: formatPercent(errorRate), trend: trend(errorRate, prevErrorRate), upIsBad: true },
{ label: 'Avg', value: formatMs(avgMs), trend: trend(avgMs, prevAvgMs), upIsBad: true },
{ label: 'P99', value: formatMs(p99), trend: trend(p99, prevP99), upIsBad: true },
];