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 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;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col gap-3 rounded-[var(--radius-widget)] border border-border bg-surface p-4 sm:col-span-2">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<span className="text-sm font-medium text-fg">{widget.name}</span>
|
|
|
|
|
{data && (
|
2026-08-17 14:27:07 +02:00
|
|
|
<span className="font-mono text-xs tabular-nums text-fg-muted">
|
2026-08-17 14:17:24 +02:00
|
|
|
{data.entrypoints.map((ep) => ep.address).join(" · ") || `${data.entrypoints.length} entrypoints`}
|
|
|
|
|
</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 && (
|
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
|
{data.routers.map((router) => (
|
|
|
|
|
<div key={router.name} className="flex items-center justify-between gap-2 text-xs">
|
|
|
|
|
<span className="truncate text-fg" title={router.rule}>
|
|
|
|
|
{router.name.replace(/@.*$/, "")}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="flex items-center gap-1 text-fg-muted">
|
|
|
|
|
{router.tls && <span title="TLS enabled">🔒</span>}
|
|
|
|
|
<span
|
|
|
|
|
className={router.status === "enabled" ? "text-status-up" : "text-status-down"}
|
|
|
|
|
>
|
|
|
|
|
{router.status}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
2026-08-17 14:27:07 +02:00
|
|
|
<span className="pt-1 text-xs text-fg-muted">
|
|
|
|
|
<span className="font-mono tabular-nums">{data.middlewaresCount}</span> middlewares
|
|
|
|
|
</span>
|
2026-08-17 14:17:24 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|