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 { SPageHead, SPill, SStat, Ticks } from '@/shared/components/sentry'; import { statusTone } from '@/shared/components/sentry-utils'; import { Activity, AlertTriangle, Clock, Database, Loader2, Timer } from 'lucide-react'; 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 (
{opsQuery.isLoading ? (
) : (
} label="In Flight" value={active.length} foot="deploying now" /> } label="Queued" value={queuedTotal} foot="waiting in queue" /> } label="Failed 24h" value={failed.length} foot="need attention" /> } label="Backups 24h" value={backups.length} foot="completed runs" />
{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
))}
)}
)}
); }