Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/src/pages/review-tryout/TryOutResult.tsx
iris 5193a101a6 swarm-ui: a review runs page lists the review classifier's recent runs
One card per run, newest first, from GET /api/review-classifier/runs: repo,
PR, head commit, trigger, when, how long, how many classifications and the
outcome as a badge. A card opens to the try-out's result table, the overall
verdict, the reason and the posted review's link. TryOutResult takes the
answer it shows rather than a whole try-out result, and its styles move to
their own file.
2026-10-12 23:21:38 +02:00

91 lines
3 KiB
TypeScript

// <TryOutResult> — a finished try-out: one row per classification, the
// overall verdict under them, and the head commit the run read. The columns
// are the review's own table (`docs/swarm/review-classifier.md`); no token
// counts, cache counts or cost, here or anywhere in the UI.
import { Badge } from "@hive/shared/badge.js";
import { Table, type TableColumn } from "../../ui/table/Table.js";
import type { TryOutResult as Result, TryOutRow } from "./TryOutTypes.js";
import "./TryOutResult.css";
const VERDICT_LABEL: Record<TryOutRow["verdict"], string> = {
match: "match",
"no-match": "no match",
"not-applicable": "not applicable",
};
const COLUMNS: TableColumn<TryOutRow>[] = [
{ key: "name", header: "classification", render: (r) => r.name },
{ key: "polarity", header: "polarity", render: (r) => r.polarity },
{
key: "verdict",
header: "verdict",
render: (r) => (r.error ? "—" : VERDICT_LABEL[r.verdict]),
},
{
key: "certainty",
header: "certainty",
render: (r) => (r.error ? "—" : r.certainty),
},
{ key: "threshold", header: "threshold", render: (r) => r.threshold },
{
key: "counted",
header: "counted",
// A counted row shows whether it passed its polarity; one below its
// threshold does not count and has no pass or fail.
render: (r) =>
r.error ? "—" : r.counted ? (r.passed ? "yes ✅" : "yes ❌") : "no",
},
{
key: "reason",
header: "reason",
cellClass: "ui-table-prose",
// A row that could not run says why where the reason would be.
render: (r) =>
r.error ? <span class="ui-tryout-row-error">{r.error}</span> : r.reason,
},
];
/** What the table needs of a run: the try-out's answer, or a listed run's. The
* head commit is absent for a run that never read one. */
export type TryOutAnswer = Pick<Result, "rows" | "overall"> & {
head_sha?: string;
};
export function TryOutResult({
result,
filterKey = "swarm-ui:review-tryout:table-filters",
}: {
result: TryOutAnswer;
/** Where the column filters are remembered; a page showing several tables
* keeps them apart from the try-out's. */
filterKey?: string;
}) {
const rows = result.rows ?? [];
return (
<div class="ui-tryout-result">
<Table
columns={COLUMNS}
rows={rows}
// By position: two classifications may share a name, and a shared key
// would let one result render over the other.
rowKey={(r) => String(rows.indexOf(r))}
storageKey={filterKey}
emptyMessage="the run returned no classifications"
/>
{result.overall ? (
<p class="ui-tryout-overall">
<strong>Overall: </strong>
<Badge
tone={result.overall === "approve" ? "positive" : "negative"}
value={result.overall === "approve" ? "approve" : "request changes"}
/>
</p>
) : null}
{result.head_sha ? (
<p class="ui-tryout-sha">
Ran on head <code>{result.head_sha.slice(0, 12)}</code>
</p>
) : null}
</div>
);
}