Simplify provisioning queue and add shared filters
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import type { ProvisioningListRow } from '../provisioning-list.js';
|
||||
import { statusPresentation, type StatusTone } from './status.js';
|
||||
|
||||
export function provisioningQueueStatus(row: Pick<ProvisioningListRow, 'state' | 'action' | 'stage' | 'waitCode' | 'phase'>): {
|
||||
label: string; tone: StatusTone; group: 'queued' | 'waiting' | 'verifying' | 'running' | 'complete' | 'attention' | 'cancelled';
|
||||
} {
|
||||
if (['failed', 'interrupted', 'warning'].includes(row.state)) return { ...statusPresentation(row.state), group: 'attention' };
|
||||
if (row.state === 'done') return { label: 'Complete', tone: 'online', group: 'complete' };
|
||||
if (row.state === 'cancelled') return { label: 'Cancelled', tone: 'neutral', group: 'cancelled' };
|
||||
if (row.state === 'awaiting-health') return { label: 'Verifying health', tone: 'info', group: 'verifying' };
|
||||
if (row.phase === 'cleanup') return { label: 'Cleaning up', tone: 'info', group: 'running' };
|
||||
const waits: Record<string, string> = {
|
||||
'startup-capacity': 'Waiting for capacity', 'restart-capacity': row.action === 'restart' ? 'Queued for restart' : 'Waiting for recovery capacity',
|
||||
'operation-conflict': 'Waiting for another operation', 'previous-recovery': 'Waiting for recovery'
|
||||
};
|
||||
if (row.waitCode && waits[row.waitCode]) return { label: waits[row.waitCode], tone: 'neutral', group: row.waitCode.endsWith('capacity') ? 'queued' : 'waiting' };
|
||||
if (['queued', 'waiting'].includes(row.state) || row.waitCode) {
|
||||
// Older records may have only a stage message; never infer a failure from it.
|
||||
if (/waiting for another server to recover/i.test(row.stage)) return { label: 'Queued for restart', tone: 'neutral', group: 'queued' };
|
||||
if (/waiting.*(?:empty|players)|players.*remaining|waiting for \d+ player.*to leave/i.test(row.stage)) return { label: 'Waiting for empty lobby', tone: 'neutral', group: 'waiting' };
|
||||
if (/waiting for .*player count/i.test(row.stage)) return { label: 'Checking lobby occupancy', tone: 'neutral', group: 'waiting' };
|
||||
if (/capacity/i.test(row.stage)) return { label: 'Waiting for capacity', tone: 'neutral', group: 'queued' };
|
||||
return { label: row.state === 'queued' ? 'Queued' : row.waitCode === 'eligibility' ? 'Waiting for eligibility' : 'Waiting', tone: 'neutral', group: row.state === 'queued' ? 'queued' : 'waiting' };
|
||||
}
|
||||
return { label: row.phase === 'cleanup' ? 'Cleaning up' : 'In progress', tone: 'info', group: 'running' };
|
||||
}
|
||||
|
||||
export function provisioningWarnings(raw: string): string[] {
|
||||
try { const value: unknown = JSON.parse(raw); return Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : []; }
|
||||
catch { return []; }
|
||||
}
|
||||
Reference in New Issue
Block a user