import StatusBadge from './StatusBadge'; /** * @param {{ vms: Array<{ vmid: number; name: string; type: string; status: string; cpu: number; memory: { total: number; used: number }; disk: { total: number; used: number }; node: string }> }} props * @returns {import('react').ReactNode} */ export default function VMList({ vms }) { if (!vms?.length) { return

No VMs found.

; } const running = vms.filter((vm) => vm.status === 'running'); const stopped = vms.filter((vm) => vm.status !== 'running'); return (
{running.length > 0 && (

Running ({running.length})

{running.map((vm) => ( ))}
VMID Name Node CPU Memory Status
{vm.vmid} {vm.name} {vm.node} {(vm.cpu * 100).toFixed(1)}% {formatBytes(vm.memory?.used || 0)} / {formatBytes(vm.memory?.total || 0)}
)} {stopped.length > 0 && (

Stopped ({stopped.length})

{stopped.map((vm) => ( ))}
VMID Name Node Disk Status
{vm.vmid} {vm.name} {vm.node} {formatBytes(vm.disk?.used || 0)}
)}
); } /** @param {number} bytes @returns {string} */ function formatBytes(bytes) { if (!bytes) return '0 B'; const units = ['B', 'KB', 'MB', 'GB', 'TB']; let i = 0; let v = bytes; while (v >= 1024 && i < units.length - 1) { v /= 1024; i++; } return `${v.toFixed(1)} ${units[i]}`; }