mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-11-18 11:36:17 +00:00
Update virtual-machines.tsx
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
Container,
|
||||
} from "lucide-react"
|
||||
import useSWR from "swr"
|
||||
import { MetricsDialog } from "./metrics-dialog" // Import MetricsDialog
|
||||
import { MetricsView } from "./metrics-dialog"
|
||||
|
||||
interface VMData {
|
||||
vmid: number
|
||||
@@ -720,60 +720,26 @@ export function VirtualMachines() {
|
||||
setSelectedMetric(null)
|
||||
}}
|
||||
>
|
||||
<DialogContent className="max-w-4xl max-h-[95vh] p-0 flex flex-col overflow-hidden">
|
||||
<DialogContent className="max-w-4xl max-h-[95vh] flex flex-col p-0">
|
||||
{currentView === "main" ? (
|
||||
<>
|
||||
<DialogHeader className="pb-4 border-b border-border px-6 pt-6 flex-shrink-0">
|
||||
<DialogHeader className="pb-4 border-b border-border px-6 pt-6">
|
||||
<DialogTitle className="flex flex-col sm:flex-row sm:items-center gap-3">
|
||||
{/* Desktop layout */}
|
||||
<div className="hidden sm:flex items-center gap-3 flex-wrap">
|
||||
<div className="flex items-center gap-2">
|
||||
<Server className="h-5 w-5 flex-shrink-0" />
|
||||
<span className="text-lg truncate">{selectedVM?.name}</span>
|
||||
<span className="text-sm text-muted-foreground">ID: {selectedVM?.vmid}</span>
|
||||
</div>
|
||||
{selectedVM && (
|
||||
<>
|
||||
<Badge variant="outline" className={`${getTypeBadge(selectedVM.type).color} flex-shrink-0`}>
|
||||
{getTypeBadge(selectedVM.type).icon}
|
||||
{getTypeBadge(selectedVM.type).label}
|
||||
</Badge>
|
||||
<Badge variant="outline" className={`${getStatusColor(selectedVM.status)} flex-shrink-0`}>
|
||||
{selectedVM.status.toUpperCase()}
|
||||
</Badge>
|
||||
{selectedVM.status === "running" && (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Uptime: {formatUptime(selectedVM.uptime)}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<div className="flex items-center gap-2">
|
||||
<Server className="h-5 w-5 flex-shrink-0" />
|
||||
<span className="text-lg truncate">{selectedVM?.name}</span>
|
||||
</div>
|
||||
|
||||
{/* Mobile layout */}
|
||||
<div className="flex sm:hidden flex-col gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Server className="h-5 w-5 flex-shrink-0" />
|
||||
<span className="text-lg truncate">{selectedVM?.name}</span>
|
||||
<span className="text-sm text-muted-foreground">ID: {selectedVM?.vmid}</span>
|
||||
{selectedVM && (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<Badge variant="outline" className={`${getTypeBadge(selectedVM.type).color} flex-shrink-0`}>
|
||||
{getTypeBadge(selectedVM.type).icon}
|
||||
{getTypeBadge(selectedVM.type).label}
|
||||
</Badge>
|
||||
<Badge variant="outline" className={`${getStatusColor(selectedVM.status)} flex-shrink-0`}>
|
||||
{selectedVM.status.toUpperCase()}
|
||||
</Badge>
|
||||
</div>
|
||||
{selectedVM && (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<Badge variant="outline" className={`${getTypeBadge(selectedVM.type).color} flex-shrink-0`}>
|
||||
{getTypeBadge(selectedVM.type).icon}
|
||||
{getTypeBadge(selectedVM.type).label}
|
||||
</Badge>
|
||||
<Badge variant="outline" className={`${getStatusColor(selectedVM.status)} flex-shrink-0`}>
|
||||
{selectedVM.status.toUpperCase()}
|
||||
</Badge>
|
||||
{selectedVM.status === "running" && (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Uptime: {formatUptime(selectedVM.uptime)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -786,14 +752,19 @@ export function VirtualMachines() {
|
||||
Basic Information
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Name</div>
|
||||
<div className="font-semibold text-foreground">{selectedVM.name}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">VMID</div>
|
||||
<div className="font-semibold text-foreground">{selectedVM.vmid}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">CPU Usage</div>
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleMetricClick("cpu")
|
||||
}}
|
||||
onClick={() => handleMetricClick("cpu")}
|
||||
>
|
||||
<div className={`font-semibold mb-1 ${getUsageColor(selectedVM.cpu * 100)}`}>
|
||||
{(selectedVM.cpu * 100).toFixed(1)}%
|
||||
@@ -808,10 +779,7 @@ export function VirtualMachines() {
|
||||
<div className="text-xs text-muted-foreground mb-1">Memory</div>
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleMetricClick("memory")
|
||||
}}
|
||||
onClick={() => handleMetricClick("memory")}
|
||||
>
|
||||
<div
|
||||
className={`font-semibold mb-1 ${getUsageColor((selectedVM.mem / selectedVM.maxmem) * 100)}`}
|
||||
@@ -829,10 +797,7 @@ export function VirtualMachines() {
|
||||
<div className="text-xs text-muted-foreground mb-1">Disk</div>
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleMetricClick("disk")
|
||||
}}
|
||||
onClick={() => handleMetricClick("disk")}
|
||||
>
|
||||
<div
|
||||
className={`font-semibold mb-1 ${getUsageColor((selectedVM.disk / selectedVM.maxdisk) * 100)}`}
|
||||
@@ -846,14 +811,15 @@ export function VirtualMachines() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Uptime</div>
|
||||
<div className="font-semibold text-foreground">{formatUptime(selectedVM.uptime)}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Disk I/O</div>
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleMetricClick("disk")
|
||||
}}
|
||||
onClick={() => handleMetricClick("disk")}
|
||||
>
|
||||
<div className="text-sm text-green-500 flex items-center gap-1">
|
||||
<span>↓</span>
|
||||
@@ -869,10 +835,7 @@ export function VirtualMachines() {
|
||||
<div className="text-xs text-muted-foreground mb-1">Network I/O</div>
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleMetricClick("network")
|
||||
}}
|
||||
onClick={() => handleMetricClick("network")}
|
||||
>
|
||||
<div className="text-sm text-green-500 flex items-center gap-1">
|
||||
<span>↓</span>
|
||||
@@ -887,163 +850,171 @@ export function VirtualMachines() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
|
||||
Resources
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{vmDetails?.config.cores && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">CPU Cores</div>
|
||||
<div className="font-semibold text-blue-500">{vmDetails.config.cores}</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.sockets && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">CPU Sockets</div>
|
||||
<div className="font-semibold text-foreground">{vmDetails.config.sockets}</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.memory && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Memory</div>
|
||||
<div className="font-semibold text-blue-500">{vmDetails.config.memory} MB</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.swap && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Swap</div>
|
||||
<div className="font-semibold text-foreground">{vmDetails.config.swap} MB</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.rootfs && (
|
||||
<div className="col-span-2 lg:col-span-3">
|
||||
<div className="text-xs text-muted-foreground mb-1">Root Filesystem</div>
|
||||
<div className="font-medium text-foreground text-sm break-all font-mono">
|
||||
{vmDetails.config.rootfs}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{Object.keys(vmDetails?.config || {})
|
||||
.filter((key) => key.match(/^(scsi|sata|ide|virtio)\d+$/))
|
||||
.map((diskKey) => (
|
||||
<div key={diskKey} className="col-span-2 lg:col-span-3">
|
||||
<div className="text-xs text-muted-foreground mb-1">
|
||||
{diskKey.toUpperCase().replace(/(\d+)/, " $1")}
|
||||
{detailsLoading ? (
|
||||
<div className="text-center py-8 text-muted-foreground">Loading configuration...</div>
|
||||
) : vmDetails?.config ? (
|
||||
<>
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
|
||||
Resources
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{vmDetails.config.cores && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">CPU Cores</div>
|
||||
<div className="font-semibold text-blue-500">{vmDetails.config.cores}</div>
|
||||
</div>
|
||||
<div className="font-medium text-foreground text-sm break-all font-mono">
|
||||
{vmDetails?.config[diskKey]}
|
||||
)}
|
||||
{vmDetails.config.sockets && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">CPU Sockets</div>
|
||||
<div className="font-semibold text-foreground">{vmDetails.config.sockets}</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails.config.memory && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Memory</div>
|
||||
<div className="font-semibold text-blue-500">{vmDetails.config.memory} MB</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails.config.swap && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Swap</div>
|
||||
<div className="font-semibold text-foreground">{vmDetails.config.swap} MB</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails.config.rootfs && (
|
||||
<div className="col-span-2 lg:col-span-3">
|
||||
<div className="text-xs text-muted-foreground mb-1">Root Filesystem</div>
|
||||
<div className="font-medium text-foreground text-sm break-all font-mono">
|
||||
{vmDetails.config.rootfs}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{Object.keys(vmDetails.config)
|
||||
.filter((key) => key.match(/^(scsi|sata|ide|virtio)\d+$/))
|
||||
.map((diskKey) => (
|
||||
<div key={diskKey} className="col-span-2 lg:col-span-3">
|
||||
<div className="text-xs text-muted-foreground mb-1">
|
||||
{diskKey.toUpperCase().replace(/(\d+)/, " $1")}
|
||||
</div>
|
||||
<div className="font-medium text-foreground text-sm break-all font-mono">
|
||||
{vmDetails.config[diskKey]}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
|
||||
Network
|
||||
</h3>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||||
{Object.keys(vmDetails?.config || {})
|
||||
.filter((key) => key.match(/^net\d+$/))
|
||||
.map((netKey) => (
|
||||
<div key={netKey} className="col-span-1">
|
||||
<div className="text-xs text-muted-foreground mb-1">
|
||||
Network Interface {netKey.replace("net", "")}
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
|
||||
Network
|
||||
</h3>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||||
{Object.keys(vmDetails.config)
|
||||
.filter((key) => key.match(/^net\d+$/))
|
||||
.map((netKey) => (
|
||||
<div key={netKey} className="col-span-1">
|
||||
<div className="text-xs text-muted-foreground mb-1">
|
||||
Network Interface {netKey.replace("net", "")}
|
||||
</div>
|
||||
<div className="font-medium text-green-500 text-sm break-all font-mono">
|
||||
{vmDetails.config[netKey]}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{vmDetails.config.nameserver && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">DNS Nameserver</div>
|
||||
<div className="font-medium text-foreground font-mono">
|
||||
{vmDetails.config.nameserver}
|
||||
</div>
|
||||
</div>
|
||||
<div className="font-medium text-green-500 text-sm break-all font-mono">
|
||||
{vmDetails?.config[netKey]}
|
||||
)}
|
||||
{vmDetails.config.searchdomain && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Search Domain</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.searchdomain}</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{vmDetails?.config.nameserver && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">DNS Nameserver</div>
|
||||
<div className="font-medium text-foreground font-mono">{vmDetails.config.nameserver}</div>
|
||||
)}
|
||||
{vmDetails.config.hostname && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Hostname</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.hostname}</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.searchdomain && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Search Domain</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.searchdomain}</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.hostname && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Hostname</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.hostname}</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
|
||||
Options
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{vmDetails?.config.onboot !== undefined && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Start on Boot</div>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
vmDetails.config.onboot
|
||||
? "bg-green-500/10 text-green-500 border-green-500/20"
|
||||
: "bg-red-500/10 text-red-500 border-red-500/20"
|
||||
}
|
||||
>
|
||||
{vmDetails.config.onboot ? "Yes" : "No"}
|
||||
</Badge>
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
|
||||
Options
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{vmDetails.config.onboot !== undefined && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Start on Boot</div>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
vmDetails.config.onboot
|
||||
? "bg-green-500/10 text-green-500 border-green-500/20"
|
||||
: "bg-red-500/10 text-red-500 border-red-500/20"
|
||||
}
|
||||
>
|
||||
{vmDetails.config.onboot ? "Yes" : "No"}
|
||||
</Badge>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails.config.unprivileged !== undefined && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Unprivileged</div>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
vmDetails.config.unprivileged
|
||||
? "bg-green-500/10 text-green-500 border-green-500/20"
|
||||
: "bg-yellow-500/10 text-yellow-500 border-yellow-500/20"
|
||||
}
|
||||
>
|
||||
{vmDetails.config.unprivileged ? "Yes" : "No"}
|
||||
</Badge>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails.config.ostype && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">OS Type</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.ostype}</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails.config.arch && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Architecture</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.arch}</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails.config.boot && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Boot Order</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.boot}</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails.config.features && (
|
||||
<div className="col-span-2 lg:col-span-3">
|
||||
<div className="text-xs text-muted-foreground mb-1">Features</div>
|
||||
<div className="font-medium text-foreground text-sm">{vmDetails.config.features}</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.unprivileged !== undefined && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Unprivileged</div>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
vmDetails.config.unprivileged
|
||||
? "bg-green-500/10 text-green-500 border-green-500/20"
|
||||
: "bg-yellow-500/10 text-yellow-500 border-yellow-500/20"
|
||||
}
|
||||
>
|
||||
{vmDetails.config.unprivileged ? "Yes" : "No"}
|
||||
</Badge>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.ostype && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">OS Type</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.ostype}</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.arch && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Architecture</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.arch}</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.boot && (
|
||||
<div>
|
||||
<div className="text-xs text-muted-foreground mb-1">Boot Order</div>
|
||||
<div className="font-medium text-foreground">{vmDetails.config.boot}</div>
|
||||
</div>
|
||||
)}
|
||||
{vmDetails?.config.features && (
|
||||
<div className="col-span-2 lg:col-span-3">
|
||||
<div className="text-xs text-muted-foreground mb-1">Features</div>
|
||||
<div className="font-medium text-foreground text-sm">{vmDetails.config.features}</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-border bg-background px-6 py-4 flex-shrink-0">
|
||||
<div className="border-t border-border bg-background px-6 py-4 mt-auto">
|
||||
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
|
||||
Control Actions
|
||||
</h3>
|
||||
@@ -1083,18 +1054,19 @@ export function VirtualMachines() {
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : currentView === "metrics" && selectedMetric ? (
|
||||
<MetricsDialog
|
||||
vmid={selectedVM?.vmid || 0}
|
||||
vmName={selectedVM?.name || ""}
|
||||
vmType={selectedVM?.type || "qemu"}
|
||||
metric={selectedMetric}
|
||||
onBack={() => {
|
||||
setCurrentView("main")
|
||||
setSelectedMetric(null)
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
) : (
|
||||
/* Render metrics view when currentView is "metrics" */
|
||||
selectedVM &&
|
||||
selectedMetric && (
|
||||
<MetricsView
|
||||
vmid={selectedVM.vmid}
|
||||
vmName={selectedVM.name}
|
||||
vmType={selectedVM.type as "qemu" | "lxc"}
|
||||
metricType={selectedMetric}
|
||||
onBack={handleBackToMain}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user