Skip to content

Commit 2828bb2

Browse files
committed
feat(web): remove a project from its sidebar section
Every project has a row now, but no way to get rid of one from there. The action existed only in LegacySidebar, which the new sidebar replaced. Right-clicking a section header opens its actions as a menu: New thread and Project settings for a project, New project for an environment, and — only for a project — Remove project. Removing deliberately does not get an icon next to New thread. It is the one destructive thing a section header can do, and a third button one slip away from the two you press all day is how people delete a project by accident. The context menu is also the gesture threads already use for their own Archive and Delete, so this is the pattern the sidebar already teaches. The confirmation names the path, the environment and how many threads go with the project; a project that still has threads needs force, and says so. Drafts parked in the removed project are cleared, or the sidebar would keep a row pointing at a project that no longer exists. Written by Claude Opus 5 in Claude Code.
1 parent 0fbfd9c commit 2828bb2

2 files changed

Lines changed: 182 additions & 4 deletions

File tree

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 177 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
} from "@t3tools/client-runtime/environment";
3333
import type {
3434
EnvironmentId,
35+
ScopedProjectRef,
3536
ScopedThreadRef,
3637
SidebarProjectGroupingMode,
3738
SidebarThreadGroupingAxis,
@@ -97,6 +98,7 @@ import { isModelPickerOpen } from "../modelPickerVisibility";
9798
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
9899
import { isMacPlatform } from "~/lib/utils";
99100
import { useOpenPrLink } from "../lib/openPullRequestLink";
101+
import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors";
100102
import { readLocalApi } from "../localApi";
101103
import { getProjectOrderKey, selectProjectGroupingSettings } from "../logicalProject";
102104
import {
@@ -117,6 +119,7 @@ import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments"
117119
import { useProjects, useThreadShells } from "../state/entities";
118120
import { environmentServerConfigsAtom, primaryServerKeybindingsAtom } from "../state/server";
119121
import { vcsEnvironment } from "../state/vcs";
122+
import { projectEnvironment } from "../state/projects";
120123
import { threadEnvironment } from "../state/threads";
121124
import { useEnvironmentQuery } from "../state/query";
122125
import { useAtomCommand } from "../state/use-atom-command";
@@ -1957,6 +1960,9 @@ export default function Sidebar() {
19571960
archiveThread,
19581961
deleteThread,
19591962
} = useThreadActions();
1963+
const deleteProject = useAtomCommand(projectEnvironment.delete, {
1964+
reportFailure: false,
1965+
});
19601966
const updateThreadMetadata = useAtomCommand(threadEnvironment.updateMetadata, {
19611967
reportFailure: false,
19621968
});
@@ -2202,10 +2208,93 @@ export default function Sidebar() {
22022208
}
22032209
return count;
22042210
});
2205-
const handleProjectSettings = useCallback(
2206-
(event: ReactMouseEvent<HTMLButtonElement>, projectGroup: SidebarProjectSnapshot) => {
2207-
event.preventDefault();
2208-
event.stopPropagation();
2211+
// Removing a project is the one destructive thing a section header can do,
2212+
// so it never sits next to New thread as a click target: it lives in the
2213+
// header's context menu, the same gesture threads already use for Delete.
2214+
//
2215+
// Ported from LegacySidebar, which is where this action lived while the new
2216+
// sidebar had no project rows to hang it on.
2217+
const handleRemoveProject = useCallback(
2218+
async (projectGroup: SidebarProjectSnapshot, projectRef: ScopedProjectRef, label: string) => {
2219+
const api = readLocalApi();
2220+
if (!api) return;
2221+
const member =
2222+
projectGroup.memberProjects.find(
2223+
(candidate) =>
2224+
candidate.environmentId === projectRef.environmentId &&
2225+
candidate.id === projectRef.projectId,
2226+
) ?? null;
2227+
if (member === null) return;
2228+
2229+
const projectThreads = threads.filter(
2230+
(thread) =>
2231+
thread.environmentId === projectRef.environmentId &&
2232+
thread.projectId === projectRef.projectId,
2233+
);
2234+
const details = [
2235+
`Path: ${member.workspaceRoot}`,
2236+
...(member.environmentLabel ? [`Environment: ${member.environmentLabel}`] : []),
2237+
];
2238+
// A project with threads costs its history, so the prompt says how much
2239+
// and the removal has to be forced. An empty one only loses the entry.
2240+
const message =
2241+
projectThreads.length > 0
2242+
? [
2243+
`Remove project "${label}" and delete its ${projectThreads.length} thread${
2244+
projectThreads.length === 1 ? "" : "s"
2245+
}?`,
2246+
...details,
2247+
"This permanently clears conversation history for those threads.",
2248+
"This removes only this project entry.",
2249+
"This action cannot be undone.",
2250+
].join("\n")
2251+
: [
2252+
`Remove project "${label}"?`,
2253+
...details,
2254+
"This removes only this project entry.",
2255+
].join("\n");
2256+
const confirmed = await settlePromise(() =>
2257+
api.dialogs.confirm(message, { variant: "destructive" }),
2258+
);
2259+
if (confirmed._tag === "Failure" || !confirmed.value) return;
2260+
2261+
const result = await deleteProject({
2262+
environmentId: projectRef.environmentId,
2263+
input: {
2264+
projectId: projectRef.projectId,
2265+
...(projectThreads.length > 0 ? { force: true } : {}),
2266+
},
2267+
});
2268+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
2269+
const error = squashAtomCommandFailure(result);
2270+
console.error("Failed to remove project", {
2271+
projectId: projectRef.projectId,
2272+
environmentId: projectRef.environmentId,
2273+
...safeErrorLogAttributes(error),
2274+
});
2275+
toastManager.add(
2276+
stackedThreadToast({
2277+
type: "error",
2278+
title: `Failed to remove "${label}"`,
2279+
description: error instanceof Error ? error.message : "Unknown error removing project.",
2280+
}),
2281+
);
2282+
return;
2283+
}
2284+
// The draft parked in a project that no longer exists would otherwise
2285+
// keep a row in the sidebar pointing at nothing.
2286+
const draftStore = useComposerDraftStore.getState();
2287+
const projectDraftThread = draftStore.getDraftThreadByProjectRef(projectRef);
2288+
if (projectDraftThread) {
2289+
draftStore.clearDraftThread(projectDraftThread.draftId);
2290+
}
2291+
draftStore.clearProjectDraftThreadId(projectRef);
2292+
},
2293+
[deleteProject, threads],
2294+
);
2295+
2296+
const handleProjectSettingsGroup = useCallback(
2297+
(projectGroup: SidebarProjectSnapshot) => {
22092298
if (isMobile) {
22102299
setOpenMobile(false);
22112300
}
@@ -2216,6 +2305,14 @@ export default function Sidebar() {
22162305
},
22172306
[isMobile, router, setOpenMobile],
22182307
);
2308+
const handleProjectSettings = useCallback(
2309+
(event: ReactMouseEvent<HTMLButtonElement>, projectGroup: SidebarProjectSnapshot) => {
2310+
event.preventDefault();
2311+
event.stopPropagation();
2312+
handleProjectSettingsGroup(projectGroup);
2313+
},
2314+
[handleProjectSettingsGroup],
2315+
);
22192316

22202317
// Settled threads stay in the live shell stream (settled ≠ archived), so
22212318
// the partition works directly off live shells: no archived-snapshot
@@ -4157,6 +4254,75 @@ export default function Sidebar() {
41574254
/>,
41584255
);
41594256
}
4257+
/**
4258+
* Right-click on a section header. Same gesture threads use
4259+
* for their own destructive actions, which is why Remove
4260+
* project lives here instead of as a third icon one slip
4261+
* away from New thread.
4262+
*/
4263+
const handleGroupContextMenu = async (
4264+
group: (typeof activeThreadGroups)[number],
4265+
position: { readonly x: number; readonly y: number },
4266+
) => {
4267+
const api = readLocalApi();
4268+
if (!api) return;
4269+
const { environmentId, projectId } = group.target;
4270+
if (group.axis === "environment" && environmentId !== null) {
4271+
const clicked = await settlePromise(() =>
4272+
api.contextMenu.show(
4273+
[{ id: "new-project", label: `New project in ${group.label}` }],
4274+
position,
4275+
),
4276+
);
4277+
if (clicked._tag === "Failure" || clicked.value !== "new-project") {
4278+
return;
4279+
}
4280+
openAddProjectCommandPalette(environmentId);
4281+
return;
4282+
}
4283+
if (group.axis !== "project" || environmentId === null || projectId === null) {
4284+
return;
4285+
}
4286+
const projectRef = scopeProjectRef(environmentId, projectId);
4287+
const projectGroup =
4288+
projectGroupByProjectKey.get(`${environmentId}:${projectId}`) ?? null;
4289+
const clicked = await settlePromise(() =>
4290+
api.contextMenu.show(
4291+
[
4292+
{ id: "new-thread", label: "New thread" },
4293+
...(projectGroup === null
4294+
? []
4295+
: [{ id: "settings" as const, label: "Project settings" }]),
4296+
...(projectGroup === null
4297+
? []
4298+
: [
4299+
{
4300+
id: "remove" as const,
4301+
label: "Remove project",
4302+
destructive: true,
4303+
},
4304+
]),
4305+
],
4306+
position,
4307+
),
4308+
);
4309+
if (clicked._tag === "Failure" || !clicked.value) return;
4310+
switch (clicked.value) {
4311+
case "new-thread":
4312+
void handleNewThreadRef.current(projectRef);
4313+
return;
4314+
case "settings":
4315+
if (projectGroup) {
4316+
void handleProjectSettingsGroup(projectGroup);
4317+
}
4318+
return;
4319+
case "remove":
4320+
if (projectGroup) {
4321+
void handleRemoveProject(projectGroup, projectRef, group.label);
4322+
}
4323+
return;
4324+
}
4325+
};
41604326
// Always visible, not hover-only: these are the way into a
41614327
// project now that the selector is gone, and an action you
41624328
// have to hunt for by hovering is an action most people
@@ -4360,6 +4526,13 @@ export default function Sidebar() {
43604526
<li
43614527
key={`group-header:${group.key}`}
43624528
data-thread-selection-safe
4529+
onContextMenu={(event) => {
4530+
event.preventDefault();
4531+
void handleGroupContextMenu(group, {
4532+
x: event.clientX,
4533+
y: event.clientY,
4534+
});
4535+
}}
43634536
className={cn(
43644537
"relative flex list-none items-center gap-1 pe-1",
43654538
// Top level carries the weight of a shelf header;

‎docs/user/thread-sidebar.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ environment.
4848

4949
Provider sections span several projects and environments, so they carry no actions.
5050

51+
Right-clicking a section header opens the same actions as a menu, plus **Remove project**.
52+
Removing is destructive, so it stays out of the row: it tells you the path, the environment and
53+
how many threads go with the project, and asks before doing anything. Threads keep their own
54+
right-click menu with **Archive thread** and **Delete**.
55+
5156
A collapsed section shows what is waiting inside it as colored dots with counts, in order of
5257
urgency: amber for approvals, indigo for input requests, red for failures, green for finished
5358
threads you have not opened yet, and blue for threads still working. Open sections leave that to

0 commit comments

Comments
 (0)