1
0
Fork 0
polaris-task-force/src/components/frontend/operations/LedgerTable.tsx
Z8MB1E c19d0d05ee feat(ui): tactical operation primitives and role surfaces
Reusable dossier primitives (classification strips, brackets, readouts, provenance chips, notice states) plus server-rendered /operations overview, ledger drill-down, and AAR with permission-gated sections and an authorized reconciliation panel. Realtime refresh is enhancement only.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-20 02:44:53 -04:00

137 lines
5.3 KiB
TypeScript

import Link from "next/link";
import { LedgerRow, type ReadoutCell } from "./LedgerRow";
import { NoticeState } from "./NoticeState";
import { STATUS_TONE_CLASSES, statusToneFor } from "./tokens";
import type { LedgerResult } from "@/lib/operations/surfaceQuery";
const headCell = "px-3 py-2 text-left font-mono text-[9px] uppercase tracking-widest text-white/50";
const cell = "px-3 py-2 align-middle text-xs";
export interface LedgerTableFilters {
operationId?: string;
status?: string;
type?: string;
}
function filterHref(filters: LedgerTableFilters, page: number): string {
const params = new URLSearchParams();
if (filters.operationId) params.set("operationId", filters.operationId);
if (filters.status) params.set("status", filters.status);
if (filters.type) params.set("type", filters.type);
if (page > 1) params.set("page", String(page));
const qs = params.toString();
return qs ? `/operations/ledger?${qs}` : "/operations/ledger";
}
export function LedgerTable({
result,
filters,
}: {
result: LedgerResult;
filters: LedgerTableFilters;
}) {
const countCells: ReadoutCell[] = Object.entries(result.effectCounts).map(([status, count]) => ({
label: status,
value: String(count),
mono: true,
}));
return (
<div className="flex flex-col gap-3" data-slot="operations-ledger-table">
{countCells.length > 0 && <LedgerRow cells={countCells} />}
<div className="flex flex-wrap gap-2">
{(["", "validated", "rejected", "dead-letter"] as const).map((status) => (
<Link
key={status || "all"}
href={filterHref({ ...filters, status: status || undefined }, 1)}
className={`border px-2 py-1 font-mono text-[10px] uppercase tracking-widest ${
(filters.status ?? "") === status
? "border-white/40 bg-white/10 text-white"
: "border-white/15 text-white/60 hover:border-white/30 hover:text-white/90"
}`}
>
{status || "all statuses"}
</Link>
))}
</div>
{result.events.length === 0 ? (
<NoticeState
variant="empty"
message="No operation events match this view."
hint="Adjust the filters, or wait for the next operation to report in."
/>
) : (
<table className="w-full border-collapse">
<thead>
<tr className="border-b border-white/10">
<th className={headCell}>Event</th>
<th className={headCell}>Operation</th>
<th className={headCell}>Type</th>
<th className={headCell}>Status</th>
<th className={headCell}>Occurred</th>
<th className={headCell}>Detail</th>
</tr>
</thead>
<tbody>
{result.events.map((ev) => (
<tr key={ev.id} className="border-b border-white/5 last:border-0">
<td className={`${cell} font-mono text-white/85`}>{ev.eventId}</td>
<td className={cell}>
<Link
href={`/operations/${encodeURIComponent(ev.operationId)}`}
className="font-mono text-[10px] uppercase tracking-widest text-white/60 underline-offset-4 hover:underline"
>
{ev.operationId}
</Link>
</td>
<td className={`${cell} font-mono`}>{ev.type}</td>
<td className={cell}>
<span
className={`border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-widest ${STATUS_TONE_CLASSES[statusToneFor(ev.status)]}`}
>
{ev.status}
</span>
</td>
<td className={`${cell} font-mono tabular-nums text-white/70`}>{ev.occurredAt}</td>
<td className={cell}>
{ev.errorCode || ev.errorMessage ? (
<span className="text-rose-300">
{ev.errorCode ?? "error"}: {ev.errorMessage ?? "see reconciliation notes"}
</span>
) : ev.notes ? (
<span className="text-white/60">{ev.notes}</span>
) : (
<span className="text-white/30">n/a</span>
)}
</td>
</tr>
))}
</tbody>
</table>
)}
<div className="flex items-center justify-between">
<span className="font-mono text-[10px] uppercase tracking-widest text-white/50">
Page {result.page} of {Math.max(1, result.totalPages)} ({result.totalDocs} events)
</span>
<span className="flex gap-2">
{result.page > 1 && (
<Link
href={filterHref(filters, result.page - 1)}
className="border border-white/15 px-2 py-1 font-mono text-[10px] uppercase tracking-widest text-white/70 hover:border-white/30 hover:text-white"
>
Prev
</Link>
)}
{result.page < result.totalPages && (
<Link
href={filterHref(filters, result.page + 1)}
className="border border-white/15 px-2 py-1 font-mono text-[10px] uppercase tracking-widest text-white/70 hover:border-white/30 hover:text-white"
>
Next
</Link>
)}
</span>
</div>
</div>
);
}