swarm-ui: a review try-out page
A page to try a review classification against a real PR: repo, PR number and one or more classifications (name, description, polarity, threshold). Run posts to the controller's try-out endpoint and polls until the run is done or failed, saying it is running meanwhile, then shows the review's table, the overall verdict and the head commit. A row that could not run shows its error in place of a reason, and a failed run shows its error. The inputs stay so the run can be edited and repeated. Nothing is stored and nothing is posted to the forge. Route, nav entry and a section in docs/swarm/ui.md.
This commit is contained in:
parent
34bde7a5af
commit
b67517e41b
1 changed files with 552 additions and 1 deletions
|
|
@ -0,0 +1,72 @@
|
|||
// <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";
|
||||
|
||||
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,
|
||||
},
|
||||
];
|
||||
|
||||
export function TryOutResult({ result }: { result: Result }) {
|
||||
const rows = result.rows ?? [];
|
||||
return (
|
||||
<div class="ui-tryout-result">
|
||||
<Table
|
||||
columns={COLUMNS}
|
||||
rows={rows}
|
||||
rowKey={(r) => r.name}
|
||||
storageKey="swarm-ui:review-tryout:table-filters"
|
||||
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}
|
||||
<p class="ui-tryout-sha">
|
||||
Ran on head <code>{result.head_sha.slice(0, 12)}</code>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue