diff --git a/docs/buzz-help.md b/docs/buzz-help.md index da6c65bafa..780c517dd0 100644 --- a/docs/buzz-help.md +++ b/docs/buzz-help.md @@ -502,7 +502,9 @@ and are asked to sign in again in Buzz. workspace control and leaves no text in the message. A plugin's chat, such as a Nexus task, shows the workspace control when its plugin files it; until that chat's first message, **#** offers its workspaces too, and choosing one - files the chat right away. + files the chat right away. **Delete workspace**, in the workspace's **…** + menu, asks first: its chats move to **Chats**, and its instructions, folders + and agent list are cleared on all your devices. Your agents aren't deleted. - **Channel links.** Type **#** and part of a channel name to link a channel. The link is a chip: Backspace or Delete removes it whole, so to change it, remove it and pick again with **#**. diff --git a/src/bundled/channels/SoloWorkspaces.test.tsx b/src/bundled/channels/SoloWorkspaces.test.tsx index 695d57350e..6d65c047c1 100644 --- a/src/bundled/channels/SoloWorkspaces.test.tsx +++ b/src/bundled/channels/SoloWorkspaces.test.tsx @@ -249,13 +249,22 @@ it("keeps chats after project deletion and allows retry after a rejected deletio await user.click( await screen.findByRole("menuitem", { name: "Delete workspace" }), ); - expect(await screen.findByRole("alert")).toHaveTextContent( - "Deletion unavailable", + const dialog = await screen.findByRole("alertdialog", { + name: "Delete Work?", + }); + await user.click( + within(dialog).getByRole("button", { name: "Delete workspace" }), ); - expect(screen.getByRole("button", { name: "Work" })).toBeVisible(); - await user.click(screen.getByRole("button", { name: "Actions for Work" })); + // A failure stays in the dialog, so Delete workspace retries it there. + expect(await within(dialog).findByRole("alert")).toHaveTextContent( + "Workspace could not be deleted. Try again.", + ); + // The workspace stays, behind the dialog. + expect( + screen.getByRole("button", { name: "Work", hidden: true }), + ).toBeInTheDocument(); await user.click( - await screen.findByRole("menuitem", { name: "Delete workspace" }), + within(dialog).getByRole("button", { name: "Delete workspace" }), ); await waitFor(() => expect(screen.queryByRole("button", { name: "Work" })).toBeNull(), @@ -263,10 +272,66 @@ it("keeps chats after project deletion and allows retry after a rejected deletio await waitFor(() => expect(screen.getByRole("button", { name: "Planning" })).toBeVisible(), ); + expect(screen.queryByRole("alertdialog")).toBeNull(); + await waitFor(() => + expect(screen.getByRole("button", { name: "Chats" })).toHaveFocus(), + ); expect(h.saved().assignments).toEqual({}); owner.dispose(); }); +it("leaves the chat count out when deleting an empty workspace", async () => { + const h = fixture(); + const owner = h.store(); + const user = userEvent.setup(); + await owner.queries.ensure(); + render(h.view(owner.queries)); + await user.click( + await screen.findByRole("button", { name: "Actions for Work" }), + ); + await user.click( + await screen.findByRole("menuitem", { name: "Delete workspace" }), + ); + expect( + await screen.findByRole("alertdialog", { name: "Delete Work?" }), + ).toHaveAccessibleDescription( + "Its instructions, folders and agent list are cleared on all your devices, but your agents aren't deleted. It can't be undone.", + ); + owner.dispose(); +}); + +it("asks before deleting a workspace, and Cancel or Escape keeps it", async () => { + const h = fixture(); + const owner = h.store(); + const user = userEvent.setup(); + await owner.queries.ensure(); + await owner.queries.assign("chat", "work"); + render(h.view(owner.queries)); + for (const dismiss of ["cancel", "escape"]) { + await user.click(screen.getByRole("button", { name: "Actions for Work" })); + await user.click( + await screen.findByRole("menuitem", { name: "Delete workspace" }), + ); + const dialog = await screen.findByRole("alertdialog", { + name: "Delete Work?", + }); + expect(dialog).toHaveAccessibleDescription( + "1 chat moves to Chats. Its instructions, folders and agent list are cleared on all your devices, but your agents aren't deleted. It can't be undone.", + ); + const cancel = within(dialog).getByRole("button", { name: "Cancel" }); + await waitFor(() => expect(cancel).toHaveFocus()); + if (dismiss === "cancel") await user.click(cancel); + else await user.keyboard("{Escape}"); + await waitFor(() => expect(screen.queryByRole("alertdialog")).toBeNull()); + await waitFor(() => + expect(screen.getByRole("button", { name: "Work" })).toHaveFocus(), + ); + } + expect(h.remove).not.toHaveBeenCalled(); + expect(screen.getByRole("button", { name: "Planning" })).toBeVisible(); + owner.dispose(); +}); + it("starts an unfiled chat from the Chats heading plus without collapsing it", async () => { const h = fixture(); const owner = h.store(); @@ -662,7 +727,7 @@ it("opens the inline rename editor from the row actions menu", async () => { owner.dispose(); }); -it("prevents rename in a deleting workspace while other workspaces remain editable", async () => { +it("holds the delete confirmation open while it runs and allows rename after", async () => { const h = fixture(); Object.assign(h.details, { available: true, @@ -696,18 +761,24 @@ it("prevents rename in a deleting workspace while other workspaces remain editab await user.click( await screen.findByRole("menuitem", { name: "Delete workspace" }), ); - await waitFor(() => - expect(h.remove).toHaveBeenCalledWith("work", expect.any(AbortSignal)), + const dialog = await screen.findByRole("alertdialog", { + name: "Delete Work?", + }); + await user.click( + within(dialog).getByRole("button", { name: "Delete workspace" }), ); - await user.dblClick(screen.getByRole("button", { name: "Planning" })); - expect(screen.queryByRole("textbox", { name: "Chat name" })).toBeNull(); - await user.dblClick(screen.getByRole("button", { name: "Existing chat" })); await waitFor(() => - expect( - screen.getByRole("textbox", { name: "Chat name" }), - ).not.toHaveAttribute("readonly"), + expect(h.remove).toHaveBeenCalledWith("work", expect.any(AbortSignal)), ); + // While the delete runs, the dialog can't be dismissed. + expect( + within(dialog).getByRole("button", { name: "Cancel" }), + ).toBeDisabled(); await user.keyboard("{Escape}"); + expect(dialog).toBeVisible(); + // The pending dialog is modal, so no row behind it can start a rename. + expect(screen.queryByRole("button", { name: "Planning" })).toBeNull(); + expect(screen.queryByRole("textbox", { name: "Chat name" })).toBeNull(); } finally { release(); } diff --git a/src/bundled/channels/SoloWorkspaces.tsx b/src/bundled/channels/SoloWorkspaces.tsx index 775879852b..1b707f97ec 100644 --- a/src/bundled/channels/SoloWorkspaces.tsx +++ b/src/bundled/channels/SoloWorkspaces.tsx @@ -40,6 +40,7 @@ import { } from "react"; import type { RelaySession } from "../../features/relay/session"; import { readView, writeView } from "../../shared/view-state"; +import { AlertDialog } from "../../shared/design-system/ui/AlertDialog"; import { Button } from "../../shared/design-system/ui/Button"; import { NavigationSectionHeading } from "../../shared/design-system/ui/NavigationSection"; import { IconButton } from "../../shared/design-system/ui/IconButton"; @@ -72,6 +73,15 @@ import { SidebarRowRenderer } from "../../features/channel-navigation/SidebarRow const emptyRows: readonly RegisteredSidebarRows[] = []; +/** What deleting a workspace does, with its real chat count. */ +function deleteDescription(chatCount: number) { + const chats = + chatCount === 0 + ? "" + : `${chatCount} ${chatCount === 1 ? "chat moves" : "chats move"} to Chats. `; + return `${chats}Its instructions, folders and agent list are cleared on all your devices, but your agents aren't deleted. It can't be undone.`; +} + /** Presentation only. The caller supplies authorized, saved chats. */ export type ChatListItem = Readonly<{ id: string; @@ -204,7 +214,14 @@ export function SoloWorkspaces({ if (renaming && !chats.some((chat) => chat.id === renaming)) setRenaming(undefined); const [deleting, setDeleting] = useState(); + // The workspace whose Delete workspace is awaiting confirmation. + const [confirmDelete, setConfirmDelete] = useState<{ + id: string; + name: string; + }>(); + const cancelDelete = useRef(null); const [projectError, setProjectError] = useState(""); + const [deleteError, setDeleteError] = useState(""); const [readError, setReadError] = useState<{ id: string; message: string }>(); const [animate, setAnimate] = useState(false); const [rowFocus, setRowFocus] = useState(); @@ -257,6 +274,28 @@ export function SoloWorkspaces({ const assignmentFor = (item: ChatListItem) => dormantAssignments?.has(item.id) ? undefined : assigned[item.id]; const ids = new Set(groups.map((group) => group.id)); + // A workspace deleted elsewhere takes its confirmation with it. + if ( + confirmDelete && + deleting !== confirmDelete.id && + !ids.has(confirmDelete.id) + ) + setConfirmDelete(undefined); + const closeDelete = () => { + setDeleteError(""); + setConfirmDelete(undefined); + }; + const deleteProject = (id: string) => { + setDeleting(id); + setDeleteError(""); + void preferences + .removeSection(id) + .then(() => setConfirmDelete(undefined)) + // Removal errors are written for developers ("recipe", "Outbox"), so + // show one plain message; the dialog stays open for retry. + .catch(() => setDeleteError("Workspace could not be deleted. Try again.")) + .finally(() => setDeleting(undefined)); + }; const activeDraft = drafts.find((draft) => draft.selected); const draftProject = activeDraft ? ids.has(activeDraft.projectId ?? "") @@ -542,18 +581,10 @@ export function SoloWorkspaces({ renamingProject === project.id } onClick={() => { - setDeleting(project.id); - setProjectError(""); - void preferences - .removeSection(project.id) - .catch((error: unknown) => { - setProjectError( - error instanceof Error - ? error.message - : "Workspace could not be deleted. Try again.", - ); - }) - .finally(() => setDeleting(undefined)); + const { id, name } = project; + setDeleteError(""); + // Let the menu restore focus before opening confirmation. + requestAnimationFrame(() => setConfirmDelete({ id, name })); }} > Delete workspace @@ -900,6 +931,55 @@ export function SoloWorkspaces({ ))} + {confirmDelete && ( + group.id === confirmDelete.id)?.name ?? confirmDelete.name}?`} + description={deleteDescription( + projects.find((project) => project.id === confirmDelete.id)?.rows + .length ?? 0, + )} + pending={deleting === confirmDelete.id} + initialFocus={cancelDelete} + // Back to the workspace's heading, or to Chats, which now holds its + // chats, once the workspace is gone. + finalFocus={() => + document.querySelector( + `[data-solo-menu-id="project-${CSS.escape(confirmDelete.id)}"] button`, + ) ?? + document.querySelector( + '[data-solo-menu-id="project-"] button', + ) ?? + false + } + onClose={closeDelete} + actions={ + <> + + + + } + > + {deleteError && ( +

+ {deleteError} +

+ )} +
+ )} {settingsFor && (