diff --git a/docs/4-implementation/swarm/review-classifier.md b/docs/4-implementation/swarm/review-classifier.md index 1fc51f1e5..9a129a8b4 100644 --- a/docs/4-implementation/swarm/review-classifier.md +++ b/docs/4-implementation/swarm/review-classifier.md @@ -350,8 +350,8 @@ collaborator: allowlist, the account counts only once it's on that list, and read access is then enough for reviews. -The try-out's **open a PR** pushes a branch to the repo itself, so it -needs **write** whatever the branch protection says. +The try-out's **push a branch for a PR** button pushes a branch to the repo itself, +so it needs **write** whatever the branch protection says. The repo also needs a rules file on its default branch (see [Repo configuration](#repo-configuration)). Without one, a request posts a @@ -596,11 +596,12 @@ since a run also works on a merged or closed PR. Two routes feed them: Every error is problem+json with the reason in `detail`. -When it's ready, **open a PR** (`POST /api/review-classifier/open-pr`, with -the repo and the classifications) has the service account push a branch that -adds the classifications to the repo's rules, with you, the swarm UI user, as -commit author. The page then links you to the forge's compare page for that -branch, where you log in as usual and open the PR yourself. +When it's ready, **push a branch for a PR** +(`POST /api/review-classifier/open-pr`, with the repo and the classifications) +has the service account push a branch that adds the classifications to the repo's +rules, with you, the swarm UI user, as commit author. The page then links you to +the forge's compare page for that branch, where you log in as usual and open the +PR yourself. - **The branch** is `review-classifier/-<8 hex digits>`, made from the default branch's head with one commit, through the forge's contents API. diff --git a/docs/4-implementation/web-ui/swarm-ui.md b/docs/4-implementation/web-ui/swarm-ui.md index 070d3d754..ee086ded7 100644 --- a/docs/4-implementation/web-ui/swarm-ui.md +++ b/docs/4-implementation/web-ui/swarm-ui.md @@ -28,6 +28,15 @@ scrolls sideways. Nothing makes the page itself scroll sideways at 360px. A dialog grows to fit its content, up to 64em or nine tenths of the window, whichever is smaller; short confirm dialogs stay short. +An action that can't be undone asks first, in a dialog with a red confirm button and +the focus on **cancel**, so a stray **Enter** doesn't confirm it. These ask: +destroying an agent, deleting a linked account or a claude login, removing a schedule, +a flow or a stored API-key environment, **fire now** on a schedule, removing an +allowed domain (swarm-wide, or for every agent from an agent's popover), moving an +agent's internet to a looser mode, sending `/clear` as a message, reloading over +unsaved instructions, and **push a branch for a PR** on the review try-out. A page +asks from inside a handler with the `useConfirm` hook, with no dialog state of its own. + | route | what | | ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `/` | the start page: the swarm's name over a digital-rain backdrop with the slug (`hyperhive / we are the wired`, its shaded gradients pulsing in a wave unless reduced motion is on) at the foot, plus a paperclip offering to set up an agent while no `ruth` exists, or her hive declares her destroyed (it opens the create form with `ruth` filled in); the swarm name in the header links here | @@ -338,11 +347,11 @@ again. The page saves no classification and no result, and a run posts nothing to the forge; like every table in the UI, the result table remembers its column filters in the browser. It shows no token counts, cache counts or cost. -When a classification answers the way you want, **open a PR** proposes the -classifications on the page to the repo. The classifier's forge account pushes -a branch that adds them to the repo's rules file, with you as the commit's -author, and the page links to the forge's page for opening the PR from that -branch, where you log in as usual. A classification named like one the file +When a classification answers the way you want, **push a branch for a PR** (it asks +first) proposes the classifications on the page to the repo. The classifier's forge +account pushes a branch that adds them to the repo's rules file, with you as the +commit's author, and the page links to the forge's page for opening the PR from +that branch, where you log in as usual. A classification named like one the file already holds replaces it, and the file's other rules stay. It needs no PR number. If the forge has no account of yours yet, log in to the forge once first. If the classifier's account may not push to the repo, the page says so: diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentClaudeLogin.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentClaudeLogin.tsx index 5c66781ae..67797cc51 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentClaudeLogin.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentClaudeLogin.tsx @@ -125,6 +125,7 @@ export function AgentClaudeLogin({ agent }: { agent: string }) { open={confirming} label={`delete the stored claude login for ${agent}`} confirmLabel={deleting ? "deleting…" : "delete login"} + danger confirmDisabled={deleting} onCancel={() => setConfirming(false)} onConfirm={() => void confirmDelete()} diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentInstructions.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentInstructions.tsx index 909e15dc7..9a401f181 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentInstructions.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentInstructions.tsx @@ -18,6 +18,7 @@ import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js"; import { Badge } from "@hive/shared/badge.js"; import { ActionRow } from "../../ui/action-row/ActionRow.js"; import { Button } from "../../ui/button/Button.js"; +import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js"; import { Preformatted } from "../../ui/preformatted/Preformatted.js"; import { Dialog } from "../../ui/dialog/Dialog.js"; import { Panel } from "../../ui/panel/Panel.js"; @@ -113,6 +114,22 @@ function InstructionsForm({ const [busy, setBusy] = useState(false); const [problem, setProblem] = useState(null); const [saved, setSaved] = useState(false); + const [confirm, confirmDialog] = useConfirm(); + + // Loading the agent's file drops what is typed, so unsaved edits ask first. + async function askReload() { + if ( + !dirty || + (await confirm({ + label: "drop unsaved changes", + confirmLabel: "drop and reload", + danger: true, + body:

Drop your unsaved changes and load {agent}'s file?

, + })) + ) { + reload(); + } + } useEffect(() => { let cancelled = false; @@ -294,24 +311,14 @@ function InstructionsForm({ > undo my changes - ) : null} + {confirmDialog} ); } diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx index a10d178fa..241d7263b 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx @@ -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: ( +

+ Set {agent}'s internet to {next}? + This will {meaning}. +

+ ), + }); + if (!yes) return; + } + void send({ + method: "PUT", + headers: { "content-type": "application/json" }, + body: JSON.stringify(internetBody(grant.permissions, next)), + }); + } + return (
- void send({ - method: "PUT", - headers: { "content-type": "application/json" }, - body: JSON.stringify( - internetBody(grant.permissions, m), - ), - }) - } + onClick={m === mode ? undefined : () => void choose(m)} />{" "} {meaning} @@ -308,6 +327,7 @@ export function AgentInternet({ agent, g }: { agent: string; g: GrantState }) { /> ) : null} + {confirmDialog}
); } diff --git a/frontend/packages/swarm-ui/src/agent/detail/AllowedDomains.tsx b/frontend/packages/swarm-ui/src/agent/detail/AllowedDomains.tsx index c3810a235..55f1cd4e4 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AllowedDomains.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AllowedDomains.tsx @@ -27,6 +27,7 @@ import { Badge } from "@hive/shared/badge.js"; import { ActionRow } from "../../ui/action-row/ActionRow.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 { FormStack } from "../../ui/form-stack/FormStack.js"; import { CheckboxField } from "../../ui/checkbox-field/CheckboxField.js"; import { Dialog } from "../../ui/dialog/Dialog.js"; @@ -66,6 +67,30 @@ function groupHelp(source: EntryGroup["source"], agent: string): string { export function AllowedDomains({ agent }: { agent: string }) { const { entries, error, busy, remove, refetch } = useAllowedDomains(); const [adding, setAdding] = useState(false); + const [confirm, confirmDialog] = useConfirm(); + + // A removal that applies to every agent asks first; one for this agent only + // is easy to add back. + async function removeEntry(e: Parameters[0]) { + if ( + e.agent === undefined && + !(await confirm({ + label: `stop allowing ${e.domain} for every agent`, + confirmLabel: "stop allowing", + danger: true, + body: ( +

