fix(web): show "No project" near the top of the new thread picker (#16628)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
4b5c604853
commit
517188b3ca
1 file changed
+90
-107
@@ -163,6 +163,7 @@ import {
|
||||
findHighlightedCommandPaletteItem,
|
||||
type CommandPaletteActionItem,
|
||||
type CommandPaletteOpenIntent,
|
||||
type CommandPaletteProject,
|
||||
type CommandPaletteSubmenuItem,
|
||||
type CommandPaletteView,
|
||||
filterCommandPaletteGroups,
|
||||
@@ -1309,89 +1310,94 @@ function OpenCommandPaletteDialog(props: {
|
||||
],
|
||||
);
|
||||
|
||||
const projectThreadItems = useMemo(
|
||||
() =>
|
||||
enumerateCommandPaletteItems([
|
||||
...buildProjectActionItems({
|
||||
// The no-project home shows once, as the "No project" item below.
|
||||
projects: pickerProjects.filter(
|
||||
(project) => !isScratchProject(project, scratchWorkspaceRootFor(project.environmentId)),
|
||||
),
|
||||
valuePrefix: "new-thread-in",
|
||||
searchTerms: (project) => {
|
||||
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
|
||||
const location = projectEnvironmentLocationById.get(project.environmentId);
|
||||
return [
|
||||
...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ??
|
||||
[]),
|
||||
...(location ? [location.label] : []),
|
||||
];
|
||||
},
|
||||
renderDescription: (project) => {
|
||||
const location = projectEnvironmentLocationById.get(project.environmentId) ?? {
|
||||
kind: "remote",
|
||||
label: "Remote",
|
||||
machine: "server" as const,
|
||||
};
|
||||
return (
|
||||
<span className="flex min-w-0 items-center gap-1">
|
||||
<span className="inline-flex min-w-0 items-center gap-1">
|
||||
{location.kind === "remote" ? (
|
||||
<EnvironmentMachineIcon
|
||||
aria-hidden
|
||||
kind={location.machine}
|
||||
className={COMMAND_PALETTE_META_ICON_CLASS}
|
||||
/>
|
||||
) : null}
|
||||
<span className="truncate">{location.label}</span>
|
||||
</span>
|
||||
<CommandPaletteMetaDot />
|
||||
<span className="truncate">{project.workspaceRoot}</span>
|
||||
const projectThreadItems = useMemo(() => {
|
||||
const isScratch = (project: CommandPaletteProject) =>
|
||||
isScratchProject(project, scratchWorkspaceRootFor(project.environmentId));
|
||||
const projectItems = enumerateCommandPaletteItems(
|
||||
buildProjectActionItems({
|
||||
// The no-project home shows once, as the "No project" item below.
|
||||
projects: pickerProjects.filter((project) => !isScratch(project)),
|
||||
valuePrefix: "new-thread-in",
|
||||
searchTerms: (project) => {
|
||||
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
|
||||
const location = projectEnvironmentLocationById.get(project.environmentId);
|
||||
return [
|
||||
...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ??
|
||||
[]),
|
||||
...(location ? [location.label] : []),
|
||||
];
|
||||
},
|
||||
renderDescription: (project) => {
|
||||
const location = projectEnvironmentLocationById.get(project.environmentId) ?? {
|
||||
kind: "remote",
|
||||
label: "Remote",
|
||||
machine: "server" as const,
|
||||
};
|
||||
return (
|
||||
<span className="flex min-w-0 items-center gap-1">
|
||||
<span className="inline-flex min-w-0 items-center gap-1">
|
||||
{location.kind === "remote" ? (
|
||||
<EnvironmentMachineIcon
|
||||
aria-hidden
|
||||
kind={location.machine}
|
||||
className={COMMAND_PALETTE_META_ICON_CLASS}
|
||||
/>
|
||||
) : null}
|
||||
<span className="truncate">{location.label}</span>
|
||||
</span>
|
||||
<CommandPaletteMetaDot />
|
||||
<span className="truncate">{project.workspaceRoot}</span>
|
||||
</span>
|
||||
);
|
||||
},
|
||||
icon: projectFaviconIcon,
|
||||
runProject: async (project) => {
|
||||
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
|
||||
const contextualRefBelongsToGroup =
|
||||
contextualProjectRef !== null &&
|
||||
group?.memberProjectRefs.some(
|
||||
(projectRef) =>
|
||||
projectRef.environmentId === contextualProjectRef.environmentId &&
|
||||
projectRef.projectId === contextualProjectRef.projectId,
|
||||
);
|
||||
},
|
||||
icon: projectFaviconIcon,
|
||||
runProject: async (project) => {
|
||||
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
|
||||
const contextualRefBelongsToGroup =
|
||||
contextualProjectRef !== null &&
|
||||
group?.memberProjectRefs.some(
|
||||
(projectRef) =>
|
||||
projectRef.environmentId === contextualProjectRef.environmentId &&
|
||||
projectRef.projectId === contextualProjectRef.projectId,
|
||||
);
|
||||
await handleNewThread(
|
||||
contextualRefBelongsToGroup
|
||||
? contextualProjectRef
|
||||
: scopeProjectRef(project.environmentId, project.id),
|
||||
);
|
||||
},
|
||||
}),
|
||||
...(scratchTargetEnvironmentId === null
|
||||
? []
|
||||
: [
|
||||
{
|
||||
kind: "action" as const,
|
||||
value: "new-thread-in:no-project",
|
||||
searchTerms: ["no project", "without project", "none"],
|
||||
title: "No project",
|
||||
icon: <MessageSquareDashedIcon className={ITEM_ICON_CLASS} />,
|
||||
shortcutCommand: "chat.newWithoutProject" as const,
|
||||
run: () => startScratchThread(scratchTargetEnvironmentId),
|
||||
},
|
||||
]),
|
||||
]),
|
||||
[
|
||||
contextualProjectRef,
|
||||
handleNewThread,
|
||||
pickerProjects,
|
||||
projectEnvironmentLocationById,
|
||||
projectGroupByTargetKey,
|
||||
scratchTargetEnvironmentId,
|
||||
scratchWorkspaceRootFor,
|
||||
startScratchThread,
|
||||
],
|
||||
);
|
||||
await handleNewThread(
|
||||
contextualRefBelongsToGroup
|
||||
? contextualProjectRef
|
||||
: scopeProjectRef(project.environmentId, project.id),
|
||||
);
|
||||
},
|
||||
}),
|
||||
);
|
||||
if (scratchTargetEnvironmentId === null) return projectItems;
|
||||
|
||||
// "No project" goes right after the current project: visible without
|
||||
// scrolling past every project, while Enter still starts in the current
|
||||
// one. When the current thread has no project, it is the current entry and
|
||||
// goes first. It keeps its own shortcut, so the projects' mod+1..9 hold.
|
||||
const noProjectIndex = pickerProjects[0] !== undefined && isScratch(pickerProjects[0]) ? 0 : 1;
|
||||
return [
|
||||
...projectItems.slice(0, noProjectIndex),
|
||||
{
|
||||
kind: "action" as const,
|
||||
value: "new-thread-in:no-project",
|
||||
searchTerms: ["no project", "without project", "none"],
|
||||
title: "No project",
|
||||
icon: <MessageSquareDashedIcon className={ITEM_ICON_CLASS} />,
|
||||
shortcutCommand: "chat.newWithoutProject" as const,
|
||||
run: () => startScratchThread(scratchTargetEnvironmentId),
|
||||
},
|
||||
...projectItems.slice(noProjectIndex),
|
||||
];
|
||||
}, [
|
||||
contextualProjectRef,
|
||||
handleNewThread,
|
||||
pickerProjects,
|
||||
projectEnvironmentLocationById,
|
||||
projectGroupByTargetKey,
|
||||
scratchTargetEnvironmentId,
|
||||
scratchWorkspaceRootFor,
|
||||
startScratchThread,
|
||||
]);
|
||||
|
||||
const allThreadItems = useMemo(
|
||||
() =>
|
||||
@@ -1848,35 +1854,12 @@ function OpenCommandPaletteDialog(props: {
|
||||
setNewProjectFlow(null);
|
||||
setViewStack([]);
|
||||
setQuery("");
|
||||
const currentPrefix =
|
||||
currentProjectEnvironmentId && currentProjectId
|
||||
? `new-thread-in:${currentProjectEnvironmentId}:${currentProjectId}`
|
||||
: null;
|
||||
const prioritized = currentPrefix
|
||||
? [
|
||||
...projectThreadItems.filter((item) => item.value === currentPrefix),
|
||||
...projectThreadItems.filter((item) => item.value !== currentPrefix),
|
||||
]
|
||||
: projectThreadItems;
|
||||
// projectThreadItems already lists the current project first.
|
||||
pushPaletteView({
|
||||
addonIcon: <SquarePenIcon className={ADDON_ICON_CLASS} />,
|
||||
groups: [
|
||||
{
|
||||
value: "projects",
|
||||
label: "Projects",
|
||||
items: enumerateCommandPaletteItems(prioritized),
|
||||
},
|
||||
],
|
||||
groups: [{ value: "projects", label: "Projects", items: projectThreadItems }],
|
||||
});
|
||||
}, [
|
||||
clearOpenIntent,
|
||||
browseNavigation,
|
||||
currentProjectEnvironmentId,
|
||||
currentProjectId,
|
||||
openIntent,
|
||||
projectThreadItems,
|
||||
pushPaletteView,
|
||||
]);
|
||||
}, [clearOpenIntent, browseNavigation, openIntent, projectThreadItems, pushPaletteView]);
|
||||
|
||||
const actionItems: Array<CommandPaletteActionItem | CommandPaletteSubmenuItem> = [];
|
||||
|
||||
|
||||
Reference in new issue
Block a user