2026-08-17 14:17:24 +02:00
|
|
|
"use client";
|
|
|
|
|
|
2026-08-17 17:21:18 +02:00
|
|
|
import { Lock } from "@phosphor-icons/react/ssr";
|
2026-08-17 14:17:24 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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 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 && (
|
2026-08-17 17:21:18 +02:00
|
|
|
<div className="flex flex-col">
|
2026-08-17 14:17:24 +02:00
|
|
|
{data.routers.map((router) => (
|
2026-08-17 17:21:18 +02:00
|
|
|
<div key={router.name} className="flex items-center justify-between gap-2 border-t border-border py-1.5 text-[13px] first:border-t-0">
|
2026-08-17 14:17:24 +02:00
|
|
|
<span className="truncate text-fg" title={router.rule}>
|
|
|
|
|
{router.name.replace(/@.*$/, "")}
|
|
|
|
|
</span>
|
2026-08-17 17:21:18 +02:00
|
|
|
<span className="flex items-center gap-1.5 text-[11px] text-fg-muted">
|
|
|
|
|
{router.tls && <Lock size={11} aria-label="TLS enabled" />}
|
2026-08-17 14:17:24 +02:00
|
|
|
<span
|
2026-08-17 17:21:18 +02:00
|
|
|
className={`flex items-center gap-1.5 ${router.status === "enabled" ? "text-status-up" : "text-status-down"}`}
|
2026-08-17 14:17:24 +02:00
|
|
|
>
|
2026-08-17 17:21:18 +02:00
|
|
|
<span className="h-1.5 w-1.5 rounded-full bg-current" />
|
2026-08-17 14:17:24 +02:00
|
|
|
{router.status}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
2026-08-17 17:21:18 +02:00
|
|
|
<span className="pt-2 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 14:17:24 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
2026-08-17 17:21:18 +02:00
|
|
|
</WidgetCard>
|
2026-08-17 14:17:24 +02:00
|
|
|
);
|
|
|
|
|
}
|