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
|
|
@ -22,6 +22,7 @@ import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
|
|||
import { Badge } from "@hive/shared/badge.js";
|
||||
import { BadgePopover } from "../../ui/badge-popover/BadgePopover.js";
|
||||
import { Button } from "../../ui/button/Button.js";
|
||||
import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js";
|
||||
import { BadgeSkeleton } from "../../ui/skeleton/BadgeSkeleton.js";
|
||||
import { Hint } from "../../ui/hint/Hint.js";
|
||||
import { TextField } from "../../ui/text-field/TextField.js";
|
||||
|
|
@ -40,6 +41,7 @@ import {
|
|||
maxReposBody,
|
||||
parseMaxRepos,
|
||||
reposSummary,
|
||||
loosensInternet,
|
||||
type InternetMode,
|
||||
} from "./permissions.js";
|
||||
import "./AgentLimits.css";
|
||||
|
|
@ -257,9 +259,37 @@ export function AgentPermissions({
|
|||
|
||||
export function AgentInternet({ agent, g }: { agent: string; g: GrantState }) {
|
||||
const { grant, busy, saveError, loading, send } = g;
|
||||
const [confirm, confirmDialog] = useConfirm();
|
||||
if (grant === null) return loading;
|
||||
|
||||
const mode = internetMode(grant.unrestricted_internet, grant.internet_log);
|
||||
|
||||
// Letting more traffic out is asked first, and says what it lets out; going
|
||||
// back to a tighter mode is not.
|
||||
async function choose(next: InternetMode) {
|
||||
if (grant === null) return;
|
||||
if (loosensInternet(mode, next)) {
|
||||
const meaning = INTERNET_MODES.find(([m]) => m === next)?.[2] ?? "";
|
||||
const yes = await confirm({
|
||||
label: `set ${agent} internet to ${next}`,
|
||||
confirmLabel: `set ${next}`,
|
||||
danger: next === "unrestricted",
|
||||
body: (
|
||||
<p>
|
||||
Set <strong>{agent}</strong>'s internet to <strong>{next}</strong>?
|
||||
This will {meaning}.
|
||||
</p>
|
||||
),
|
||||
});
|
||||
if (!yes) return;
|
||||
}
|
||||
void send({
|
||||
method: "PUT",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(internetBody(grant.permissions, next)),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="ui-agent-limits">
|
||||
<BadgePopover
|
||||
|
|
@ -284,18 +314,7 @@ export function AgentInternet({ agent, g }: { agent: string; g: GrantState }) {
|
|||
value={label}
|
||||
title={`${meaning} for ${agent}`}
|
||||
disabled={busy}
|
||||
onClick={
|
||||
m === mode
|
||||
? undefined
|
||||
: () =>
|
||||
void send({
|
||||
method: "PUT",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(
|
||||
internetBody(grant.permissions, m),
|
||||
),
|
||||
})
|
||||
}
|
||||
onClick={m === mode ? undefined : () => void choose(m)}
|
||||
/>{" "}
|
||||
<Hint as="span">{meaning}</Hint>
|
||||
</li>
|
||||
|
|
@ -308,6 +327,7 @@ export function AgentInternet({ agent, g }: { agent: string; g: GrantState }) {
|
|||
/>
|
||||
) : null}
|
||||
</BadgePopover>
|
||||
{confirmDialog}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue