import { useMemo } from "react"; import { FolderOpen, HardDrive, Settings, Unplug } from "lucide-react"; import { Label, Pie, PieChart } from "recharts"; import { ByteSize } from "~/client/components/bytes-size"; import { Card, CardTitle } from "~/client/components/ui/card"; import { ChartContainer, ChartTooltip, ChartTooltipContent } from "~/client/components/ui/chart"; import type { StatFs, Volume } from "~/client/lib/types"; import { cn } from "~/client/lib/utils"; type Props = { volume: Volume; statfs: StatFs; }; const backendLabels: Record = { directory: "Directory", nfs: "NFS", smb: "SMB", webdav: "WebDAV", rclone: "rclone", sftp: "SFTP", }; type ConfigRowProps = { icon: React.ReactNode; label: string; value: string; mono?: boolean; }; function ConfigRow({ icon, label, value, mono }: ConfigRowProps) { return (
{icon} {label} {value}
); } function BackendConfigRows({ volume }: { volume: Volume }) { const config = volume.config; switch (config.backend) { case "directory": return ( } label="Directory Path" value={config.path} mono /> ); case "nfs": return ( <> } label="Server" value={config.server} mono /> } label="Export Path" value={config.exportPath} mono /> ); case "smb": return ( <> } label="Server" value={config.server} mono /> } label="Share" value={config.share} mono /> ); case "webdav": return ( <> } label="Server" value={config.server} mono /> } label="Path" value={config.path} mono /> ); case "rclone": return ( <> } label="Remote" value={config.remote} mono /> } label="Path" value={config.path} mono /> ); case "sftp": return ( <> } label="Host" value={config.host} mono /> } label="Username" value={config.username} /> } label="Path" value={config.path} mono /> ); } } function DonutChart({ statfs }: { statfs: StatFs }) { const { used = 0, total = 0 } = statfs; const chartData = useMemo( () => [ { name: "Used", value: statfs.used, fill: "var(--strong-accent)" }, { name: "Free", value: statfs.free, fill: "lightgray" }, ], [statfs], ); const usagePercentage = useMemo(() => { return Math.round((used / total) * 100); }, [used, total]); return ( [, name]} /> } /> ); } export const VolumeInfoTabContent = ({ volume, statfs }: Props) => { const { total = 0, used = 0, free = 0 } = statfs; const hasStorage = total > 0; return (
Configuration
} label="Name" value={volume.name} /> } label="Backend" value={backendLabels[volume.type]} />
{hasStorage ? (
Storage
Total
Used
Free
) : (

No storage data available.
Mount the volume to see usage.

)}
); };