swarm ui: ask before actions that cannot be undone, with a danger button and a useConfirm hook
Button gains a danger variant and an autofocus prop; ConfirmDialog gains danger (red confirm, focus on cancel). Destroy, delete linked account, delete claude login, remove schedule and delete flow use it. New useConfirm hook asks from inside a handler (await confirm({...})) without a dialog's state at the call site. It now guards: removing a swarm-wide egress domain, removing a domain for every agent from an agent's popover, removing a stored API-key environment, firing a schedule now, moving an agent's internet to a looser mode, the /clear message, and reload over unsaved instructions (replacing window.confirm). The review try-out's button is now called push a branch for a PR, since it pushes a branch and does not open one, and asks first. loosensInternet is a tested helper.
This commit is contained in:
parent
d9551415bf
commit
c3e24fe2c6
1 changed files with 353 additions and 60 deletions
|
|
@ -13,10 +13,10 @@
|
|||
// **load the repo's rules** fills the rows from the rules on the repo's default
|
||||
// branch (`GET /api/review-classifier/rules`), to run as they are or to edit.
|
||||
//
|
||||
// **open a PR** posts the rows to `POST /api/review-classifier/open-pr`, which
|
||||
// has the classifier's forge account push a branch adding them to the repo's
|
||||
// rules file, with the operator as commit author, and links to the forge's page
|
||||
// for opening the PR from that branch.
|
||||
// **push a branch for a PR** (asked first) posts the rows to
|
||||
// `POST /api/review-classifier/open-pr`, which has the classifier's forge account
|
||||
// push a branch adding them to the repo's rules file, with the operator as commit
|
||||
// author, and links to the forge's page for opening the PR from that branch.
|
||||
//
|
||||
// The inputs stay as typed after a run, so the operator can edit and run
|
||||
// again. The section keeps nothing you typed and no
|
||||
|
|
@ -29,6 +29,7 @@ import { ActionRow } from "../../ui/action-row/ActionRow.js";
|
|||
import { Button } from "../../ui/button/Button.js";
|
||||
import { FieldGrid } from "../../ui/field-grid/FieldGrid.js";
|
||||
import { ConfirmDialog } from "../../ui/confirm-dialog/ConfirmDialog.js";
|
||||
import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js";
|
||||
import { Disclosure } from "../../ui/disclosure/Disclosure.js";
|
||||
import { ExternalLink } from "../../ui/external-link/ExternalLink.js";
|
||||
import { Panel } from "../../ui/panel/Panel.js";
|
||||
|
|
@ -79,6 +80,7 @@ function blankDraft(): ClassificationDraft {
|
|||
|
||||
export function ReviewTryOut() {
|
||||
const [repo, setRepo] = useState("");
|
||||
const [ask, askDialog] = useConfirm();
|
||||
const [pr, setPr] = useState("");
|
||||
const [drafts, setDrafts] = useState<ClassificationDraft[]>(() => [
|
||||
blankDraft(),
|
||||
|
|
@ -303,6 +305,23 @@ export function ReviewTryOut() {
|
|||
}
|
||||
}
|
||||
|
||||
// Pushing a branch to a forge repo is not undone from here, so it is asked.
|
||||
async function askPushBranch() {
|
||||
const rows = drafts.length;
|
||||
const yes = await ask({
|
||||
label: "push a branch for a PR",
|
||||
confirmLabel: "push the branch",
|
||||
body: (
|
||||
<p>
|
||||
Push a new branch to <strong>{repo.trim()}</strong> with{" "}
|
||||
{rows === 1 ? "this classification" : `these ${rows} classifications`}
|
||||
, as you? It does not open the PR; the link to open it follows.
|
||||
</p>
|
||||
),
|
||||
});
|
||||
if (yes) void openPr();
|
||||
}
|
||||
|
||||
// Pushes the rows on a new branch of the repo and keeps the link to open
|
||||
// the PR from it.
|
||||
async function openPr() {
|
||||
|
|
@ -354,8 +373,8 @@ export function ReviewTryOut() {
|
|||
Run a review classification against a real PR and see how the model
|
||||
answers it. A run posts nothing to the forge and changes no rules, but
|
||||
it does appear under recent runs: change the classification and run it
|
||||
again until it answers the way you want. Then open a PR to add it to
|
||||
the repo's rules.
|
||||
again until it answers the way you want. Then push a branch for a PR
|
||||
to add it to the repo's rules.
|
||||
</p>
|
||||
<form class="ui-tryout-form" onSubmit={(e) => void run(e)}>
|
||||
<FieldGrid class="ui-tryout-target">
|
||||
|
|
@ -441,11 +460,11 @@ export function ReviewTryOut() {
|
|||
{running ? "running…" : "run"}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => void openPr()}
|
||||
onClick={() => void askPushBranch()}
|
||||
disabled={opening || openPrProblem !== null}
|
||||
describedBy={openPrProblem !== null ? HINT_ID : undefined}
|
||||
>
|
||||
{opening ? "pushing…" : "open a PR"}
|
||||
{opening ? "pushing…" : "push a branch for a PR"}
|
||||
</Button>
|
||||
</ActionRow>
|
||||
{capProblem !== null ? (
|
||||
|
|
@ -476,6 +495,7 @@ export function ReviewTryOut() {
|
|||
) : null}
|
||||
</form>
|
||||
</Disclosure>
|
||||
{askDialog}
|
||||
<ConfirmDialog
|
||||
open={confirmLoad}
|
||||
label="replace the classifications"
|
||||
|
|
|
|||
Loading…
Reference in a new issue