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 17:21:18 +02:00
|
|
|
import { WidgetCard } from "@/components/widgets/WidgetCard";
|
2026-08-17 14:01:53 +02:00
|
|
|
import { formatUptime } from "@/lib/format";
|
|
|
|
|
|
|
|
|
|
type DatabaseWidget = Extract<Widget, { type: "database" }>;
|
|
|
|
|
|
|
|
|
|
const ENGINE_LABEL: Record<DatabaseWidget["engine"], string> = {
|
|
|
|
|
postgres: "PostgreSQL",
|
|
|
|
|
redis: "Redis",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function DatabaseWidget({ widget, widgetId }: { widget: DatabaseWidget; widgetId: string }) {
|
|
|
|
|
const result = useWidgetSubscription(widgetId);
|
|
|
|
|
const data = result?.type === "database" ? 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:01:53 +02:00
|
|
|
<div className="flex items-center justify-between gap-2">
|
2026-08-17 17:21:18 +02:00
|
|
|
<span className="text-[15px] font-medium text-fg">{widget.name}</span>
|
2026-08-17 14:01:53 +02:00
|
|
|
<StatusDot status={data?.status} health={data?.health} />
|
|
|
|
|
</div>
|
2026-08-17 17:21:18 +02:00
|
|
|
<span className="text-[11px] text-fg-muted">{ENGINE_LABEL[widget.engine]}</span>
|
2026-08-17 14:01:53 +02:00
|
|
|
{errorMessage && <span className="text-xs text-status-down">{errorMessage}</span>}
|
|
|
|
|
{data?.uptimeSeconds != null && (
|
2026-08-17 17:21:18 +02:00
|
|
|
<span className="text-[11px] text-fg-muted">
|
|
|
|
|
up <span className="font-mono tabular-nums text-fg">{formatUptime(data.uptimeSeconds)}</span>
|
2026-08-17 14:27:07 +02:00
|
|
|
</span>
|
2026-08-17 14:01:53 +02:00
|
|
|
)}
|
2026-08-17 17:21:18 +02:00
|
|
|
</WidgetCard>
|
2026-08-17 14:01:53 +02:00
|
|
|
);
|
|
|
|
|
}
|