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 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;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col gap-2 rounded-[var(--radius-widget)] border border-border bg-surface p-4">
|
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
|
{widget.href ? (
|
|
|
|
|
<a
|
|
|
|
|
href={widget.href}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
className="text-sm font-medium text-fg hover:text-accent"
|
|
|
|
|
>
|
|
|
|
|
{widget.name}
|
|
|
|
|
</a>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="text-sm font-medium text-fg">{widget.name}</span>
|
|
|
|
|
)}
|
|
|
|
|
<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 && (
|
|
|
|
|
<dl className="flex flex-col gap-1 text-xs text-fg-muted">
|
2026-08-17 14:27:07 +02:00
|
|
|
{data.uptimeSeconds !== null && (
|
2026-08-17 14:01:53 +02:00
|
|
|
<div>
|
2026-08-17 14:27:07 +02:00
|
|
|
Uptime: <span className="font-mono tabular-nums text-fg">{formatUptime(data.uptimeSeconds)}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{widget.showStats && data.cpuPercent !== null && (
|
|
|
|
|
<div>
|
|
|
|
|
CPU: <span className="font-mono tabular-nums text-fg">{data.cpuPercent.toFixed(1)}%</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{widget.showStats && data.memUsageBytes !== null && (
|
|
|
|
|
<div>
|
|
|
|
|
Mem:{" "}
|
|
|
|
|
<span className="font-mono tabular-nums text-fg">
|
|
|
|
|
{formatBytes(data.memUsageBytes)}
|
|
|
|
|
{data.memLimitBytes ? ` / ${formatBytes(data.memLimitBytes)}` : ""}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{data.restartCount > 0 && (
|
|
|
|
|
<div>
|
|
|
|
|
Restarts: <span className="font-mono tabular-nums text-fg">{data.restartCount}</span>
|
2026-08-17 14:01:53 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</dl>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|