|
| 1 | +/** |
| 2 | + * Shared badge/status class utilities for the devtools dashboard. |
| 3 | + * These are bundled and served as globals for stx template expressions. |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * Badge classes for job statuses (active = indigo). |
| 8 | + * Used by: jobs, index, batch-details, batches, group-details, groups |
| 9 | + */ |
| 10 | +export function badgeClass(status: string): string { |
| 11 | + const map: Record<string, string> = { |
| 12 | + completed: 'bg-emerald-500/15 text-emerald-500', |
| 13 | + finished: 'bg-emerald-500/15 text-emerald-500', |
| 14 | + failed: 'bg-red-500/15 text-red-500', |
| 15 | + processing: 'bg-indigo-500/15 text-indigo-400', |
| 16 | + active: 'bg-indigo-500/15 text-indigo-400', |
| 17 | + waiting: 'bg-amber-500/15 text-amber-500', |
| 18 | + pending: 'bg-amber-500/15 text-amber-500', |
| 19 | + delayed: 'bg-zinc-500/15 text-zinc-500', |
| 20 | + } |
| 21 | + return map[status] || 'bg-zinc-500/15 text-zinc-500' |
| 22 | +} |
| 23 | + |
| 24 | +/** |
| 25 | + * Badge classes for queue health statuses (active = emerald). |
| 26 | + * Used by: queues, queue-details |
| 27 | + */ |
| 28 | +export function queueBadgeClass(status: string): string { |
| 29 | + const map: Record<string, string> = { |
| 30 | + active: 'bg-emerald-500/15 text-emerald-500', |
| 31 | + paused: 'bg-amber-500/15 text-amber-500', |
| 32 | + stopped: 'bg-red-500/15 text-red-500', |
| 33 | + completed: 'bg-emerald-500/15 text-emerald-500', |
| 34 | + failed: 'bg-red-500/15 text-red-500', |
| 35 | + waiting: 'bg-amber-500/15 text-amber-500', |
| 36 | + pending: 'bg-amber-500/15 text-amber-500', |
| 37 | + } |
| 38 | + return map[status] || 'bg-zinc-500/15 text-zinc-500' |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * Progress bar color based on batch/queue status. |
| 43 | + * Used by: batches |
| 44 | + */ |
| 45 | +export function progressBarColorClass(status: string): string { |
| 46 | + const map: Record<string, string> = { |
| 47 | + completed: 'bg-emerald-500', |
| 48 | + finished: 'bg-emerald-500', |
| 49 | + failed: 'bg-red-500', |
| 50 | + processing: 'bg-indigo-500', |
| 51 | + active: 'bg-indigo-500', |
| 52 | + pending: 'bg-amber-500', |
| 53 | + waiting: 'bg-amber-500', |
| 54 | + } |
| 55 | + return map[status] || 'bg-indigo-500' |
| 56 | +} |
| 57 | + |
| 58 | +/** |
| 59 | + * Dot color for monitoring event types. |
| 60 | + * Used by: monitoring |
| 61 | + */ |
| 62 | +export function dotColor(dot: string): string { |
| 63 | + const map: Record<string, string> = { |
| 64 | + completed: 'bg-emerald-500', |
| 65 | + started: 'bg-indigo-500', |
| 66 | + failed: 'bg-red-500', |
| 67 | + queued: 'bg-amber-500', |
| 68 | + } |
| 69 | + return map[dot] || 'bg-zinc-500' |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * Health indicator color based on error rate. |
| 74 | + * Used by: monitoring |
| 75 | + */ |
| 76 | +export function healthColor(errorRateValue: number): string { |
| 77 | + if (errorRateValue > 5) return 'bg-red-500' |
| 78 | + if (errorRateValue > 1) return 'bg-amber-500' |
| 79 | + return 'bg-emerald-500' |
| 80 | +} |
| 81 | + |
| 82 | +/** |
| 83 | + * Queue status display label. |
| 84 | + * Used by: queues |
| 85 | + */ |
| 86 | +export function statusLabel(status: string): string { |
| 87 | + const map: Record<string, string> = { |
| 88 | + active: 'Active', |
| 89 | + paused: 'Paused', |
| 90 | + stopped: 'Stopped', |
| 91 | + } |
| 92 | + return map[status] || status |
| 93 | +} |
0 commit comments