import React from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/index'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/index'; import { Button } from '@/components/ui/index'; import { Checkbox } from '@/components/ui/index'; import { MoreHorizontal, Play, Square, RotateCcw, Power, PlayCircle, Pause, X } from 'lucide-react'; interface VMInfo { id: string; vmid: number; name: string; node: string; status: 'running' | 'stopped' | 'paused'; cpu: number; memory: number; memoryTotal: number; disk: number; diskTotal: number; uptime?: string; tags?: string[]; } interface VMListProps { vms: VMInfo[]; onRefresh?: () => void; isLoading?: boolean; onVMAction?: (vm: VMInfo, action: 'start' | 'stop' | 'reboot' | 'shutdown' | 'resume' | 'suspend') => void; onSnapshotAction?: (vm: VMInfo, action: 'create' | 'list' | 'rollback' | 'delete') => void; onMigrate?: (vm: VMInfo) => void; onClone?: (vm: VMInfo) => void; onDelete?: (vm: VMInfo) => void; selectedVMs?: Set; onToggleSelect?: (vm: VMInfo) => void; } export function VMList({ vms, onRefresh, isLoading, onVMAction, onSnapshotAction, onMigrate, onClone, onDelete, selectedVMs = new Set(), onToggleSelect, }: VMListProps) { return ( Virtual Machines
selectedVMs.has(vm.id))} onCheckedChange={(checked) => { if (checked) { vms.forEach((vm) => selectedVMs.add(vm.id)); } else { vms.forEach((vm) => selectedVMs.delete(vm.id)); } }} /> Name VM ID Node Status CPU Memory Disk Uptime Actions {vms.map((vm) => ( onToggleSelect?.(vm)} /> {vm.name} {vm.vmid} {vm.node} {vm.status} {vm.cpu}% {Math.round((vm.memory / vm.memoryTotal) * 100)}% {Math.round((vm.disk / vm.diskTotal) * 100)}% {vm.uptime || '-'}
))}
); } interface VMActionMenuProps { vm: VMInfo; onVMAction?: (vm: VMInfo, action: 'start' | 'stop' | 'reboot' | 'shutdown' | 'resume' | 'suspend') => void; onSnapshotAction?: (vm: VMInfo, action: 'create' | 'list' | 'rollback' | 'delete') => void; onMigrate?: (vm: VMInfo) => void; onClone?: (vm: VMInfo) => void; onDelete?: (vm: VMInfo) => void; } function VMActionMenu({ vm, onVMAction, onSnapshotAction, onMigrate, onClone, onDelete, }: VMActionMenuProps) { const [isOpen, setIsOpen] = React.useState(false); return (
{isOpen && (
{vm.status === 'paused' && ( )} {vm.status === 'running' && ( )}
)}
); }