import { useQuery } from '@tanstack/react-query'; import { useNavigate } from 'react-router-dom'; import { getOperations, type OperationsView } from '@/lib/api-client'; import { useDemoMode } from '@/lib/demo-mode'; import { formatRelative } from '@/lib/time'; import { DemoRestricted } from '@/shared/components'; import { Activity, AlertTriangle, Clock, Database, Loader2, Timer } from 'lucide-react'; function statusClass(status: string): string { switch (status) { case 'deployed': case 'completed': case 'success': return 'text-[var(--success)]'; case 'failed': case 'cancelled': case 'rolled_back': return 'text-[var(--error)]'; case 'building': case 'deploying': case 'in_progress': case 'running': return 'text-[var(--accent-primary)]'; default: return 'text-[var(--warning)]'; } } function Section({ title, icon: Icon, count, children }: { title: string; icon: typeof Activity; count: number; children: React.ReactNode; }) { return (

{title}

({count})
{children}
); } function EmptyLine({ text }: { text: string }) { return

{text}

; } export function OperationsPage() { const isDemoMode = useDemoMode(); const navigate = useNavigate(); const opsQuery = useQuery({ queryKey: ['operations'], queryFn: getOperations, enabled: !isDemoMode, refetchInterval: (query) => (query.state.data?.active_deployments?.length ?? 0) > 0 ? 3000 : 15000, }); if (isDemoMode) { return ; } const ops: OperationsView | undefined = opsQuery.data; const active = ops?.active_deployments ?? []; const failed = ops?.recent_failures ?? []; const cron = ops?.cron_runs ?? []; const backups = ops?.backups ?? []; const queue = ops?.deploy_queue ?? []; const queuedTotal = queue.reduce((sum, q) => sum + q.queued, 0); return (

Operations_

Live view of deploys, queues, cron runs, and backups

{opsQuery.isLoading ? (
) : (

In flight

{active.length}

Queued

{queuedTotal}

Failed 24h

{failed.length}

Backups 24h

{backups.length}

{active.length === 0 ? ( ) : (
{active.map((d) => ( ))}
)}
{failed.length === 0 ? ( ) : (
{failed.map((d) => ( ))}
)}
{cron.length === 0 ? ( ) : (
{cron.map((r) => (
{r.status} {r.job_name} {r.schedule} {r.error && {r.error}} {formatRelative(r.started_at)}
))}
)}
{backups.length === 0 ? ( ) : (
{backups.map((b) => (
{b.status} {b.database_name} {b.size} {formatRelative(b.created_at)}
))}
)}
{queue.length > 0 && (
{queue.map((q) => (
{q.service_id.slice(0, 8)} {q.running ? 'running' : 'idle'} {q.queued} queued
))}
)}
)}
); }