'use client'; import Link from 'next/link'; import { Alert, Button, Card, Descriptions, Progress, Space, Table, Tag, Typography } from 'antd'; import { PREVIEW_TOOLTIP, failureLabel, isWait, pendingCounts, previewReadiness, readinessSummary, refusalsText, type DrainPreview, type PreviewFailure, type Readiness, } from '@/lib/drain-preview'; import { publicSandboxIdFromAny } from '@/lib/sandbox-id'; const { Text, Title } = Typography; // A sandbox the node names, linked to its page. function SandboxRef({ id }: { id: string }) { const publicId = publicSandboxIdFromAny(id); return {publicId}; } export function ReadinessBadge({ result }: { result?: Readiness }) { if (!result) return Not checked; const [label, color] = { clean: ['CLEAN', 'green'], not_clean: ['NOT CLEAN', 'red'], unknown: ['UNKNOWN', 'gold'], }[result.verdict]; const summary = readinessSummary(result); return ( {label} {summary ? {summary} : null} {result.checkedAt ? ( Checked ) : null} ); } // Rows keyed by their position: the node may report the same item twice, // such as two uploads of one sandbox. function byPosition(rows: T[]): (T & { key: number })[] { return rows.map((row, key) => ({ ...row, key })); } // What a pending sandbox waits on, colored by whether a drain moves it. function waitTag(wait: string) { return {wait}; } // The node page's panel: the last preview's verdict, every blocker, and what // a drain would do or wait for. export function DrainPreviewPanel({ preview, failure, loading, failureReadiness, }: { preview: DrainPreview | null; failure: PreviewFailure | null; loading: boolean; failureReadiness: Readiness | null; }) { const pending = Array.isArray(preview?.pending) ? preview.pending : []; const counts = pendingCounts(pending); const result = loading ? null : preview ? previewReadiness(preview) : failureReadiness; return ( {result ? (
) : null} {failure ? (
{failure.message}
{refusalsText(failure.refusals) ? (
{refusalsText(failure.refusals)}
) : null} } style={{ marginBottom: 12 }} /> ) : null} {result?.reasons.length ? ( <> Reasons 20 ? { pageSize: 20 } : false} columns={[ { title: 'Reason', dataIndex: 'code', render: (code: string) => code.replaceAll('_', ' ') }, { title: 'Sandbox', dataIndex: 'sandbox_id', render: (id?: string) => id ? : null }, { title: 'Source', dataIndex: 'source' }, { title: 'Detail', dataIndex: 'detail' }, ]} /> ) : null} {result?.orphanInventoryCoverage ? ( {result.orphanInventoryCoverage.gateway_run_dirs === 'enumerated' ? 'Enumerated' : 'Confirmed absent'} {result.orphanInventoryCoverage.root_forward_chain === 'enumerated' ? 'Enumerated' : 'Confirmed absent'} ) : null} {preview ? ( <> {Array.isArray(preview.evacuated) ? preview.evacuated.length : 0} {pending.filter((p) => p.running).length} {preview.warm_pool_evictions !== undefined ? ( {preview.warm_pool_evictions}; evicted after cordon ) : null} {counts.length ? ( {counts.map(([wait, n]) => {waitTag(wait)} {n})} ) : nothing} Planned evacuation and waits ({pending.length})
20 ? { pageSize: 20 } : false} locale={{ emptyText: 'Nothing to do or wait for' }} columns={[ { title: 'Sandbox', dataIndex: 'sandbox_id', width: 340, render: (v: string) => }, { title: 'Wait', dataIndex: 'wait', width: 120, render: (v: string) => waitTag(v) }, { title: 'Running', dataIndex: 'running', width: 90, render: (v: boolean) => (v ? 'yes' : 'no') }, { title: 'Reason', dataIndex: 'reason', render: (v: string | undefined) => v ?? — }, ]} /> ) : !failure && !loading ? ( Not checked. ) : null} ); } export function DrainPreviewAll({ total, checked, running, onCancel, }: { total: number; checked: number; running: boolean; onCancel: () => void; }) { return ( {checked} of {total} workers checked {running ? : null} ); }