Multi-tenant platform (182 pages, 228 API routes, ~30 modules) built on a deterministic verification core: clinical-trial claims checked against ClinicalTrials.gov registered results and raw event counts (ARR/NNT/RR+CI recomputed in code, oracle-tested), code-enforced exact-span grounding, and multi-source cross-verification. Auth/RBAC/multi-tenancy, document processing at scale (unpdf + Docling), agentic workflows, Claude Science connector, compliance/audit, billing, public API, and more. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
113 lines
3.1 KiB
TypeScript
113 lines
3.1 KiB
TypeScript
"use client";
|
|
|
|
import type { ErrorLevel, HealthStatus } from "@/lib/observability/types";
|
|
|
|
// Small shared presentational primitives used across the observability views:
|
|
// status/level pills, loading/empty/error states, and timestamp formatting.
|
|
|
|
export function formatTime(iso: string): string {
|
|
const d = new Date(iso);
|
|
if (Number.isNaN(d.getTime())) return iso;
|
|
return d.toLocaleString(undefined, {
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
second: "2-digit",
|
|
});
|
|
}
|
|
|
|
export function relativeTime(iso: string): string {
|
|
const then = new Date(iso).getTime();
|
|
if (Number.isNaN(then)) return iso;
|
|
const diff = Date.now() - then;
|
|
const s = Math.round(diff / 1000);
|
|
if (s < 60) return `${s}s ago`;
|
|
const m = Math.round(s / 60);
|
|
if (m < 60) return `${m}m ago`;
|
|
const h = Math.round(m / 60);
|
|
if (h < 24) return `${h}h ago`;
|
|
return `${Math.round(h / 24)}d ago`;
|
|
}
|
|
|
|
const HEALTH_STYLES: Record<HealthStatus, string> = {
|
|
ok: "bg-emerald-50 text-emerald-700 border-emerald-200",
|
|
degraded: "bg-amber-50 text-amber-700 border-amber-200",
|
|
down: "bg-red-50 text-red-700 border-red-200",
|
|
};
|
|
|
|
export function HealthPill({ status }: { status: HealthStatus }) {
|
|
return (
|
|
<span
|
|
className={`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-0.5 text-xs font-medium ${HEALTH_STYLES[status]}`}
|
|
>
|
|
<span className="h-1.5 w-1.5 rounded-full bg-current" />
|
|
{status}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
const LEVEL_STYLES: Record<ErrorLevel, string> = {
|
|
debug: "bg-paper text-ink/50 border-ink/10",
|
|
info: "bg-sky-50 text-sky-700 border-sky-200",
|
|
warn: "bg-amber-50 text-amber-700 border-amber-200",
|
|
error: "bg-red-50 text-red-700 border-red-200",
|
|
fatal: "bg-red-100 text-red-800 border-red-300",
|
|
};
|
|
|
|
export function LevelBadge({ level }: { level: ErrorLevel }) {
|
|
return (
|
|
<span
|
|
className={`inline-flex items-center rounded border px-1.5 py-0.5 text-[11px] font-medium uppercase tracking-wide ${LEVEL_STYLES[level]}`}
|
|
>
|
|
{level}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
export function LoadingState({ label = "Loading…" }: { label?: string }) {
|
|
return (
|
|
<div className="flex items-center justify-center gap-2 py-12 text-sm text-ink/40">
|
|
<span className="h-3 w-3 animate-spin rounded-full border-2 border-ink/20 border-t-accent" />
|
|
{label}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function ErrorState({
|
|
message,
|
|
onRetry,
|
|
}: {
|
|
message: string;
|
|
onRetry?: () => void;
|
|
}) {
|
|
return (
|
|
<div className="rounded-lg border border-red-200 bg-red-50 p-5 text-sm text-red-700">
|
|
<p>{message}</p>
|
|
{onRetry && (
|
|
<button
|
|
onClick={onRetry}
|
|
className="mt-3 rounded border border-red-300 bg-white px-3 py-1.5 text-xs font-medium text-red-700 hover:bg-red-100"
|
|
>
|
|
Retry
|
|
</button>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function EmptyState({
|
|
title,
|
|
hint,
|
|
}: {
|
|
title: string;
|
|
hint?: string;
|
|
}) {
|
|
return (
|
|
<div className="rounded-lg border border-dashed border-ink/10 bg-white p-10 text-center">
|
|
<p className="text-sm font-medium text-ink/60">{title}</p>
|
|
{hint && <p className="mt-1 text-xs text-ink/40">{hint}</p>}
|
|
</div>
|
|
);
|
|
}
|