diff --git a/src/features/metrics/components/disks/disk.info.tsx b/src/features/metrics/components/disks/disk.info.tsx index 8e1a913e..1ab9d02f 100644 --- a/src/features/metrics/components/disks/disk.info.tsx +++ b/src/features/metrics/components/disks/disk.info.tsx @@ -1,9 +1,24 @@ -import { ActionIcon, Badge, Card, Group, Stack, Image, Text, createStyles, Button } from "@mantine/core"; +import { + ActionIcon, + Badge, + Card, + Group, + Stack, + Image, + Text, + createStyles, + Button, + Progress, + DefaultMantineColor, + Center, + Title, +} from "@mantine/core"; import { Enumerable } from "@/hooks/useServerEventsEnumerableStore"; import { Disk, commands } from "@/lib"; import { IconCheck, IconFolderOpen, IconX } from "@tabler/icons-react"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import drive from "/drive.png"; +import formatBytes from "@/features/metrics/utils/format-bytes"; interface RemovableIconProps { isRemovable?: boolean; @@ -25,10 +40,6 @@ interface DiskInfoProps { } const useStyles = createStyles((theme) => ({ - card: { - backgroundColor: theme.colorScheme === "dark" ? theme.colors.dark[7] : theme.colors.white, - }, - section: { borderBottom: `1px solid ${theme.colorScheme === "dark" ? theme.colors.dark[4] : theme.colors.gray[3]}`, paddingLeft: theme.spacing.md, @@ -56,6 +67,29 @@ const onCheckDisk = async (mountPoint: string) => { }); }; +interface DynamicProgressRangeInput { + from: number; + to: number; + color: DefaultMantineColor; +} +interface DynamicProgressProps { + value: number; + range?: DynamicProgressRangeInput[]; +} + +const DynamicProgress: React.FC = (props) => { + const { value, range } = props; + const [color, setColor] = useState("blue"); + + useEffect(() => { + if (!range) return; + const currentColor = range.find((r) => value >= r.from && value <= r.to)?.color; + if (currentColor) setColor(currentColor); + }, [value, range]); + + return ; +}; + const DiskStatsCard: React.FC = ({ disk }) => { const { classes } = useStyles(); const last = disk.data.at(-1); @@ -65,19 +99,52 @@ const DiskStatsCard: React.FC = ({ disk }) => { await commands.showInFolder(last.mountPoint); }; - useEffect(() => {}, [disk]); + const range: DynamicProgressRangeInput[] = [ + { + from: 0, + to: 50, + color: "green", + }, + { + from: 50, + to: 80, + color: "yellow", + }, + { + from: 80, + to: 100, + color: "red", + }, + ]; return ( - + +
+ {last?.name} +
Drive + + Free: {formatBytes(last?.free || 0)} + +
+ + + Location + + + {last?.mountPoint} + + - {last?.name} - + + Disk Type + + {last?.diskType} @@ -85,7 +152,7 @@ const DiskStatsCard: React.FC = ({ disk }) => { File System - + {last?.fileSystem} diff --git a/src/lib/bindings/Disk.ts b/src/lib/bindings/Disk.ts index 930c7c58..a0ec6d7a 100644 --- a/src/lib/bindings/Disk.ts +++ b/src/lib/bindings/Disk.ts @@ -1,4 +1,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { Timestamp } from "./Timestamp"; -export type Disk = { name: string, free: number, total: number, used: number, mountPoint: string, fileSystem: string, diskType: string, isRemovable: boolean, timestamp: Timestamp, }; \ No newline at end of file +export type Disk = { name: string, free: number, total: number, used: number, usedPercentage: number, mountPoint: string, fileSystem: string, diskType: string, isRemovable: boolean, timestamp: Timestamp, }; \ No newline at end of file