From f20e46dee0abf4cb4faa3d63dd8e7dc449d71631 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Tue, 21 Oct 2025 17:20:16 +0200 Subject: [PATCH] Update AppImage --- AppImage/components/metrics-dialog.tsx | 208 ++++++++++------------- AppImage/components/virtual-machines.tsx | 171 +++++++++---------- 2 files changed, 169 insertions(+), 210 deletions(-) diff --git a/AppImage/components/metrics-dialog.tsx b/AppImage/components/metrics-dialog.tsx index 4c79aaf..4c663da 100644 --- a/AppImage/components/metrics-dialog.tsx +++ b/AppImage/components/metrics-dialog.tsx @@ -10,7 +10,6 @@ interface MetricsViewProps { vmid: number vmName: string vmType: "qemu" | "lxc" - metricType: "cpu" | "memory" | "network" | "disk" onBack: () => void } @@ -22,14 +21,7 @@ const TIMEFRAME_OPTIONS = [ { value: "year", label: "1 Year" }, ] -const METRIC_TITLES = { - cpu: "CPU Usage", - memory: "Memory Usage", - network: "Network Traffic", - disk: "Disk I/O", -} - -export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: MetricsViewProps) { +export function MetricsView({ vmid, vmName, vmType, onBack }: MetricsViewProps) { const [timeframe, setTimeframe] = useState("week") const [data, setData] = useState([]) const [loading, setLoading] = useState(false) @@ -61,23 +53,19 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric const date = new Date(item.time * 1000) let timeLabel = "" - // Format time based on timeframe if (timeframe === "hour") { - // For 1 hour: show HH:mm timeLabel = date.toLocaleString("en-US", { hour: "2-digit", minute: "2-digit", hour12: false, }) } else if (timeframe === "day") { - // For 24 hours: show HH:mm timeLabel = date.toLocaleString("en-US", { hour: "2-digit", minute: "2-digit", hour12: false, }) } else if (timeframe === "week") { - // For 7 days: show Mon DD HH:mm timeLabel = date.toLocaleString("en-US", { month: "short", day: "numeric", @@ -86,13 +74,11 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric hour12: false, }) } else if (timeframe === "month") { - // For 30 days: show Mon DD timeLabel = date.toLocaleString("en-US", { month: "short", day: "numeric", }) } else { - // For 1 year: show Mon YYYY timeLabel = date.toLocaleString("en-US", { month: "short", year: "numeric", @@ -125,7 +111,7 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric return tick } - const renderChart = () => { + const renderAllCharts = () => { if (loading) { return (
@@ -150,17 +136,15 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric ) } - // Calculate tick interval based on data length const tickInterval = Math.ceil(data.length / 8) - switch (metricType) { - case "cpu": - const maxCpuValue = Math.max(...data.map((d) => d.cpu || 0)) - const cpuDomainMax = Math.ceil(maxCpuValue * 1.15) // 15% margin - - return ( - - + return ( +
+ {/* CPU Chart */} +
+

CPU Usage

+ + @@ -178,8 +162,7 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric className="text-foreground" tick={{ fill: "currentColor" }} label={{ value: "%", angle: -90, position: "insideLeft", fill: "currentColor" }} - domain={[0, cpuDomainMax]} - allowDataOverflow={false} + domain={[0, (dataMax: number) => Math.ceil(dataMax * 1.15)]} /> - + - ) +
- case "memory": - const maxMemoryValue = Math.max(...data.map((d) => d.memory || 0)) - const memoryDomainMax = Math.ceil(maxMemoryValue * 1.15) // 15% margin - - return ( - - + {/* Memory Chart */} +
+

Memory Usage

+ + @@ -226,8 +207,7 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric className="text-foreground" tick={{ fill: "currentColor" }} label={{ value: "%", angle: -90, position: "insideLeft", fill: "currentColor" }} - domain={[0, memoryDomainMax]} - allowDataOverflow={false} + domain={[0, (dataMax: number) => Math.ceil(dataMax * 1.15)]} /> - + - ) +
- case "network": - const maxNetworkValue = Math.max(...data.map((d) => Math.max(d.netin || 0, d.netout || 0))) - const networkDomainMax = Math.ceil(maxNetworkValue * 1.15) // 15% margin - - return ( - - + {/* Disk I/O Chart */} +
+

Disk I/O

+ + @@ -274,8 +252,7 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric className="text-foreground" tick={{ fill: "currentColor" }} label={{ value: "MB", angle: -90, position: "insideLeft", fill: "currentColor" }} - domain={[0, networkDomainMax]} - allowDataOverflow={false} + domain={[0, (dataMax: number) => Math.ceil(dataMax * 1.15)]} /> - - - - - - ) - - case "disk": - const maxDiskValue = Math.max(...data.map((d) => Math.max(d.diskread || 0, d.diskwrite || 0))) - const diskDomainMax = Math.ceil(maxDiskValue * 1.15) // 15% margin - - return ( - - - - - - - + - ) +
- default: - return null - } + {/* Network I/O Chart */} +
+

Network I/O