+ Stop allowing {e.domain} for{" "} + every agent? Agents lose access to it through the + proxy, not just {agent}. +

+ ), + })) + ) { + return; + } + void remove(e); + } // A list already loaded stays under a failed refetch, so a change that // worked is not hidden by a read that did not. @@ -114,7 +139,7 @@ export function AllowedDomains({ agent }: { agent: string }) { e.agent === undefined ? "every agent" : agent }`} disabled={busy} - onClick={() => void remove(e)} + onClick={() => void removeEntry(e)} /> )} @@ -147,6 +172,7 @@ export function AllowedDomains({ agent }: { agent: string }) { /> ) : null} + {confirmDialog} ); } diff --git a/frontend/packages/swarm-ui/src/agent/detail/LinkedAccounts.tsx b/frontend/packages/swarm-ui/src/agent/detail/LinkedAccounts.tsx index d5b8f14e9..248062575 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/LinkedAccounts.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/LinkedAccounts.tsx @@ -107,6 +107,7 @@ export function LinkedAccounts({ onCancel={() => setDeleteTarget(null)} onConfirm={() => void confirmDelete()} confirmLabel="delete" + danger confirmDisabled={deleting} > {deleteTarget ? ( diff --git a/frontend/packages/swarm-ui/src/agent/detail/permissions.ts b/frontend/packages/swarm-ui/src/agent/detail/permissions.ts index 44577204b..c965d94d4 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/permissions.ts +++ b/frontend/packages/swarm-ui/src/agent/detail/permissions.ts @@ -25,6 +25,17 @@ export function grantSummary(stored: string[] | undefined): string { /** The three modes of an agent's internet access. */ export type InternetMode = "unrestricted" | "log" | "restricted"; +const INTERNET_OPENNESS: Record = { + restricted: 0, + log: 1, + unrestricted: 2, +}; + +/** Whether a change of mode lets more traffic through: the one that is asked first. */ +export function loosensInternet(from: InternetMode, to: InternetMode): boolean { + return INTERNET_OPENNESS[to] > INTERNET_OPENNESS[from]; +} + /** * How the panel reads the stored `unrestricted_internet` and `internet_log`. * An absent flag counts as on, and says "legacy" because the swarm never set diff --git a/frontend/packages/swarm-ui/src/agent/roster/AgentActions.tsx b/frontend/packages/swarm-ui/src/agent/roster/AgentActions.tsx index 101c15aea..de865c112 100644 --- a/frontend/packages/swarm-ui/src/agent/roster/AgentActions.tsx +++ b/frontend/packages/swarm-ui/src/agent/roster/AgentActions.tsx @@ -325,6 +325,7 @@ export function useAgentActions( onCancel={() => setDestroyTarget(null)} onConfirm={() => destroyTarget && void destroyAgent(destroyTarget)} confirmLabel="destroy" + danger > {destroyTarget ? (

