lib/format.ts gains shortTime(value, zone) and becomes the home of the single duration() formatter (moved from timeline-event.ts, which re-exports it so the stage rail and duration.test.ts are unchanged). LogTable's time column, audit's From/To chips and chat session titles now format in the zone chosen under Appearance instead of the browser's. StepNode, schedule runDuration, labels formatMs and ChatToolCall all delegate to duration(), removing the "12ms" vs "12 ms" vs "under 1 s" split.
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
/** Naming and numbers shared by the workflow tables. */
|
||
|
||
import { duration } from "../lib/format.ts";
|
||
|
||
const WORKFLOW_LABELS: Record<string, string> = {
|
||
implement: "Implement",
|
||
tdd: "TDD",
|
||
feasibility: "Feasibility check",
|
||
};
|
||
|
||
/** A workflow's display name. An unknown one is still shown, not hidden: a new
|
||
* workflow on the server should be visible before the UI knows its proper
|
||
* name. */
|
||
export function workflowLabel(name: string | undefined | null): string {
|
||
if (name && WORKFLOW_LABELS[name]) return WORKFLOW_LABELS[name];
|
||
if (!name) return "Unknown";
|
||
return name.charAt(0).toUpperCase() + name.slice(1).replace(/_/g, " ");
|
||
}
|
||
|
||
/** A percentage, or 0 when there is no whole to divide by. Accepts the absent
|
||
* case because the stats endpoint omits a field it has no data for. */
|
||
export function pct(
|
||
part: number | undefined | null,
|
||
whole: number | undefined | null,
|
||
): number {
|
||
if (!whole || !part) return 0;
|
||
return Math.round((part / whole) * 100);
|
||
}
|
||
|
||
export function formatMs(ms: number | undefined | null): string {
|
||
if (!ms) return "–";
|
||
return duration(ms);
|
||
}
|