Compare commits

...
Author SHA1 Message Date
Julius Marminge 4c49b8a514 Block deletion of projects that still have threads
- Show warning toast when attempting to delete a non-empty project
- Simplify confirmation copy to emphasize irreversible deletion
- Remove thread/worktree/session cleanup from project delete flow
2026-02-15 16:20:15 -08:00
Julius Marminge f6a0b67e89 Confirm project deletion and clean up orphaned worktrees
- Prompt before deleting a project with thread and linked worktree counts
- Best-effort remove orphaned worktrees when project threads are deleted
- Show toast with error details if project deletion fails
2026-02-15 16:20:15 -08:00
Julius Marminge ebac75593e Delete projects from the sidebar context menu
- Add project right-click Delete action in `Sidebar` and clean up sessions/terminals before removal
- Add `DELETE_PROJECT` reducer action to remove the project, its threads, and reset active thread
- Add reducer test coverage for project deletion behavior
2026-02-15 16:19:17 -08:00
3 changed files with 118 additions and 0 deletions

No files matched your search

+53
View File
@@ -17,6 +17,7 @@ import {
import { useNativeApi } from "../hooks/useNativeApi";
import { gitRemoveWorktreeMutationOptions } from "../lib/gitReactQuery";
import { serverConfigQueryOptions } from "../lib/serverReactQuery";
import { toastManager } from "./ui/toast";
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
const THEME_CYCLE = { system: "light", light: "dark", dark: "system" } as const;
@@ -333,6 +334,51 @@ export default function Sidebar() {
[api, dispatch, removeWorktreeMutation, state.projects, state.threads],
);
const handleProjectContextMenu = useCallback(
async (projectId: string, position: { x: number; y: number }) => {
if (!api) return;
const clicked = await api.contextMenu.show([{ id: "delete", label: "Delete" }], position);
if (clicked !== "delete") return;
const project = state.projects.find((entry) => entry.id === projectId);
if (!project) return;
const projectThreads = state.threads.filter((thread) => thread.projectId === projectId);
if (projectThreads.length > 0) {
toastManager.add({
type: "warning",
title: "Project is not empty",
description: "Delete all threads in this project before deleting it.",
});
return;
}
const confirmed = await api.dialogs.confirm(
[`Delete project "${project.name}"?`, "This action cannot be undone."].join("\n"),
);
if (!confirmed) return;
if (isElectron) {
try {
await api.projects.remove({ id: projectId });
} catch (error) {
const message =
error instanceof Error ? error.message : "Unknown error deleting project.";
console.error("Failed to remove project", { projectId, error });
toastManager.add({
type: "error",
title: `Failed to delete "${project.name}"`,
description: message,
});
return;
}
}
dispatch({ type: "DELETE_PROJECT", projectId });
},
[api, dispatch, state.projects, state.threads],
);
useEffect(() => {
const onWindowKeyDown = (event: KeyboardEvent) => {
if (!isChatNewShortcut(event, keybindings)) return;
@@ -413,6 +459,13 @@ export default function Sidebar() {
type="button"
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors duration-150 hover:bg-accent"
onClick={() => dispatch({ type: "TOGGLE_PROJECT", projectId: project.id })}
onContextMenu={(e) => {
e.preventDefault();
void handleProjectContextMenu(project.id, {
x: e.clientX,
y: e.clientY,
});
}}
>
<span className="text-[10px] text-muted-foreground/70">
{project.expanded ? "▼" : "▶"}
+45
View File
@@ -486,6 +486,51 @@ describe("store reducer thread continuity", () => {
expect(next.activeThreadId).toBe("thread-a");
});
it("deletes a project and all of its threads", () => {
const state: AppState = {
projects: [
{
id: "project-1",
name: "One",
cwd: "/tmp/one",
model: "gpt-5.3-codex",
expanded: true,
},
{
id: "project-2",
name: "Two",
cwd: "/tmp/two",
model: "gpt-5.3-codex",
expanded: true,
},
],
threads: [
makeThread({
id: "thread-a",
projectId: "project-1",
}),
makeThread({
id: "thread-b",
projectId: "project-2",
}),
],
activeThreadId: "thread-a",
runtimeMode: "full-access",
diffOpen: false,
};
const next = reducer(state, {
type: "DELETE_PROJECT",
projectId: "project-1",
});
expect(next.projects).toHaveLength(1);
expect(next.projects[0]?.id).toBe("project-2");
expect(next.threads).toHaveLength(1);
expect(next.threads[0]?.id).toBe("thread-b");
expect(next.activeThreadId).toBe("thread-b");
});
it("marks the active thread as visited when selected", () => {
const state = makeState(
makeThread({
+20
View File
@@ -28,6 +28,7 @@ type Action =
| { type: "ADD_PROJECT"; project: Project }
| { type: "SYNC_PROJECTS"; projects: Project[] }
| { type: "TOGGLE_PROJECT"; projectId: string }
| { type: "DELETE_PROJECT"; projectId: string }
| { type: "ADD_THREAD"; thread: Thread }
| { type: "SET_ACTIVE_THREAD"; threadId: string }
| { type: "TOGGLE_THREAD_TERMINAL"; threadId: string }
@@ -473,6 +474,25 @@ export function reducer(state: AppState, action: Action): AppState {
),
};
case "DELETE_PROJECT": {
const projects = state.projects.filter((project) => project.id !== action.projectId);
if (projects.length === state.projects.length) {
return state;
}
const threads = state.threads.filter((thread) => thread.projectId !== action.projectId);
const activeThreadId = threads.some((thread) => thread.id === state.activeThreadId)
? state.activeThreadId
: (threads[0]?.id ?? null);
return {
...state,
projects,
threads,
activeThreadId,
};
}
case "ADD_THREAD": {
const nextThread = normalizeThreadTerminals({
...action.thread,