Repository Public
1// State → tone mapping. Driven by the generated token semantics so web and Apple clients agree.2import { semantic } from "@tokens/tokens";3import type { Schemas } from "@/api/client";4import type { Tone } from "./cx";5import type { IconName } from "./Icon";67const toTone = (token: string): Tone => {8 const name = token.replace(/^state\./, "");9 return name === "ok" || name === "warning" || name === "critical" || name === "info" || name === "stale" || name === "offline" || name === "maintenance" ? name : "neutral";10};1112export const freshnessTone = (f: Schemas["Freshness"]): Tone => toTone(semantic.freshness[f]);13export const severityTone = (s: Schemas["Severity"]): Tone => toTone(semantic.severity[s]);14export const serviceTone = (s: Schemas["ServiceState"]): Tone => toTone(semantic.service[s]);15export const actionTone = (s: Schemas["ActionState"]): Tone => toTone(semantic.action[s]);1617export const jobTone = (s: Schemas["JobState"]): Tone =>18 s === "succeeded" ? "ok" : s === "failed" || s === "timed_out" ? "critical" : s === "cancelled" ? "offline" : "info";19export const alertTone = (s: Schemas["AlertState"], severity: Schemas["Severity"]): Tone =>20 s === "resolved" ? "ok" : s === "acknowledged" ? "info" : s === "pending" ? "stale" : severityTone(severity);21export const incidentTone = (s: Schemas["IncidentState"]): Tone => (s === "resolved" ? "ok" : s === "mitigated" ? "info" : "critical");22export const maintenanceTone = (s: Schemas["MaintenanceStatus"]): Tone => (s === "in_progress" ? "maintenance" : s === "completed" ? "ok" : s === "cancelled" ? "offline" : "info");23export const criticalityTone = (c: Schemas["Criticality"]): Tone => (c === "critical" ? "critical" : c === "high" ? "warning" : c === "medium" ? "info" : "neutral");24export const healthTone = (h: "ok" | "failing" | "unknown" | "failed" | "degraded" | "down"): Tone =>25 h === "ok" ? "ok" : h === "failing" || h === "failed" || h === "down" ? "critical" : h === "degraded" ? "warning" : "stale";26export const outcomeTone = (o: Schemas["AuditOutcome"]): Tone => (o === "success" ? "ok" : o === "denied" ? "warning" : "critical");2728export const actionIcon = (s: Schemas["ActionState"]): IconName =>29 s === "pending_approval" ? "pending" : s === "queued" || s === "dispatched" ? "clock" : s === "running" ? "running" : s === "succeeded" ? "ok" : s === "failed" || s === "timed_out" ? "critical" : "offline";30export const availabilityIcon = (a: Schemas["Availability"]): IconName =>31 a === "unsupported" ? "unsupported" : a === "permission_denied" ? "denied" : a === "stale" ? "stale" : a === "offline" ? "offline" : "unknown";32