replace nested project actions with management dialog
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
46e15372d1
commit
aee5f8d304
3 files changed
+123
-161
No files matched your search
@@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"
|
||||
import {
|
||||
archiveSelectedThreadEntries,
|
||||
buildMultiSelectThreadContextMenuItems,
|
||||
buildSidebarV2ProjectActionItems,
|
||||
createThreadJumpHintVisibilityController,
|
||||
getSidebarThreadIdsToPrewarm,
|
||||
getVisibleSidebarThreadIds,
|
||||
@@ -37,73 +36,6 @@ import {
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
describe("buildSidebarV2ProjectActionItems", () => {
|
||||
it("targets each physical member and makes remove-all explicit for grouped projects", () => {
|
||||
expect(
|
||||
buildSidebarV2ProjectActionItems([
|
||||
{
|
||||
physicalProjectKey: "local:/repo",
|
||||
title: "Local title",
|
||||
workspaceRoot: "/repo",
|
||||
environmentLabel: "Grouping Local",
|
||||
},
|
||||
{
|
||||
physicalProjectKey: "remote:/repo",
|
||||
title: "Remote title",
|
||||
workspaceRoot: "/repo",
|
||||
environmentLabel: "Grouping Remote",
|
||||
},
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
id: "rename:submenu",
|
||||
label: "Rename project entry",
|
||||
children: [
|
||||
{ id: "rename:local:/repo", label: "Grouping Local — /repo" },
|
||||
{ id: "rename:remote:/repo", label: "Grouping Remote — /repo" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "grouping:submenu",
|
||||
label: "Group into…",
|
||||
children: [
|
||||
{ id: "grouping:local:/repo", label: "Grouping Local — /repo" },
|
||||
{ id: "grouping:remote:/repo", label: "Grouping Remote — /repo" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "copy-path:submenu",
|
||||
label: "Copy Path",
|
||||
children: [
|
||||
{ id: "copy-path:local:/repo", label: "Grouping Local — /repo" },
|
||||
{ id: "copy-path:remote:/repo", label: "Grouping Remote — /repo" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "remove:submenu",
|
||||
label: "Remove",
|
||||
children: [
|
||||
{
|
||||
id: "remove:local:/repo",
|
||||
label: "Grouping Local — /repo",
|
||||
destructive: true,
|
||||
},
|
||||
{
|
||||
id: "remove:remote:/repo",
|
||||
label: "Grouping Remote — /repo",
|
||||
destructive: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "remove-all",
|
||||
label: "Remove all grouped entries…",
|
||||
destructive: true,
|
||||
icon: "trash",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
import {
|
||||
DEFAULT_INTERACTION_MODE,
|
||||
DEFAULT_RUNTIME_MODE,
|
||||
|
||||
@@ -44,63 +44,6 @@ type LogicalSidebarProject = SidebarProject & {
|
||||
}[];
|
||||
};
|
||||
|
||||
type ProjectActionMember = {
|
||||
readonly physicalProjectKey: string;
|
||||
readonly title: string;
|
||||
readonly workspaceRoot: string;
|
||||
readonly environmentLabel: string | null;
|
||||
};
|
||||
|
||||
export function buildSidebarV2ProjectActionItems(
|
||||
members: readonly ProjectActionMember[],
|
||||
): ContextMenuItem<string>[] {
|
||||
const memberLabel = (member: ProjectActionMember) =>
|
||||
members.length > 1
|
||||
? member.environmentLabel
|
||||
? `${member.environmentLabel} — ${member.workspaceRoot}`
|
||||
: member.workspaceRoot
|
||||
: member.title;
|
||||
const targetedItem = (
|
||||
action: "rename" | "grouping" | "copy-path" | "remove",
|
||||
label: string,
|
||||
destructive = false,
|
||||
): ContextMenuItem<string> => {
|
||||
if (members.length === 1) {
|
||||
return {
|
||||
id: `${action}:${members[0]!.physicalProjectKey}`,
|
||||
label,
|
||||
...(destructive ? { destructive: true, icon: "trash" as const } : {}),
|
||||
};
|
||||
}
|
||||
return {
|
||||
id: `${action}:submenu`,
|
||||
label,
|
||||
children: members.map((member) => ({
|
||||
id: `${action}:${member.physicalProjectKey}`,
|
||||
label: memberLabel(member),
|
||||
...(destructive ? { destructive: true } : {}),
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
return [
|
||||
targetedItem("rename", members.length > 1 ? "Rename project entry" : "Rename"),
|
||||
targetedItem("grouping", "Group into…"),
|
||||
targetedItem("copy-path", "Copy Path"),
|
||||
targetedItem("remove", "Remove", true),
|
||||
...(members.length > 1
|
||||
? [
|
||||
{
|
||||
id: "remove-all",
|
||||
label: "Remove all grouped entries…",
|
||||
destructive: true,
|
||||
icon: "trash" as const,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
}
|
||||
|
||||
export type ThreadTraversalDirection = "previous" | "next";
|
||||
|
||||
export async function archiveSelectedThreadEntries<
|
||||
|
||||
@@ -90,7 +90,6 @@ import type { SidebarThreadSummary } from "../types";
|
||||
import { cn } from "~/lib/utils";
|
||||
import {
|
||||
firstValidTimestampMs,
|
||||
buildSidebarV2ProjectActionItems,
|
||||
hasUnseenCompletion,
|
||||
isTrailingDoubleClick,
|
||||
orderItemsByPreferredIds,
|
||||
@@ -797,6 +796,9 @@ export default function SidebarV2() {
|
||||
null,
|
||||
);
|
||||
const [projectRenameTitle, setProjectRenameTitle] = useState("");
|
||||
const [projectActionsTarget, setProjectActionsTarget] = useState<SidebarProjectSnapshot | null>(
|
||||
null,
|
||||
);
|
||||
const [projectGroupingTarget, setProjectGroupingTarget] =
|
||||
useState<SidebarProjectGroupMember | null>(null);
|
||||
const [projectGroupingSelection, setProjectGroupingSelection] = useState<
|
||||
@@ -1124,44 +1126,12 @@ export default function SidebarV2() {
|
||||
]);
|
||||
|
||||
const handleProjectActions = useCallback(
|
||||
async (event: ReactMouseEvent<HTMLButtonElement>, projectGroup: SidebarProjectSnapshot) => {
|
||||
(event: ReactMouseEvent<HTMLButtonElement>, projectGroup: SidebarProjectSnapshot) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const api = readLocalApi();
|
||||
if (!api) return;
|
||||
const clicked = await api.contextMenu.show(
|
||||
buildSidebarV2ProjectActionItems(projectGroup.memberProjects),
|
||||
{ x: event.clientX, y: event.clientY },
|
||||
);
|
||||
if (!clicked) return;
|
||||
if (clicked === "remove-all") {
|
||||
await handleRemoveProjectMembers(projectGroup, projectGroup.memberProjects);
|
||||
return;
|
||||
}
|
||||
const member = projectGroup.memberProjects.find((candidate) =>
|
||||
clicked.endsWith(`:${candidate.physicalProjectKey}`),
|
||||
);
|
||||
if (!member) return;
|
||||
if (clicked.startsWith("rename:")) {
|
||||
setProjectRenameTarget(member);
|
||||
setProjectRenameTitle(member.title);
|
||||
} else if (clicked.startsWith("grouping:")) {
|
||||
const overrideKey = deriveProjectGroupingOverrideKey(member);
|
||||
setProjectGroupingTarget(member);
|
||||
setProjectGroupingSelection(
|
||||
projectGroupingSettings.sidebarProjectGroupingOverrides?.[overrideKey] ?? "inherit",
|
||||
);
|
||||
} else if (clicked.startsWith("copy-path:")) {
|
||||
copyProjectPath(member.workspaceRoot, { path: member.workspaceRoot });
|
||||
} else if (clicked.startsWith("remove:")) {
|
||||
await handleRemoveProjectMembers(projectGroup, [member]);
|
||||
}
|
||||
setProjectActionsTarget(projectGroup);
|
||||
},
|
||||
[
|
||||
copyProjectPath,
|
||||
handleRemoveProjectMembers,
|
||||
projectGroupingSettings.sidebarProjectGroupingOverrides,
|
||||
],
|
||||
[],
|
||||
);
|
||||
|
||||
// Settled threads stay in the live shell stream (settled ≠ archived), so
|
||||
@@ -2022,6 +1992,123 @@ export default function SidebarV2() {
|
||||
) : null}
|
||||
</SidebarGroup>
|
||||
</SidebarContent>
|
||||
<Dialog
|
||||
open={projectActionsTarget !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setProjectActionsTarget(null);
|
||||
}}
|
||||
>
|
||||
<DialogPopup className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Manage {projectActionsTarget?.displayName ?? "project"}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{projectActionsTarget && projectActionsTarget.memberProjects.length > 1
|
||||
? "Manage each environment's project entry independently."
|
||||
: "Rename, regroup, copy, or remove this project entry."}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogPanel className="space-y-3">
|
||||
{projectActionsTarget?.memberProjects.map((member) => (
|
||||
<div
|
||||
key={member.physicalProjectKey}
|
||||
className="rounded-lg border border-border/70 bg-muted/20 p-3"
|
||||
>
|
||||
<div className="flex min-w-0 items-start gap-2">
|
||||
<ProjectFavicon
|
||||
environmentId={member.environmentId}
|
||||
cwd={member.workspaceRoot}
|
||||
className="mt-0.5 size-4 shrink-0"
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm font-medium text-foreground">
|
||||
{member.title}
|
||||
</div>
|
||||
<div className="mt-0.5 truncate text-xs text-muted-foreground">
|
||||
{member.environmentLabel
|
||||
? `${member.environmentLabel} · ${member.workspaceRoot}`
|
||||
: member.workspaceRoot}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setProjectActionsTarget(null);
|
||||
setProjectRenameTarget(member);
|
||||
setProjectRenameTitle(member.title);
|
||||
}}
|
||||
>
|
||||
Rename
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setProjectActionsTarget(null);
|
||||
setProjectGroupingTarget(member);
|
||||
setProjectGroupingSelection(
|
||||
projectGroupingSettings.sidebarProjectGroupingOverrides?.[
|
||||
deriveProjectGroupingOverrideKey(member)
|
||||
] ?? "inherit",
|
||||
);
|
||||
}}
|
||||
>
|
||||
Grouping
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
copyProjectPath(member.workspaceRoot, { path: member.workspaceRoot })
|
||||
}
|
||||
>
|
||||
Copy path
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
className="ml-auto"
|
||||
onClick={() => {
|
||||
const projectGroup = projectActionsTarget;
|
||||
if (!projectGroup) return;
|
||||
setProjectActionsTarget(null);
|
||||
void handleRemoveProjectMembers(projectGroup, [member]);
|
||||
}}
|
||||
>
|
||||
Remove
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{projectActionsTarget && projectActionsTarget.memberProjects.length > 1 ? (
|
||||
<div className="flex items-center justify-between gap-4 border-t border-border/70 pt-3">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Removes every grouped entry and its conversation history.
|
||||
</p>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
className="shrink-0"
|
||||
onClick={() => {
|
||||
const projectGroup = projectActionsTarget;
|
||||
setProjectActionsTarget(null);
|
||||
void handleRemoveProjectMembers(projectGroup, projectGroup.memberProjects);
|
||||
}}
|
||||
>
|
||||
Remove all entries
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</DialogPanel>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setProjectActionsTarget(null)}>
|
||||
Done
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogPopup>
|
||||
</Dialog>
|
||||
<Dialog
|
||||
open={projectRenameTarget !== null}
|
||||
onOpenChange={(open) => {
|
||||
|
||||
Reference in new issue
Block a user