2026-08-17 14:01:53 +02:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import type { Widget } from "@/lib/config/schema";
|
|
|
|
|
import { useWidgetSubscription } from "@/lib/ws/client";
|
|
|
|
|
import { StatusDot } from "@/components/widgets/StatusDot";
|
2026-08-17 14:27:07 +02:00
|
|
|
import { SkeletonLines } from "@/components/widgets/Skeleton";
|
2026-08-17 17:21:18 +02:00
|
|
|
import { WidgetCard } from "@/components/widgets/WidgetCard";
|
|
|
|
|
import { MetricBar } from "@/components/widgets/MetricBar";
|
2026-08-17 14:01:53 +02:00
|
|
|
import { formatBytes, formatUptime } from "@/lib/format";
|
|
|
|
|
|
|
|
|
|
type DockerWidget = Extract<Widget, { type: "docker" }>;
|
|
|
|
|
|
|
|
|
|
export function DockerWidget({ widget, widgetId }: { widget: DockerWidget; widgetId: string }) {
|
|
|
|
|
const result = useWidgetSubscription(widgetId);
|
|
|
|
|
const data = result?.type === "docker" ? result.data : null;
|
|
|
|
|
const errorMessage = result?.type === "error" ? result.message : null;
|
2026-08-17 17:21:18 +02:00
|
|
|
const memPercent = data?.memUsageBytes != null && data.memLimitBytes ? (data.memUsageBytes / data.memLimitBytes) * 100 : null;
|
2026-08-17 14:01:53 +02:00
|
|
|
|
|
|
|
|
return (
|
2026-08-17 17:21:18 +02:00
|
|
|
<WidgetCard span={4}>
|
2026-08-17 14:01:53 +02:00
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
|
{widget.href ? (
|
|
|
|
|
<a
|
|
|
|
|
href={widget.href}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
2026-08-17 17:21:18 +02:00
|
|
|
className="text-[15px] font-medium text-fg hover:text-accent"
|
2026-08-17 14:01:53 +02:00
|
|
|
>
|
|
|
|
|
{widget.name}
|
|
|
|
|
</a>
|
|
|
|
|
) : (
|
2026-08-17 17:21:18 +02:00
|
|
|
<span className="text-[15px] font-medium text-fg">{widget.name}</span>
|
2026-08-17 14:01:53 +02:00
|
|
|
)}
|
|
|
|
|
<StatusDot status={data?.status} health={data?.health} />
|
|
|
|
|
</div>
|
|
|
|
|
{errorMessage && <span className="text-xs text-status-down">{errorMessage}</span>}
|
2026-08-17 14:27:07 +02:00
|
|
|
{!result && !errorMessage && <SkeletonLines />}
|
2026-08-17 14:01:53 +02:00
|
|
|
{data && (
|
2026-08-17 17:21:18 +02:00
|
|
|
<>
|
|
|
|
|
{widget.showStats && data.cpuPercent !== null && memPercent !== null && (
|
|
|
|
|
<div className="mt-0.5 flex gap-4">
|
|
|
|
|
<MetricBar label="CPU" percent={data.cpuPercent} detail={`${data.cpuPercent.toFixed(1)}%`} />
|
|
|
|
|
<MetricBar label="MEM" percent={memPercent} detail={`${memPercent.toFixed(0)}%`} />
|
2026-08-17 14:27:07 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
2026-08-17 17:21:18 +02:00
|
|
|
<div className="flex items-center gap-3 text-[11px] text-fg-muted">
|
|
|
|
|
{data.uptimeSeconds !== null && <span>up {formatUptime(data.uptimeSeconds)}</span>}
|
|
|
|
|
{widget.showStats && data.memUsageBytes !== null && memPercent === null && (
|
|
|
|
|
<span className="font-mono tabular-nums">{formatBytes(data.memUsageBytes)}</span>
|
|
|
|
|
)}
|
|
|
|
|
{data.restartCount > 0 && <span>{data.restartCount} restarts</span>}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
2026-08-17 14:01:53 +02:00
|
|
|
)}
|
2026-08-17 17:21:18 +02:00
|
|
|
</WidgetCard>
|
2026-08-17 14:01:53 +02:00
|
|
|
);
|
|
|
|
|
}
|