feat(system-resources-widget): add visible charts option (#4069)
This commit is contained in:
1 parent
8c24da8732
commit
b30cc21dbe
4 files changed
+46
-35
No files matched your search
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Box, Group, Stack } from "@mantine/core";
|
||||
import { useElementSize } from "@mantine/hooks";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
@@ -10,11 +11,10 @@ import { CombinedNetworkTrafficChart } from "./chart/combined-network-traffic";
|
||||
import { SystemResourceCPUChart } from "./chart/cpu-chart";
|
||||
import { SystemResourceMemoryChart } from "./chart/memory-chart";
|
||||
import { NetworkTrafficChart } from "./chart/network-traffic";
|
||||
import classes from "./component.module.css";
|
||||
|
||||
const MAX_QUEUE_SIZE = 15;
|
||||
|
||||
export default function SystemResources({ integrationIds }: WidgetComponentProps<"systemResources">) {
|
||||
export default function SystemResources({ integrationIds, options }: WidgetComponentProps<"systemResources">) {
|
||||
const { ref, width } = useElementSize();
|
||||
|
||||
const [data] = clientApi.widget.healthMonitoring.getSystemHealthStatus.useSuspenseQuery({
|
||||
@@ -49,34 +49,40 @@ export default function SystemResources({ integrationIds }: WidgetComponentProps
|
||||
},
|
||||
);
|
||||
|
||||
const showNetwork = items.length === 0 || items.every((item) => item.network !== null);
|
||||
const showNetwork =
|
||||
items.length === 0 || (items.every((item) => item.network !== null) && options.visibleCharts.includes("network"));
|
||||
const rowHeight = `calc((100% - ${(options.visibleCharts.length - 1) * 8}px) / ${options.visibleCharts.length})`;
|
||||
|
||||
return (
|
||||
<div ref={ref} className={classes.grid}>
|
||||
<div className={classes.colSpanWide}>
|
||||
<SystemResourceCPUChart cpuUsageOverTime={items.map((item) => item.cpu)} />
|
||||
</div>
|
||||
<div className={classes.colSpanWide}>
|
||||
<SystemResourceMemoryChart
|
||||
memoryUsageOverTime={items.map((item) => item.memory)}
|
||||
totalCapacityInBytes={memoryCapacityInBytes}
|
||||
/>
|
||||
</div>
|
||||
<Stack gap="xs" p="xs" ref={ref} h="100%">
|
||||
{options.visibleCharts.includes("cpu") && (
|
||||
<Box h={rowHeight}>
|
||||
<SystemResourceCPUChart cpuUsageOverTime={items.map((item) => item.cpu)} />
|
||||
</Box>
|
||||
)}
|
||||
{options.visibleCharts.includes("memory") && (
|
||||
<Box h={rowHeight}>
|
||||
<SystemResourceMemoryChart
|
||||
memoryUsageOverTime={items.map((item) => item.memory)}
|
||||
totalCapacityInBytes={memoryCapacityInBytes}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
{showNetwork &&
|
||||
(width > 200 ? (
|
||||
<>
|
||||
(width > 256 ? (
|
||||
<Group h={rowHeight} gap="xs" grow>
|
||||
{/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */}
|
||||
<NetworkTrafficChart usageOverTime={items.map((item) => item.network!.down)} isUp={false} />
|
||||
|
||||
{/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */}
|
||||
<NetworkTrafficChart usageOverTime={items.map((item) => item.network!.up)} isUp />
|
||||
</>
|
||||
</Group>
|
||||
) : (
|
||||
<div className={classes.colSpanWide}>
|
||||
<Box h={rowHeight}>
|
||||
{/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */}
|
||||
<CombinedNetworkTrafficChart usageOverTime={items.map((item) => item.network!)} />
|
||||
</div>
|
||||
</Box>
|
||||
))}
|
||||
</div>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user