All files / apps/developer-portal/layers/workflows/app/utils format.ts

100% Statements 19/19
100% Branches 4/4
100% Functions 6/6
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43      6x                       15x     6x 186x   6x           79x     6x   103x   159x   6x 20x 18x   16x    
import type { CapabilityState, Kind, TicketStatus } from "#layers/workflows/shared/workflows.ts";
import type { Tone } from "~/types/Tone";
 
const CAPABILITY_TONES = {
    off: "neutral",
    skipped: "neutral",
    waits: "neutral",
    "can-file": "neutral",
    blocked: "neutral",
    "waiting-on-you": "warn",
    ready: "neutral",
    "in-flight": "warn",
    done: "good",
} as const satisfies Record<CapabilityState, Tone>;
 
export const capabilityStateTone = (state: CapabilityState): Tone => CAPABILITY_TONES[state];
 
/** One `--state-*` token per state in `workflows.css`, shared by blocks and tickets. */
export const stateColor = (state: CapabilityState | TicketStatus): string =>
    `var(--state-${state})`;
 
const BLOCK_ICONS = {
    build: null,
    spike: "i-lucide-flask-conical",
    owner: "i-lucide-user-round",
} as const satisfies Record<Kind, string | null>;
 
export const blockKindIcon = (kind: Kind): string | null => BLOCK_ICONS[kind];
 
/** How many `--stage-*` tokens `workflows.css` defines; a longer template wraps round. */
const STAGE_COLORS = 7;
 
export const stageColor = (index: number): string => `var(--stage-${(index % STAGE_COLORS) + 1})`;
 
export const capabilityColor = (state: CapabilityState): string => stateColor(state);
 
export const progressTone = (percent: number): Tone => {
    if (percent >= 100) return "good";
    if (percent >= 50) return "warn";
 
    return "neutral";
};