+ + + + + Math.ceil(dataMax * 1.15)]} + /> + + + + + + +
+
+ ) } return ( @@ -379,9 +351,7 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
-

- {METRIC_TITLES[metricType]} - {vmName} -

+

Metrics - {vmName}

VMID: {vmid} • Type: {vmType.toUpperCase()}

@@ -402,8 +372,8 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
- {/* Scrollable Content */} -
{renderChart()}
+ {/* Scrollable Content with all charts */} +
{renderAllCharts()}
) } diff --git a/AppImage/components/virtual-machines.tsx b/AppImage/components/virtual-machines.tsx index 2b0a3a6..1de44dd 100644 --- a/AppImage/components/virtual-machines.tsx +++ b/AppImage/components/virtual-machines.tsx @@ -1,5 +1,7 @@ "use client" +import type React from "react" + import { useState, useMemo, useEffect } from "react" import { Card, CardContent, CardHeader, CardTitle } from "./ui/card" import { Badge } from "./ui/badge" @@ -170,6 +172,30 @@ const getModalProgressColor = (percent: number): string => { return "[&>div]:bg-blue-500" } +// Placeholder for the undeclared getOSIcon function +const getOSIcon = (ostype: string | undefined, vmType: string): React.ReactNode => { + if (vmType === "lxc") { + return + } + + switch (ostype) { + case "debian": + return Debian + case "ubuntu": + return Ubuntu + case "centos": + return CentOS + case "fedora": + return Fedora + case "windows": + return Windows + case "alpine": + return Alpine + default: + return + } +} + export function VirtualMachines() { const { data: vmData, @@ -188,8 +214,8 @@ export function VirtualMachines() { const [detailsLoading, setDetailsLoading] = useState(false) const [vmConfigs, setVmConfigs] = useState>({}) const [currentView, setCurrentView] = useState<"main" | "metrics">("main") - const [selectedMetric, setSelectedMetric] = useState<"cpu" | "memory" | "disk" | "network" | null>(null) const [showAdditionalInfo, setShowAdditionalInfo] = useState(false) + const [selectedMetric, setSelectedMetric] = useState(null) // undeclared variable fix useEffect(() => { const fetchLXCIPs = async () => { @@ -223,7 +249,6 @@ export function VirtualMachines() { const handleVMClick = async (vm: VMData) => { setSelectedVM(vm) setCurrentView("main") - setSelectedMetric(null) setShowAdditionalInfo(false) setDetailsLoading(true) try { @@ -239,14 +264,12 @@ export function VirtualMachines() { } } - const handleMetricClick = (metric: "cpu" | "memory" | "disk" | "network") => { - setSelectedMetric(metric) + const handleMetricsClick = () => { setCurrentView("metrics") } const handleBackToMain = () => { setCurrentView("main") - setSelectedMetric(null) } const handleVMControl = async (vmid: number, action: string) => { @@ -562,7 +585,7 @@ export function VirtualMachines() {
{ - setSelectedMetric("cpu") + setSelectedMetric("cpu") // undeclared variable fix }} >
Basic Information -
- {/* CPU Usage Card */} - - -
CPU Usage
-
handleMetricClick("cpu")} - > -
+ + +
+ {/* CPU Usage */} +
+
CPU Usage
+
{(selectedVM.cpu * 100).toFixed(1)}%
- - - {/* Memory Card */} - - -
Memory
-
handleMetricClick("memory")} - > + {/* Memory */} +
+
Memory
{(selectedVM.mem / 1024 ** 3).toFixed(1)} /{" "} {(selectedVM.maxmem / 1024 ** 3).toFixed(1)} GB
- - - {/* Disk Card */} - - -
Disk
-
handleMetricClick("disk")} - > -
- {(selectedVM.disk / 1024 ** 3).toFixed(1)} /{" "} - {(selectedVM.maxdisk / 1024 ** 3).toFixed(1)} GB -
- -
-
-
- - {/* Disk I/O Card */} - - -
Disk I/O
-
handleMetricClick("disk")} - > -
- - {((selectedVM.diskread || 0) / 1024 ** 2).toFixed(2)} MB -
-
- - {((selectedVM.diskwrite || 0) / 1024 ** 2).toFixed(2)} MB + {/* Disk I/O */} +
+
Disk I/O
+
+
+ + {((selectedVM.diskread || 0) / 1024 ** 2).toFixed(2)} MB +
+
+ + {((selectedVM.diskwrite || 0) / 1024 ** 2).toFixed(2)} MB +
- - - {/* Network I/O Card */} - - -
Network I/O
-
handleMetricClick("network")} - > -
- - {((selectedVM.netin || 0) / 1024 ** 2).toFixed(2)} MB -
-
- - {((selectedVM.netout || 0) / 1024 ** 2).toFixed(2)} MB + {/* Network I/O */} +
+
Network I/O
+
+
+ + {((selectedVM.netin || 0) / 1024 ** 2).toFixed(2)} MB +
+
+ + {((selectedVM.netout || 0) / 1024 ** 2).toFixed(2)} MB +
- - -
+ + {/* OS Icon / VM Icon */} +
+ {getOSIcon(vmDetails?.config?.ostype, selectedVM.type)} {/* undeclared variable fix */} +
+
+
+
+ {/* ... existing RESOURCES card and additional info ... */} {detailsLoading ? (
Loading configuration...
) : vmDetails?.config ? ( @@ -1140,13 +1130,12 @@ export function VirtualMachines() {
) : ( - selectedVM && - selectedMetric && ( + selectedVM && ( + // Pass only vmid, vmName, vmType and onBack )