diff --git a/frontend/packages/swarm-ui/src/agent/terminal/AgentInputForm.tsx b/frontend/packages/swarm-ui/src/agent/terminal/AgentInputForm.tsx index 0ca26e2df..8edb6dc40 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/AgentInputForm.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/AgentInputForm.tsx @@ -34,6 +34,7 @@ import { moveSelection, type AgentCommand, } from "./command-menu.js"; +import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js"; import { useAgentCommands } from "./useAgentCommands.js"; import "./AgentInputForm.css"; @@ -42,6 +43,7 @@ export function AgentInputForm({ agentName }: { agentName: string }) { const [selected, setSelected] = useState(0); const [closed, setClosed] = useState(false); const { state, submitting, run } = useSubmit(); + const [confirm, confirmDialog] = useConfirm(); const commands = useAgentCommands(agentName); const query = menuQuery(body); @@ -57,10 +59,27 @@ export function AgentInputForm({ agentName }: { agentName: string }) { setClosed(false); }, [body]); - function submit(e: Event) { + async function submit(e: Event) { e.preventDefault(); const base = `/api/agents/${encodeURIComponent(agentName)}`; const route = controlRoute(body, commands); + // /clear drops the agent's conversation, so it is asked first. + if ( + route === "new-session" && + !(await confirm({ + label: "start a new session", + confirmLabel: "start a new session", + danger: true, + body: ( +

+ Start a new session for {agentName}? Its current + conversation is dropped on its next turn. +

