2026-08-17 14:17:24 +02:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import type { Widget } from "@/lib/config/schema";
|
|
|
|
|
import { useWidgetSubscription } from "@/lib/ws/client";
|
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";
|
2026-08-17 14:17:24 +02:00
|
|
|
|
|
|
|
|
type TraefikWidget = Extract<Widget, { type: "traefik" }>;
|
|
|
|
|
|
|
|
|
|
export function TraefikWidget({ widget, widgetId }: { widget: TraefikWidget; widgetId: string }) {
|
|
|
|
|
const result = useWidgetSubscription(widgetId);
|
|
|
|
|
const data = result?.type === "traefik" ? result.data : null;
|
|
|
|
|
const errorMessage = result?.type === "error" ? result.message : null;
|
2026-08-17 21:11:56 +02:00
|
|
|
const enabledCount = data?.routers.filter((router) => router.status === "enabled").length ?? 0;
|
2026-08-17 14:17:24 +02:00
|
|
|
|
|
|
|
|
return (
|
2026-08-17 17:21:18 +02:00
|
|
|
<WidgetCard span={4}>
|
2026-08-17 14:17:24 +02:00
|
|
|
<div className="flex items-center justify-between">
|
2026-08-17 17:21:18 +02:00
|
|
|
<span className="text-[15px] font-medium text-fg">{widget.name}</span>
|
2026-08-17 14:17:24 +02:00
|
|
|
{data && (
|
2026-08-17 17:21:18 +02:00
|
|
|
<span className="font-mono text-[11px] tabular-nums text-fg-muted">
|
2026-08-17 21:11:56 +02:00
|
|
|
{data.entrypoints.length} entrypoints
|
2026-08-17 14:17:24 +02:00
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{errorMessage && <span className="text-xs text-status-down">{errorMessage}</span>}
|
2026-08-17 14:27:07 +02:00
|
|
|
{!result && !errorMessage && <SkeletonLines count={3} />}
|
2026-08-17 14:17:24 +02:00
|
|
|
{data && (
|
2026-08-17 21:11:56 +02:00
|
|
|
<>
|
|
|
|
|
<div className="flex items-start gap-4">
|
|
|
|
|
<div className="flex flex-col gap-0.5">
|
|
|
|
|
<span className="font-mono text-2xl leading-none font-semibold tabular-nums text-accent">
|
|
|
|
|
{data.routers.length}
|
2026-08-17 14:17:24 +02:00
|
|
|
</span>
|
2026-08-17 21:11:56 +02:00
|
|
|
<span className="text-[10px] tracking-wide text-fg-muted uppercase">Routes</span>
|
2026-08-17 14:17:24 +02:00
|
|
|
</div>
|
2026-08-17 21:11:56 +02:00
|
|
|
{enabledCount !== data.routers.length && (
|
|
|
|
|
<div className="flex flex-col gap-0.5 border-l border-border pl-4">
|
|
|
|
|
<span className="font-mono text-2xl leading-none font-semibold tabular-nums text-status-degraded">
|
|
|
|
|
{enabledCount}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="text-[10px] tracking-wide text-fg-muted uppercase">Enabled</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<span className="text-[11px] text-fg-muted">
|
2026-08-17 14:27:07 +02:00
|
|
|
<span className="font-mono tabular-nums">{data.middlewaresCount}</span> middlewares
|
|
|
|
|
</span>
|
2026-08-17 21:11:56 +02:00
|
|
|
</>
|
2026-08-17 14:17:24 +02:00
|
|
|
)}
|
2026-08-17 17:21:18 +02:00
|
|
|
</WidgetCard>
|
2026-08-17 14:17:24 +02:00
|
|
|
);
|
|
|
|
|
}
|