TypeScript
fix(web): show "No project" near the top of the new thread picker (#16628)
Julius Marminge517188b3caa1
diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsxindex f7b78b5ae67..a0738dc8534 100644--- a/apps/web/src/components/CommandPalette.tsx+++ b/apps/web/src/components/CommandPalette.tsx@@ -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> = [];