From 3d4bd79ad51716e71a8d76e2dec9784371056ede Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Mon, 2 Dec 2024 11:47:48 +0800 Subject: [PATCH] feat: gpu info --- src/components/NetworkChart.tsx | 43 ++++++++++++------------- src/components/ServerDetailOverview.tsx | 16 +++++++-- src/types/nezha-api.ts | 1 + 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/components/NetworkChart.tsx b/src/components/NetworkChart.tsx index 2049add..0af6b21 100644 --- a/src/components/NetworkChart.tsx +++ b/src/components/NetworkChart.tsx @@ -111,28 +111,27 @@ export const NetworkChartClient = React.memo(function NetworkChart({ const defaultChart = "All"; - const [activeCharts, setActiveCharts] = React.useState([defaultChart]); + const [activeCharts, setActiveCharts] = React.useState([ + defaultChart, + ]); - const handleButtonClick = useCallback( - (chart: string) => { - setActiveCharts((prev) => { - if (chart === defaultChart) { - return [defaultChart]; - } - - const newCharts = prev.filter(c => c !== defaultChart); - const chartIndex = newCharts.indexOf(chart); - - if (chartIndex === -1) { - return newCharts.length === 0 ? [chart] : [...newCharts, chart]; - } else { - const result = newCharts.filter(c => c !== chart); - return result.length === 0 ? [defaultChart] : result; - } - }); - }, - [], - ); + const handleButtonClick = useCallback((chart: string) => { + setActiveCharts((prev) => { + if (chart === defaultChart) { + return [defaultChart]; + } + + const newCharts = prev.filter((c) => c !== defaultChart); + const chartIndex = newCharts.indexOf(chart); + + if (chartIndex === -1) { + return newCharts.length === 0 ? [chart] : [...newCharts, chart]; + } else { + const result = newCharts.filter((c) => c !== chart); + return result.length === 0 ? [defaultChart] : result; + } + }); + }, []); const getColorByIndex = useCallback( (chart: string) => { @@ -177,7 +176,7 @@ export const NetworkChartClient = React.memo(function NetworkChart({ /> )); } - + return activeCharts.map((chart) => (

{"CPU"}

- {server.host.cpu ? ( -
{server.host.cpu}
+ {server.host.cpu.length > 0 ? ( +
{server.host.cpu.join(", ")}
+ ) : ( +
{t("serverDetail.unknown")}
+ )} +
+ + + + +
+

{"GPU"}

+ {server.host.gpu.length > 0 ? ( +
{server.host.gpu.join(", ")}
) : (
{t("serverDetail.unknown")}
)} diff --git a/src/types/nezha-api.ts b/src/types/nezha-api.ts index 5f15971..48cb38a 100644 --- a/src/types/nezha-api.ts +++ b/src/types/nezha-api.ts @@ -16,6 +16,7 @@ export interface NezhaServerHost { platform: string; platform_version: string; cpu: string[]; + gpu: string[]; mem_total: number; disk_total: number; swap_total: number;