import React, { useState, useEffect, useCallback } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/index'; import { Button } from '@/components/ui/index'; import { Badge } from '@/components/ui/index'; import { RefreshCw } from 'lucide-react'; import { listClusterTasks, listProxmoxClusters, ClusterTask } from '@/lib/proxmoxClient'; function taskBadgeVariant(exitstatus?: string): 'default' | 'destructive' | 'secondary' { if (!exitstatus) return 'secondary'; return exitstatus === 'OK' ? 'default' : 'destructive'; } function taskBadgeLabel(exitstatus?: string): string { if (!exitstatus) return 'running'; return exitstatus; } function formatTimestamp(epoch: number): string { if (!epoch) return '-'; return new Date(epoch * 1000).toLocaleString(); } export function ProxmoxTasksPage() { const [tasks, setTasks] = useState([]); const [clusterId, setClusterId] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const loadTasks = useCallback(async (cId: string) => { if (!cId) return; setLoading(true); setError(null); try { const t = await listClusterTasks(cId, 100); setTasks(t); } catch (e) { setError(String(e)); console.error(e); } finally { setLoading(false); } }, []); useEffect(() => { listProxmoxClusters() .then((cls) => { if (cls.length > 0) { setClusterId(cls[0].id); void loadTasks(cls[0].id); } }) .catch(console.error); }, [loadTasks]); const runningCount = tasks.filter((t) => !t.exitstatus).length; const completedCount = tasks.filter((t) => t.exitstatus === 'OK').length; const failedCount = tasks.filter( (t) => t.exitstatus && t.exitstatus !== 'OK' ).length; return (

Tasks

Cluster task log and operations

{error && (
{error}
)}
{runningCount}
Running
{completedCount}
Completed
{failedCount}
Failed
Task Log {loading ? (
Loading tasks...
) : tasks.length === 0 ? (
{clusterId ? 'No tasks found.' : 'No cluster configured.'}
) : (
{tasks.map((t, i) => (
{taskBadgeLabel(t.exitstatus)} {t.type} {t.node} {t.user} {formatTimestamp(t.starttime)} {t.upid}
))}
)}
); }