All checks were successful
Build & Publish / publish (push) Successful in 1m12s
Consolidate formatDuration, statusToVariant, statusLabel, formatTimestamp, toRouteNodeType, and durationClass from 5 page/component files into one shared utils module. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import type { RouteNode } from '../design-system/composites/RouteFlow/RouteFlow'
|
|
|
|
export function formatDuration(ms: number): string {
|
|
if (ms >= 60_000) return `${(ms / 1000).toFixed(0)}s`
|
|
if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`
|
|
return `${ms}ms`
|
|
}
|
|
|
|
export function statusToVariant(status: string): 'success' | 'error' | 'running' | 'warning' {
|
|
switch (status) {
|
|
case 'completed': return 'success'
|
|
case 'failed': return 'error'
|
|
case 'running': return 'running'
|
|
case 'warning': return 'warning'
|
|
default: return 'warning'
|
|
}
|
|
}
|
|
|
|
export function statusLabel(s: string): string {
|
|
switch (s) {
|
|
case 'completed': return 'OK'
|
|
case 'failed': return 'ERR'
|
|
case 'running': return 'RUN'
|
|
case 'warning': return 'WARN'
|
|
default: return s
|
|
}
|
|
}
|
|
|
|
export function formatTimestamp(date: Date): string {
|
|
return date.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
|
}
|
|
|
|
export function toRouteNodeType(procType: string): RouteNode['type'] {
|
|
switch (procType) {
|
|
case 'consumer': return 'from'
|
|
case 'transform': return 'process'
|
|
case 'enrich': return 'process'
|
|
default: return procType as RouteNode['type']
|
|
}
|
|
}
|
|
|
|
interface DurationStyles {
|
|
durBreach: string
|
|
durFast: string
|
|
durNormal: string
|
|
durSlow: string
|
|
}
|
|
|
|
export function durationClass(ms: number, status: string, styles: DurationStyles): string {
|
|
if (status === 'failed') return styles.durBreach
|
|
if (ms < 100) return styles.durFast
|
|
if (ms < 200) return styles.durNormal
|
|
if (ms < 300) return styles.durSlow
|
|
return styles.durBreach
|
|
}
|