Skip to content

Commit 774c6c1

Browse files
authored
revert(web): restore grouped projects in the new thread selector (pingdotgg#22242)
1 parent d7bc3a2 commit 774c6c1

9 files changed

Lines changed: 43 additions & 234 deletions

‎apps/web/src/components/CommandPalette.logic.test.ts‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -348,31 +348,6 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
348348
}
349349

350350
describe("buildProjectActionItems", () => {
351-
it("shows offline checkout rows but excludes them from keyboard selection", () => {
352-
const local = makeProject();
353-
const remote = makeProject({
354-
id: local.id,
355-
environmentId: EnvironmentId.make("offline"),
356-
});
357-
const items = buildProjectActionItems({
358-
projects: [remote, local].map((project) => ({ ...project, displayName: "shared-repo" })),
359-
valuePrefix: "new-thread-in",
360-
icon: () => null,
361-
runProject: async () => undefined,
362-
disabled: (project) => project.environmentId === remote.environmentId,
363-
});
364-
const groups = [{ value: "projects", label: "Projects", items }];
365-
const { rows, itemValues } = buildCommandPaletteRows(groups);
366-
367-
expect(rows.filter((row) => row.kind === "item").map((row) => row.item.value)).toEqual([
368-
`new-thread-in:${remote.environmentId}:${remote.id}`,
369-
`new-thread-in:${local.environmentId}:${local.id}`,
370-
]);
371-
expect(itemValues).toEqual([`new-thread-in:${local.environmentId}:${local.id}`]);
372-
expect(findHighlightedCommandPaletteItem(groups, items[0]!.value)).toBeNull();
373-
expect(findHighlightedCommandPaletteItem(groups, items[1]!.value)).toBe(items[1]);
374-
});
375-
376351
it("shows the grouped display name but keeps the real title for icons", () => {
377352
const project = makeProject({ title: "fleet", workspaceRoot: "/Users/theo/Code/p/fleet" });
378353
const iconTitles: string[] = [];

‎apps/web/src/components/CommandPalette.logic.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ export function buildProjectActionItems(input: {
315315
runProject: (project: CommandPaletteProject) => Promise<void>;
316316
searchTerms?: (project: CommandPaletteProject) => ReadonlyArray<string>;
317317
renderDescription?: (project: CommandPaletteProject) => ReactNode;
318-
disabled?: (project: CommandPaletteProject) => boolean;
319318
shortcutCommand?: KeybindingCommand;
320319
}): CommandPaletteActionItem[] {
321320
return input.projects.map((project) => ({
@@ -330,7 +329,6 @@ export function buildProjectActionItems(input: {
330329
title: project.displayName,
331330
description: input.renderDescription?.(project) ?? project.workspaceRoot,
332331
icon: input.icon(project),
333-
...(input.disabled ? { disabled: input.disabled(project) } : {}),
334332
...(input.shortcutCommand !== undefined ? { shortcutCommand: input.shortcutCommand } : {}),
335333
run: async () => {
336334
await input.runProject(project);

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

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
type AddProjectRemoteSourceReadiness,
2626
} from "@t3tools/client-runtime/operations/projects";
2727
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
28-
import { connectionStatusText, connectionStatusTitle } from "@t3tools/client-runtime/connection";
28+
import { connectionStatusText } from "@t3tools/client-runtime/connection";
2929
import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
3030
import { resolveThreadReferenceCopyTarget } from "@t3tools/shared/threadReference";
3131
import {
@@ -887,20 +887,6 @@ function OpenCommandPaletteDialog(props: {
887887
groups: projectGroups,
888888
preferredProjectRef: contextualProjectRef,
889889
});
890-
const isEnvironmentReachable = (environmentId: EnvironmentId) =>
891-
environments.some(
892-
(environment) =>
893-
environment.environmentId === environmentId && environment.connection.phase === "connected",
894-
);
895-
const threadPickerProjects = buildSidebarProjectPickerEntries({
896-
groups: projectGroups,
897-
preferredProjectRef: contextualProjectRef,
898-
expandCheckouts: true,
899-
isEnvironmentReachable,
900-
}).map(({ group, targetProject }) => ({
901-
...targetProject,
902-
displayName: group.displayName,
903-
}));
904890
const pickerProjects = projectPickerEntries.map(({ group, targetProject }) => ({
905891
...targetProject,
906892
displayName: group.displayName,
@@ -1177,16 +1163,18 @@ function OpenCommandPaletteDialog(props: {
11771163
isScratchProject(project, scratchWorkspaceRootFor(project.environmentId));
11781164
const projectItems = enumerateCommandPaletteItems(
11791165
buildProjectActionItems({
1180-
projects: threadPickerProjects.filter((project) => !isScratch(project)),
1166+
projects: pickerProjects.filter((project) => !isScratch(project)),
11811167
valuePrefix: "new-thread-in",
1182-
disabled: (project) => !isEnvironmentReachable(project.environmentId),
1183-
searchTerms: (project) => [
1184-
projectEnvironmentLocationById.get(project.environmentId)?.label ?? "Remote",
1185-
],
1168+
searchTerms: (project) => {
1169+
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
1170+
const location = projectEnvironmentLocationById.get(project.environmentId);
1171+
return [
1172+
...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ??
1173+
[]),
1174+
...(location ? [location.label] : []),
1175+
];
1176+
},
11861177
renderDescription: (project) => {
1187-
const environment = environments.find(
1188-
(candidate) => candidate.environmentId === project.environmentId,
1189-
);
11901178
const location = projectEnvironmentLocationById.get(project.environmentId) ?? {
11911179
kind: "remote",
11921180
label: "Remote",
@@ -1206,29 +1194,30 @@ function OpenCommandPaletteDialog(props: {
12061194
</span>
12071195
<CommandPaletteMetaDot />
12081196
<span className="truncate">{project.workspaceRoot}</span>
1209-
{isEnvironmentReachable(project.environmentId) ? null : (
1210-
<>
1211-
<CommandPaletteMetaDot />
1212-
<span className="shrink-0">
1213-
{environment ? connectionStatusTitle(environment.connection) : "Unavailable"}
1214-
</span>
1215-
</>
1216-
)}
12171197
</span>
12181198
);
12191199
},
12201200
icon: projectFaviconIcon,
12211201
runProject: async (project) => {
1222-
await handleNewThread(scopeProjectRef(project.environmentId, project.id), {
1223-
environmentSelection: "manual",
1224-
});
1202+
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
1203+
const contextualRefBelongsToGroup =
1204+
contextualProjectRef !== null &&
1205+
group?.memberProjectRefs.some(
1206+
(projectRef) =>
1207+
projectRef.environmentId === contextualProjectRef.environmentId &&
1208+
projectRef.projectId === contextualProjectRef.projectId,
1209+
);
1210+
await handleNewThread(
1211+
contextualRefBelongsToGroup
1212+
? contextualProjectRef
1213+
: scopeProjectRef(project.environmentId, project.id),
1214+
);
12251215
},
12261216
}),
12271217
);
12281218
if (scratchTargetEnvironmentId === null) return projectItems;
12291219

1230-
const noProjectIndex =
1231-
threadPickerProjects[0] !== undefined && isScratch(threadPickerProjects[0]) ? 0 : 1;
1220+
const noProjectIndex = pickerProjects[0] !== undefined && isScratch(pickerProjects[0]) ? 0 : 1;
12321221
return [
12331222
...projectItems.slice(0, noProjectIndex),
12341223
{
@@ -1631,7 +1620,7 @@ function OpenCommandPaletteDialog(props: {
16311620
title: "New thread in...",
16321621
icon: <SquarePenIcon className={ITEM_ICON_CLASS} />,
16331622
addonIcon: <SquarePenIcon className={ADDON_ICON_CLASS} />,
1634-
groups: [{ value: "new-thread-in", label: "Projects", items: projectThreadItems }],
1623+
groups: [{ value: "projects", label: "Projects", items: projectThreadItems }],
16351624
});
16361625
}
16371626

@@ -1978,7 +1967,7 @@ function OpenCommandPaletteDialog(props: {
19781967
case "new-thread-in":
19791968
pushPaletteView({
19801969
addonIcon: <SquarePenIcon className={ADDON_ICON_CLASS} />,
1981-
groups: [{ value: "new-thread-in", label: "Projects", items: projectThreadItems }],
1970+
groups: [{ value: "projects", label: "Projects", items: projectThreadItems }],
19821971
});
19831972
return;
19841973
case "change-theme":
@@ -2125,9 +2114,7 @@ function OpenCommandPaletteDialog(props: {
21252114
? changeThemeItem.groups
21262115
: currentView?.groups[0]?.value === "appearance"
21272116
? changeAppearanceItem.groups
2128-
: currentView?.groups[0]?.value === "new-thread-in"
2129-
? [{ value: "new-thread-in", label: "Projects", items: projectThreadItems }]
2130-
: (currentView?.groups ?? rootGroups);
2117+
: (currentView?.groups ?? rootGroups);
21312118

21322119
const filteredGroups = filterCommandPaletteGroups({
21332120
activeGroups,

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ import { readLocalApi } from "../localApi";
130130
import { useSidebarPendingFileDropStore } from "../sidebarPendingFileDropStore";
131131
import { selectProjectGroupingSettings } from "../logicalProject";
132132
import {
133-
countSidebarProjectChoices,
134133
projectGroupsSpanEnvironments,
135134
resolveSidebarProjectScopeKey,
136135
getSidebarProjectSettingsKey,
@@ -4531,9 +4530,8 @@ export default function Sidebar() {
45314530
updateThreadJumpHintsVisibility(shouldShowJumpHintsNow);
45324531
}, [shouldShowJumpHintsNow, updateThreadJumpHintsVisibility]);
45334532

4534-
const projectChoiceCount = countSidebarProjectChoices(projectGroups);
45354533
const handleNewThreadClick = (event?: ReactMouseEvent) => {
4536-
if (shouldCreateNewThreadInCurrentProject(event?.shiftKey ?? false, projectChoiceCount)) {
4534+
if (shouldCreateNewThreadInCurrentProject(event?.shiftKey ?? false, projectGroups.length)) {
45374535
if (isMobile) setOpenMobile(false);
45384536
void startNewThreadFromContext({
45394537
activeDraftThread: newThreadContext.activeDraftThread,
@@ -4549,7 +4547,7 @@ export default function Sidebar() {
45494547

45504548
const newThreadShortcutLabel =
45514549
shortcutLabelForCommand(keybindings, "chat.new") ??
4552-
(projectChoiceCount <= 1 ? shortcutLabelForCommand(keybindings, "chat.newLocal") : undefined);
4550+
(projectGroups.length <= 1 ? shortcutLabelForCommand(keybindings, "chat.newLocal") : undefined);
45534551
const newThreadInProjectShortcutLabel = shortcutLabelForCommand(keybindings, "chat.newLocal");
45544552
return (
45554553
<>
@@ -4691,7 +4689,7 @@ export default function Sidebar() {
46914689
newThreadDisabled={projects.length === 0}
46924690
newThreadShortcutLabel={newThreadShortcutLabel}
46934691
newThreadInProjectShortcutLabel={newThreadInProjectShortcutLabel}
4694-
showNewThreadInProjectHint={projectChoiceCount > 1}
4692+
showNewThreadInProjectHint={projectGroups.length > 1}
46954693
searchInputRef={threadSearchInputRef}
46964694
searchQuery={threadSearchQuery}
46974695
onSearchQueryChange={(value) => {

‎apps/web/src/environmentGrouping.test.ts‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
buildPhysicalToLogicalProjectKeyMap,
1313
buildSidebarProjectPickerEntries,
1414
buildSidebarProjectSnapshots,
15-
countSidebarProjectChoices,
1615
projectGroupsSpanEnvironments,
1716
resolveSidebarProjectScopeKey,
1817
getSidebarProjectSettingsKey,
@@ -78,10 +77,6 @@ describe("environment grouping", () => {
7877
const settingsGroups = buildSidebarProjectSnapshots(input);
7978
expect(filters).toHaveLength(1);
8079
expect(settingsGroups).toHaveLength(2);
81-
expect([
82-
countSidebarProjectChoices(filters),
83-
countSidebarProjectChoices(settingsGroups),
84-
]).toEqual([1, 1]);
8580
expect(settingsGroups.map((group) => group.memberProjectRefs)).toEqual([
8681
[{ environmentId: local.environmentId, projectId: local.id }],
8782
[{ environmentId: remote.environmentId, projectId: remote.id }],
@@ -570,53 +565,6 @@ describe("environment grouping", () => {
570565
});
571566
});
572567

573-
it("offers every physical checkout, with reachable choices before an offline preference", () => {
574-
const primary = makeProject({ repositoryIdentity });
575-
const worktree = makeProject({
576-
id: ProjectId.make("local-worktree"),
577-
workspaceRoot: "/tmp/shared-repo-feature",
578-
repositoryIdentity,
579-
});
580-
const remote = makeProject({
581-
id: worktree.id,
582-
environmentId: remoteEnvironmentId,
583-
repositoryIdentity,
584-
});
585-
const groups = buildSidebarProjectSnapshots({
586-
projects: [remote, primary, worktree],
587-
settings: defaultGroupingSettings,
588-
primaryEnvironmentId,
589-
resolveEnvironmentLabel: () => null,
590-
});
591-
expect(countSidebarProjectChoices(groups)).toBe(3);
592-
const pickerInput = {
593-
groups,
594-
expandCheckouts: true,
595-
isEnvironmentReachable: (environmentId: EnvironmentId) =>
596-
environmentId === primaryEnvironmentId,
597-
};
598-
599-
const connectedPreference = buildSidebarProjectPickerEntries({
600-
...pickerInput,
601-
preferredProjectRef: { environmentId: primaryEnvironmentId, projectId: worktree.id },
602-
});
603-
expect(connectedPreference.map(({ targetProject }) => targetProject)).toMatchObject([
604-
worktree,
605-
primary,
606-
remote,
607-
]);
608-
609-
const offlinePreference = buildSidebarProjectPickerEntries({
610-
...pickerInput,
611-
preferredProjectRef: { environmentId: remoteEnvironmentId, projectId: remote.id },
612-
});
613-
expect(offlinePreference.map(({ targetProject }) => targetProject)).toMatchObject([
614-
primary,
615-
worktree,
616-
remote,
617-
]);
618-
});
619-
620568
it("keeps manual project order when building grouped sidebar entries", () => {
621569
const primary = makeProject({ repositoryIdentity });
622570
const remote = makeProject({

‎apps/web/src/hooks/useHandleNewThread.test.ts‎

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,12 @@ vi.mock("@effect/atom-react", () => ({
103103
? { newWorktreesStartFromOrigin: !testState.targetSettings.newWorktreesStartFromOrigin }
104104
: testServerConfigs(),
105105
}));
106-
vi.mock("@t3tools/client-runtime/environment", async (importOriginal) => ({
107-
...(await importOriginal<typeof import("@t3tools/client-runtime/environment")>()),
106+
vi.mock("@t3tools/client-runtime/environment", () => ({
108107
scopedProjectKey: () => "remote-project",
109108
scopeProjectRef: (environmentId: string, projectId: string) => ({ environmentId, projectId }),
110109
scopeThreadRef: (environmentId: string, threadId: string) => ({ environmentId, threadId }),
111110
}));
112-
vi.mock("@t3tools/contracts", async (importOriginal) => ({
113-
...(await importOriginal<typeof import("@t3tools/contracts")>()),
111+
vi.mock("@t3tools/contracts", () => ({
114112
DEFAULT_RUNTIME_MODE: "default",
115113
DEFAULT_SERVER_SETTINGS: {},
116114
}));
@@ -140,8 +138,7 @@ vi.mock("@tanstack/react-router", () => ({
140138
useParams: () => null,
141139
useRouter: () => testState.router,
142140
}));
143-
vi.mock("react", async (importOriginal) => ({
144-
...(await importOriginal<typeof import("react")>()),
141+
vi.mock("react", () => ({
145142
useCallback: <T>(callback: T) => callback,
146143
useMemo: <T>(factory: () => T) => factory(),
147144
}));
@@ -202,49 +199,6 @@ vi.mock("../uiStateStore", () => ({
202199
vi.mock("./useSettings", () => ({ useClientSettings: () => ({}) }));
203200

204201
import { useNewThreadHandler } from "./useHandleNewThread";
205-
import { useComposerDraftStore } from "../composerDraftStore";
206-
207-
it("pins a reused automatic draft to the explicitly selected checkout", async () => {
208-
const { useComposerDraftStore: realDraftStore, DraftId } =
209-
await vi.importActual<typeof import("../composerDraftStore")>("../composerDraftStore");
210-
const { EnvironmentId, ProjectId, ThreadId } =
211-
await vi.importActual<typeof import("@t3tools/contracts")>("@t3tools/contracts");
212-
testState.reset(null);
213-
const draftId = DraftId.make("draft-manual-checkout");
214-
const projectRef = {
215-
environmentId: EnvironmentId.make("environment-ssh"),
216-
projectId: ProjectId.make("project-remote"),
217-
};
218-
const store = realDraftStore.getState();
219-
store.setLogicalProjectDraftThreadId(
220-
"remote-project",
221-
{
222-
environmentId: EnvironmentId.make("environment-primary"),
223-
projectId: ProjectId.make("local"),
224-
},
225-
draftId,
226-
{
227-
threadId: ThreadId.make("thread-manual-checkout"),
228-
environmentSelection: "auto",
229-
loadBalancedEnvironmentId: EnvironmentId.make("environment-primary"),
230-
},
231-
);
232-
const getState = vi.spyOn(useComposerDraftStore, "getState").mockReturnValue(store);
233-
try {
234-
const opened = await useNewThreadHandler()(projectRef, { environmentSelection: "manual" });
235-
236-
expect(opened?.draftId).toBe(draftId);
237-
expect(store.getDraftSession(draftId)).toMatchObject({
238-
environmentId: projectRef.environmentId,
239-
projectId: projectRef.projectId,
240-
environmentSelection: "manual",
241-
loadBalancedEnvironmentId: null,
242-
});
243-
} finally {
244-
getState.mockRestore();
245-
realDraftStore.setState(store, true);
246-
}
247-
});
248202

249203
describe.each([
250204
["new", null],

0 commit comments

Comments
 (0)