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 21:23:01 +02:00
|
|
|
import { StatusDot } from "@/components/widgets/StatusDot";
|
|
|
|
|
import { BrandIcon } from "@/components/widgets/BrandIcon";
|
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 21:23:01 +02:00
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
|
<div className="flex min-w-0 items-center gap-2">
|
|
|
|
|
<BrandIcon slug={widget.icon} />
|
|
|
|
|
{widget.href ? (
|
|
|
|
|
<a
|
|
|
|
|
href={widget.href}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
className="truncate text-[15px] font-medium text-fg hover:text-accent"
|
|
|
|
|
>
|
|
|
|
|
{widget.name}
|
|
|
|
|
</a>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="truncate text-[15px] font-medium text-fg">{widget.name}</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
{data && (
|
|
|
|
|
<span className="font-mono text-[11px] tabular-nums text-fg-muted">
|
|
|
|
|
{data.entrypoints.length} entrypoints
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
<StatusDot status={data ? "running" : undefined} />
|
|
|
|
|
</div>
|
2026-08-17 14:17:24 +02:00
|
|
|
</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
|
|
|
);
|
|
|
|
|
}
|