group projects in new-thread pickers
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
ee44f639a3
commit
a499f30f7e
2 files changed
+150
-16
No files matched your search
@@ -59,6 +59,7 @@ import { useAtomQueryRunner } from "../state/use-atom-query-runner";
|
||||
import { useEnvironments, usePrimaryEnvironment } from "../state/environments";
|
||||
import { useProjects, useThreadShells } from "../state/entities";
|
||||
import {
|
||||
resolveThreadActionProjectRef,
|
||||
startNewThreadInProjectFromContext,
|
||||
startNewThreadFromContext,
|
||||
} from "../lib/chatThreadActions";
|
||||
@@ -79,7 +80,7 @@ import {
|
||||
} from "../lib/projectPaths";
|
||||
import { onOpenCommandPalette } from "../commandPaletteBus";
|
||||
import { isTerminalFocused } from "../lib/terminalFocus";
|
||||
import { getLatestThreadForProject } from "../lib/threadSort";
|
||||
import { getLatestThreadForProject, sortThreads } from "../lib/threadSort";
|
||||
import { cn, isMacPlatform, isWindowsPlatform, newProjectId } from "../lib/utils";
|
||||
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
|
||||
import { buildThreadRouteParams, resolveThreadRouteTarget } from "../threadRoutes";
|
||||
@@ -106,6 +107,7 @@ import {
|
||||
ITEM_ICON_CLASS,
|
||||
RECENT_THREAD_LIMIT,
|
||||
} from "./CommandPalette.logic";
|
||||
import { orderItemsByPreferredIds, sortLogicalProjectsForSidebar } from "./Sidebar.logic";
|
||||
import { resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
|
||||
import { CommandPaletteResults } from "./CommandPaletteResults";
|
||||
import { AzureDevOpsIcon, BitbucketIcon, GitHubIcon, GitLabIcon } from "./Icons";
|
||||
@@ -128,6 +130,12 @@ import { stackedThreadToast, toastManager } from "./ui/toast";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
import { ComposerHandleContext, useComposerHandleContext } from "../composerHandleContext";
|
||||
import type { ChatComposerHandle } from "./chat/ChatComposer";
|
||||
import { getProjectOrderKey, selectProjectGroupingSettings } from "../logicalProject";
|
||||
import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
|
||||
import {
|
||||
buildSidebarProjectPickerEntries,
|
||||
buildSidebarProjectSnapshots,
|
||||
} from "../sidebarProjectGrouping";
|
||||
|
||||
const EMPTY_BROWSE_ENTRIES: FilesystemBrowseResult["entries"] = [];
|
||||
|
||||
@@ -491,6 +499,7 @@ function OpenCommandPaletteDialog(props: {
|
||||
const { activeDraftThread, activeThread, defaultProjectRef, handleNewThread } =
|
||||
useHandleNewThread();
|
||||
const projects = useProjects();
|
||||
const projectOrder = useUiStateStore((store) => store.projectOrder);
|
||||
const threads = useThreadShells();
|
||||
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
|
||||
const providers = useAtomValue(primaryServerProvidersAtom);
|
||||
@@ -505,6 +514,93 @@ function OpenCommandPaletteDialog(props: {
|
||||
const [isRemoteProjectLookingUp, setIsRemoteProjectLookingUp] = useState(false);
|
||||
const [isRemoteProjectCloning, setIsRemoteProjectCloning] = useState(false);
|
||||
const primaryEnvironmentId = primaryEnvironment?.environmentId ?? null;
|
||||
const projectGroupingSettings = useMemo(
|
||||
() => selectProjectGroupingSettings(clientSettings),
|
||||
[clientSettings],
|
||||
);
|
||||
|
||||
const environmentLabelById = useMemo(
|
||||
() =>
|
||||
new Map(
|
||||
environments.map((environment) => [environment.environmentId, environment.label] as const),
|
||||
),
|
||||
[environments],
|
||||
);
|
||||
const orderedProjects = useMemo(
|
||||
() =>
|
||||
orderItemsByPreferredIds({
|
||||
items: projects,
|
||||
preferredIds: projectOrder,
|
||||
getId: getProjectOrderKey,
|
||||
getPreferenceIds: (project) => [
|
||||
getProjectOrderKey(project),
|
||||
legacyProjectCwdPreferenceKey(project.workspaceRoot),
|
||||
],
|
||||
}),
|
||||
[projectOrder, projects],
|
||||
);
|
||||
const unsortedProjectGroups = useMemo(
|
||||
() =>
|
||||
buildSidebarProjectSnapshots({
|
||||
projects: clientSettings.sidebarProjectSortOrder === "manual" ? orderedProjects : projects,
|
||||
settings: projectGroupingSettings,
|
||||
primaryEnvironmentId,
|
||||
resolveEnvironmentLabel: (environmentId) => environmentLabelById.get(environmentId) ?? null,
|
||||
}),
|
||||
[
|
||||
clientSettings.sidebarProjectSortOrder,
|
||||
environmentLabelById,
|
||||
orderedProjects,
|
||||
primaryEnvironmentId,
|
||||
projectGroupingSettings,
|
||||
projects,
|
||||
],
|
||||
);
|
||||
const projectGroups = useMemo(
|
||||
() =>
|
||||
sortLogicalProjectsForSidebar(
|
||||
unsortedProjectGroups,
|
||||
threads,
|
||||
clientSettings.sidebarProjectSortOrder,
|
||||
),
|
||||
[clientSettings.sidebarProjectSortOrder, threads, unsortedProjectGroups],
|
||||
);
|
||||
const contextualProjectRef = useMemo(
|
||||
() =>
|
||||
resolveThreadActionProjectRef({
|
||||
activeDraftThread,
|
||||
activeThread: activeThread ?? undefined,
|
||||
defaultProjectRef,
|
||||
handleNewThread,
|
||||
}),
|
||||
[activeDraftThread, activeThread, defaultProjectRef, handleNewThread],
|
||||
);
|
||||
const projectPickerEntries = useMemo(
|
||||
() =>
|
||||
buildSidebarProjectPickerEntries({
|
||||
groups: projectGroups,
|
||||
preferredProjectRef: contextualProjectRef,
|
||||
}),
|
||||
[contextualProjectRef, projectGroups],
|
||||
);
|
||||
const pickerProjects = useMemo(
|
||||
() =>
|
||||
projectPickerEntries.map(({ group, targetProject }) => ({
|
||||
...targetProject,
|
||||
title: group.displayName,
|
||||
})),
|
||||
[projectPickerEntries],
|
||||
);
|
||||
const projectGroupByTargetKey = useMemo(
|
||||
() =>
|
||||
new Map(
|
||||
projectPickerEntries.map(({ group, targetProject }) => [
|
||||
`${targetProject.environmentId}:${targetProject.id}`,
|
||||
group,
|
||||
]),
|
||||
),
|
||||
[projectPickerEntries],
|
||||
);
|
||||
|
||||
const addProjectEnvironmentOptions = useMemo(() => {
|
||||
const options = environments.map((environment): AddProjectEnvironmentOption => {
|
||||
@@ -648,11 +744,28 @@ function OpenCommandPaletteDialog(props: {
|
||||
|
||||
const openProjectFromSearch = useMemo(
|
||||
() => async (project: (typeof projects)[number]) => {
|
||||
const latestThread = getLatestThreadForProject(
|
||||
threads.filter((thread) => thread.environmentId === project.environmentId),
|
||||
project.id,
|
||||
clientSettings.sidebarThreadSortOrder,
|
||||
);
|
||||
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
|
||||
const groupedProjectKeys = group
|
||||
? new Set(
|
||||
group.memberProjectRefs.map(
|
||||
(projectRef) => `${projectRef.environmentId}:${projectRef.projectId}`,
|
||||
),
|
||||
)
|
||||
: null;
|
||||
const latestThread = groupedProjectKeys
|
||||
? (sortThreads(
|
||||
threads.filter(
|
||||
(thread) =>
|
||||
thread.archivedAt === null &&
|
||||
groupedProjectKeys.has(`${thread.environmentId}:${thread.projectId}`),
|
||||
),
|
||||
clientSettings.sidebarThreadSortOrder,
|
||||
)[0] ?? null)
|
||||
: getLatestThreadForProject(
|
||||
threads.filter((thread) => thread.environmentId === project.environmentId),
|
||||
project.id,
|
||||
clientSettings.sidebarThreadSortOrder,
|
||||
);
|
||||
if (latestThread) {
|
||||
await navigate({
|
||||
to: "/$environmentId/$threadId",
|
||||
@@ -665,13 +778,19 @@ function OpenCommandPaletteDialog(props: {
|
||||
|
||||
await handleNewThread(scopeProjectRef(project.environmentId, project.id));
|
||||
},
|
||||
[handleNewThread, navigate, clientSettings.sidebarThreadSortOrder, threads],
|
||||
[
|
||||
clientSettings.sidebarThreadSortOrder,
|
||||
handleNewThread,
|
||||
navigate,
|
||||
projectGroupByTargetKey,
|
||||
threads,
|
||||
],
|
||||
);
|
||||
|
||||
const projectSearchItems = useMemo(
|
||||
() =>
|
||||
buildProjectActionItems({
|
||||
projects,
|
||||
projects: pickerProjects,
|
||||
valuePrefix: "project",
|
||||
icon: (project) => (
|
||||
<ProjectFavicon
|
||||
@@ -682,7 +801,7 @@ function OpenCommandPaletteDialog(props: {
|
||||
),
|
||||
runProject: openProjectFromSearch,
|
||||
}),
|
||||
[openProjectFromSearch, projects],
|
||||
[openProjectFromSearch, pickerProjects],
|
||||
);
|
||||
|
||||
const projectThreadItems = useMemo(
|
||||
@@ -1018,9 +1137,9 @@ function OpenCommandPaletteDialog(props: {
|
||||
const actionItems: Array<CommandPaletteActionItem | CommandPaletteSubmenuItem> = [];
|
||||
|
||||
if (projects.length > 0) {
|
||||
const activeProjectTitle = currentProjectId
|
||||
? (projectTitleById.get(currentProjectId) ?? null)
|
||||
: null;
|
||||
const activeProjectTitle =
|
||||
projectPickerEntries.find((entry) => entry.isPreferred)?.group.displayName ??
|
||||
(currentProjectId ? (projectTitleById.get(currentProjectId) ?? null) : null);
|
||||
|
||||
if (activeProjectTitle) {
|
||||
actionItems.push({
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useMemo } from "react";
|
||||
|
||||
import { isCommandPaletteOpen } from "../commandPaletteBus";
|
||||
import { useClientSettings } from "../hooks/useSettings";
|
||||
import { openCommandPalette } from "../commandPaletteBus";
|
||||
import { useProjects } from "../state/entities";
|
||||
import { usePrimaryEnvironmentId } from "../state/environments";
|
||||
import { selectProjectGroupingSettings } from "../logicalProject";
|
||||
import { buildSidebarProjectSnapshots } from "../sidebarProjectGrouping";
|
||||
import { dispatchPreviewAction } from "../components/preview/previewActionBus";
|
||||
import { useHandleNewThread } from "../hooks/useHandleNewThread";
|
||||
import {
|
||||
@@ -29,7 +32,19 @@ function ChatRouteGlobalShortcuts() {
|
||||
useHandleNewThread();
|
||||
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
|
||||
const sidebarV2Enabled = useClientSettings((settings) => settings.sidebarV2Enabled);
|
||||
const projectCount = useProjects().length;
|
||||
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
|
||||
const projects = useProjects();
|
||||
const primaryEnvironmentId = usePrimaryEnvironmentId();
|
||||
const projectGroupCount = useMemo(
|
||||
() =>
|
||||
buildSidebarProjectSnapshots({
|
||||
projects,
|
||||
settings: projectGroupingSettings,
|
||||
primaryEnvironmentId,
|
||||
resolveEnvironmentLabel: () => null,
|
||||
}).length,
|
||||
[primaryEnvironmentId, projectGroupingSettings, projects],
|
||||
);
|
||||
const terminalOpen = useTerminalUiStateStore((state) =>
|
||||
routeThreadRef
|
||||
? selectThreadTerminalUiState(state.terminalUiStateByThreadKey, routeThreadRef).terminalOpen
|
||||
@@ -83,7 +98,7 @@ function ChatRouteGlobalShortcuts() {
|
||||
// Sidebar v2 routes creation through the command palette whenever
|
||||
// there is a real choice to make; v1 (and single-project setups)
|
||||
// keep the immediate contextual create.
|
||||
if (sidebarV2Enabled && projectCount > 1) {
|
||||
if (sidebarV2Enabled && projectGroupCount > 1) {
|
||||
openCommandPalette({ open: "new-thread-in" });
|
||||
return;
|
||||
}
|
||||
@@ -152,7 +167,7 @@ function ChatRouteGlobalShortcuts() {
|
||||
keybindings,
|
||||
defaultProjectRef,
|
||||
previewOpen,
|
||||
projectCount,
|
||||
projectGroupCount,
|
||||
routeThreadRef,
|
||||
selectedThreadKeysSize,
|
||||
sidebarV2Enabled,
|
||||
|
||||
Reference in new issue
Block a user