Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/buzz-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 **#**.
Expand Down
99 changes: 85 additions & 14 deletions src/bundled/channels/SoloWorkspaces.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,24 +249,89 @@ 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(),
);
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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down
104 changes: 92 additions & 12 deletions src/bundled/channels/SoloWorkspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -204,7 +214,14 @@ export function SoloWorkspaces({
if (renaming && !chats.some((chat) => chat.id === renaming))
setRenaming(undefined);
const [deleting, setDeleting] = useState<string>();
// The workspace whose Delete workspace is awaiting confirmation.
const [confirmDelete, setConfirmDelete] = useState<{
id: string;
name: string;
}>();
const cancelDelete = useRef<HTMLButtonElement>(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<string>();
Expand Down Expand Up @@ -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 ?? "")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -900,6 +931,55 @@ export function SoloWorkspaces({
</Button>
</div>
))}
{confirmDelete && (
<AlertDialog
// The current name, in case it's renamed on another device meanwhile.
title={`Delete ${groups.find((group) => 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<HTMLElement>(
`[data-solo-menu-id="project-${CSS.escape(confirmDelete.id)}"] button`,
) ??
document.querySelector<HTMLElement>(
'[data-solo-menu-id="project-"] button',
) ??
false
}
onClose={closeDelete}
actions={
<>
<Button
ref={cancelDelete}
disabled={deleting === confirmDelete.id}
onClick={closeDelete}
>
Cancel
</Button>
<Button
variant="destructive"
loading={deleting === confirmDelete.id}
disabled={!preferences.sectionRemovalWritable}
onClick={() => deleteProject(confirmDelete.id)}
>
Delete workspace
</Button>
</>
}
>
{deleteError && (
<p role="alert" className="m-0 text-body-sm text-danger">
{deleteError}
</p>
)}
</AlertDialog>
)}
{settingsFor && (
<WorkspaceSettings
key={settingsFor.id}
Expand Down
Loading