+ ), + })) + ) { + return; + } void run( () => route @@ -142,6 +161,7 @@ export function AgentInputForm({ agentName }: { agentName: string }) { {submitting ? : } + {confirmDialog} ); } diff --git a/frontend/packages/swarm-ui/src/pages/ComponentsPage.tsx b/frontend/packages/swarm-ui/src/pages/ComponentsPage.tsx index c5024a27c..49076d170 100644 --- a/frontend/packages/swarm-ui/src/pages/ComponentsPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/ComponentsPage.tsx @@ -50,6 +50,7 @@ import { Preformatted } from "../ui/preformatted/Preformatted.js"; import { SectionHeading } from "../ui/section-heading/SectionHeading.js"; import { Toolbar } from "../ui/toolbar/Toolbar.js"; import { ConfirmDialog } from "../ui/confirm-dialog/ConfirmDialog.js"; +import { useConfirm } from "../ui/confirm-dialog/useConfirm.js"; import { Popover } from "../ui/popover/Popover.js"; import { Badge, type BadgeTone } from "@hive/shared/badge.js"; import { GearIcon } from "@hive/shared/icons.js"; @@ -131,7 +132,7 @@ const SELECT_OPTIONS: SelectOption[] = [ { value: "beta", label: "beta" }, ]; -const BUTTON_VARIANTS: ButtonVariant[] = ["primary", "default"]; +const BUTTON_VARIANTS: ButtonVariant[] = ["primary", "default", "danger"]; const BADGE_TONES: BadgeTone[] = [ "neutral", "positive", @@ -396,10 +397,46 @@ function FilterableViewSample() { ); } -function ConfirmDialogSample() { - const [open, setOpen] = useState(false); +// `useConfirm`: ask in the middle of a handler, without a dialog's state. +function UseConfirmSample() { + const [confirm, dialog] = useConfirm(); + const [answer, setAnswer] = useState("not asked yet"); + async function ask() { + const yes = await confirm({ + label: "sample question", + confirmLabel: "go ahead", + body:

Awaited in the click handler: it resolves true or false.

, + }); + setAnswer(yes ? "confirmed" : "cancelled"); + } return ( <> + + answer: {answer} + {dialog} + + ); +} + +function ConfirmDialogSample() { + const [open, setOpen] = useState(false); + const [dangerOpen, setDangerOpen] = useState(false); + return ( + <> + + setDangerOpen(false)} + onConfirm={() => setDangerOpen(false)} + confirmLabel="delete" + danger + > +

+ danger makes the confirm button red and starts the focus + on cancel, for an action that cannot be taken back. +

+
+ + +
diff --git a/frontend/packages/swarm-ui/src/pages/LinkBackendEnvForm.tsx b/frontend/packages/swarm-ui/src/pages/LinkBackendEnvForm.tsx index 16444ea30..f0d0c985a 100644 --- a/frontend/packages/swarm-ui/src/pages/LinkBackendEnvForm.tsx +++ b/frontend/packages/swarm-ui/src/pages/LinkBackendEnvForm.tsx @@ -13,6 +13,7 @@ import { TextAreaField } from "../ui/text-area-field/TextAreaField.js"; import { Button } from "../ui/button/Button.js"; import { FormStack } from "../ui/form-stack/FormStack.js"; import { FormResult } from "../ui/submit/FormResult.js"; +import { useConfirm } from "../ui/confirm-dialog/useConfirm.js"; import { useSubmit } from "../ui/submit/useSubmit.js"; // A swarm-controller without the route answers 404 with no problem body. @@ -31,6 +32,23 @@ export function LinkBackendEnvForm({ const [env, setEnv] = useState(""); // The success line is what the request did, so it is the done value. const { state, submitting: busy, run } = useSubmit(); + const [confirm, confirmDialog] = useConfirm(); + + async function removeEnv() { + const yes = await confirm({ + label: "remove the API-key environment", + confirmLabel: "remove", + danger: true, + body: ( +

+ Remove the stored API-key environment for {agent}? + The stored text cannot be read back, so it cannot be restored; paste + it again to set it. +

+ ), + }); + if (yes) send("DELETE", "removed the API-key environment for"); + } function send(method: "PUT" | "DELETE", done: string) { void run( @@ -89,11 +107,7 @@ export function LinkBackendEnvForm({ - @@ -106,6 +120,7 @@ export function LinkBackendEnvForm({ )} failed="failed to update the API-key environment" /> + {confirmDialog} ); } diff --git a/frontend/packages/swarm-ui/src/pages/notifications/FlowEditorPage.tsx b/frontend/packages/swarm-ui/src/pages/notifications/FlowEditorPage.tsx index 78562910f..e38c49d28 100644 --- a/frontend/packages/swarm-ui/src/pages/notifications/FlowEditorPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/notifications/FlowEditorPage.tsx @@ -416,6 +416,7 @@ export function FlowEditorPage({ open={confirmDelete} label="delete this flow" confirmLabel="delete" + danger onCancel={() => setConfirmDelete(false)} onConfirm={() => void onDelete()} > diff --git a/frontend/packages/swarm-ui/src/pages/review-tryout/ReviewTryOut.tsx b/frontend/packages/swarm-ui/src/pages/review-tryout/ReviewTryOut.tsx index ebd54eb95..205c8707e 100644 --- a/frontend/packages/swarm-ui/src/pages/review-tryout/ReviewTryOut.tsx +++ b/frontend/packages/swarm-ui/src/pages/review-tryout/ReviewTryOut.tsx @@ -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(() => [ 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: ( +

+ Push a new branch to {repo.trim()} with{" "} + {rows === 1 ? "this classification" : `these ${rows} classifications`} + , as you? It does not open the PR; the link to open it follows. +

+ ), + }); + 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.

void run(e)}> @@ -441,11 +460,11 @@ export function ReviewTryOut() { {running ? "running…" : "run"} {capProblem !== null ? ( @@ -476,6 +495,7 @@ export function ReviewTryOut() { ) : null} + {askDialog} >(new Set()); const [removeTarget, setRemoveTarget] = useState(null); + const [confirm, fireDialog] = useConfirm(); const [actionError, setActionError] = useState(null); function markPending(id: string, on: boolean) { @@ -120,7 +122,20 @@ function SchedulesBody() { } } - function fireNow(s: Schedule) { + async function fireNow(s: Schedule) { + const repeats = s.interval_seconds !== null; + const yes = await confirm({ + label: "fire schedule now", + confirmLabel: "fire now", + body: ( +

+ Fire {s.name} now? It sends its message to{" "} + {s.agents.join(", ")} at once, and its start moves to this moment + {repeats ? ", so it repeats from now on" : ""}. That cannot be undone. +

+ ), + }); + if (!yes) return; return act(s.id, () => fetch(`/api/schedules/${encodeURIComponent(s.id)}`, { method: "PATCH", @@ -232,10 +247,12 @@ function SchedulesBody() { } /> ) : null} + {fireDialog} setRemoveTarget(null)} onConfirm={confirmRemove} > diff --git a/frontend/packages/swarm-ui/src/pages/swarm/EgressCard.tsx b/frontend/packages/swarm-ui/src/pages/swarm/EgressCard.tsx index ca42909a0..b96d253f1 100644 --- a/frontend/packages/swarm-ui/src/pages/swarm/EgressCard.tsx +++ b/frontend/packages/swarm-ui/src/pages/swarm/EgressCard.tsx @@ -22,6 +22,7 @@ import { useDeniedDomains, } from "../../agent/detail/useAllowedDomains.js"; import { Button } from "../../ui/button/Button.js"; +import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js"; import { LazyDisclosure } from "../../ui/disclosure/LazyDisclosure.js"; import { Dialog } from "../../ui/dialog/Dialog.js"; import { Hint } from "../../ui/hint/Hint.js"; @@ -46,6 +47,27 @@ function DomainSection({ }) { const { entries, behind, error, busy, remove, refetch } = list; const [adding, setAdding] = useState(false); + const [confirm, confirmDialog] = useConfirm(); + + async function removeEntry(e: Parameters[0]) { + const verb = kind === "deny" ? "Stop denying" : "Stop allowing"; + if ( + !(await confirm({ + label: `${verb.toLowerCase()} ${e.domain} swarm-wide`, + confirmLabel: "remove", + danger: true, + body: ( +

+ {verb} {e.domain} for every agent on + the swarm? +

+ ), + })) + ) { + return; + } + void remove(e); + } // A list already loaded stays under a failed refetch, so a change that // worked is not hidden by a read that did not. @@ -94,7 +116,7 @@ function DomainSection({ @@ -121,6 +143,7 @@ function DomainSection({ /> ) : null} + {confirmDialog} )}
diff --git a/frontend/packages/swarm-ui/src/ui/button/Button.css b/frontend/packages/swarm-ui/src/ui/button/Button.css index 1114b7bdb..9ce2d7383 100644 --- a/frontend/packages/swarm-ui/src/ui/button/Button.css +++ b/frontend/packages/swarm-ui/src/ui/button/Button.css @@ -15,6 +15,11 @@ color: var(--fg); border: none; } +.ui-button-danger { + background: color-mix(in srgb, var(--red) 14%, var(--bg-elev)); + color: var(--red); + border: 1px solid var(--red); +} .ui-button-default { background: var(--bg-elev); color: var(--fg); diff --git a/frontend/packages/swarm-ui/src/ui/button/Button.tsx b/frontend/packages/swarm-ui/src/ui/button/Button.tsx index 7b5424dc4..42b0f2cf0 100644 --- a/frontend/packages/swarm-ui/src/ui/button/Button.tsx +++ b/frontend/packages/swarm-ui/src/ui/button/Button.tsx @@ -1,14 +1,13 @@ // +