Skip to content

Commit 96f2eb5

Browse files
committed
fixup! feat(web): simplify the window project chooser (#1669)
Reshape CommandPalette as marked insertions without replacing upstream calls; keep project identity on derived thread actions. Fork-Domain: workspaces Fork-Tier: qol Fork-Upstreamable: no
1 parent 2e0bad8 commit 96f2eb5

5 files changed

Lines changed: 101 additions & 24 deletions

File tree

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

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,49 @@ export function dropNewThreadHintFork(
193193
items[index] = withoutHint;
194194
}
195195

196-
/** The palette's threads under the scope. */
197-
export function scopedPaletteThreadsFork<
198-
Thread extends { readonly environmentId: string; readonly projectId: string },
199-
>(threads: ReadonlyArray<Thread>, projectKeys: ReadonlySet<string> | null) {
200-
return scopeToProjectKeys(threads, projectKeys, (thread) => [
201-
`${thread.environmentId}:${thread.projectId}`,
202-
]);
196+
// These arrays are freshly derived for this render, never store-owned. Filtering
197+
// them after construction keeps the upstream palette calls as insertion-only seams.
198+
export function scopePaletteThreadItemsFork(
199+
items: CommandPaletteActionItem[],
200+
projectKeys: ReadonlySet<string> | null,
201+
): void {
202+
if (projectKeys === null) return;
203+
const scoped = scopeToProjectKeys(items, projectKeys, (item) =>
204+
"projectKeyFork" in item && typeof item.projectKeyFork === "string"
205+
? [item.projectKeyFork]
206+
: [],
207+
);
208+
items.splice(0, items.length, ...scoped);
209+
}
210+
211+
export function scopePalettePickerProjectsFork<
212+
Project extends { readonly environmentId: string; readonly id: string },
213+
>(
214+
projects: Project[],
215+
entries: ReadonlyArray<{
216+
readonly group: { readonly memberProjectRefs: ReadonlyArray<ScopedProjectRef> };
217+
readonly targetProject: { readonly environmentId: string; readonly id: string };
218+
}>,
219+
scope: CommandPaletteProjectScope,
220+
): void {
221+
if (scope.projectKeys === null) return;
222+
const allowed = new Set(
223+
scopePaletteProjectEntriesFork(entries, scope.projectKeys, scope.preserveEmpty).map(
224+
({ targetProject }) => `${targetProject.environmentId}:${targetProject.id}`,
225+
),
226+
);
227+
const scoped = projects.filter((project) =>
228+
allowed.has(`${project.environmentId}:${project.id}`),
229+
);
230+
projects.splice(0, projects.length, ...scoped);
231+
}
232+
233+
export function paletteGroupsInputFork(
234+
groups: ReadonlyArray<CommandPaletteGroup>,
235+
projectThreadItems: ReadonlyArray<CommandPaletteActionItem>,
236+
) {
237+
const refreshed = refreshNewThreadInViewFork(groups, projectThreadItems);
238+
return refreshed === groups ? {} : { activeGroups: refreshed };
203239
}
204240

205241
/**

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import { describe, expect, it } from "vite-plus/test";
33

44
import {
55
browseInputEndPaddingClass,
6+
buildThreadActionItems,
67
filterCommandPaletteGroups,
78
type CommandPaletteActionItem,
89
} from "./CommandPalette.logic";
10+
import { makeThreadFixture } from "../test-fixtures";
911
import {
1012
buildLinkGitHubIssueActionItemFork,
1113
refreshNewThreadInViewFork,
1214
scopePaletteProjectEntriesFork,
15+
scopePalettePickerProjectsFork,
16+
scopePaletteThreadItemsFork,
1317
withProjectScopeToggleFork,
1418
} from "./CommandPalette.fork";
1519

@@ -78,6 +82,48 @@ describe("palette project scope", () => {
7882
expect(scopePaletteProjectEntriesFork(entries, new Set())).toBe(entries);
7983
});
8084

85+
it("filters extracted thread items by project and environment, not thread id", () => {
86+
const threads = ["local", "remote"].map((environmentId) =>
87+
makeThreadFixture({
88+
id: ThreadId.make("shared-thread-id"),
89+
projectId: ProjectId.make("api"),
90+
environmentId: EnvironmentId.make(environmentId),
91+
}),
92+
);
93+
const items = buildThreadActionItems({
94+
threads,
95+
projectTitleById: new Map(),
96+
sortOrder: "updated_at",
97+
icon: null,
98+
runThread: async () => {},
99+
});
100+
const remoteItem = items[1];
101+
scopePaletteThreadItemsFork(items, new Set(["remote:api"]));
102+
expect(items).toEqual([remoteItem]);
103+
scopePaletteThreadItemsFork(items, new Set());
104+
expect(items).toEqual([]);
105+
});
106+
107+
it("filters derived picker projects through group members and preserves explicit empty", () => {
108+
const entries = ["api", "web"].map((id) => ({
109+
...entryOf(id),
110+
targetProject: { environmentId: "local", id },
111+
}));
112+
entries[1]!.group.memberProjectRefs.push(ref("remote", "alias"));
113+
const projects = entries.map(({ targetProject }) => ({ ...targetProject }));
114+
scopePalettePickerProjectsFork(projects, entries, {
115+
projectKeys: new Set(["remote:alias"]),
116+
toggle: null,
117+
});
118+
expect(projects.map(({ id }) => id)).toEqual(["web"]);
119+
scopePalettePickerProjectsFork(projects, entries, {
120+
projectKeys: new Set(),
121+
preserveEmpty: true,
122+
toggle: null,
123+
});
124+
expect(projects).toEqual([]);
125+
});
126+
81127
it("Search all: the pushed new-thread picker follows the scope, keeping its lead first", () => {
82128
const pushed = [{ value: "projects", label: "Projects", items: [item("b"), item("a")] }];
83129
const refreshed = refreshNewThreadInViewFork(pushed, [item("a"), item("b"), item("c")]);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
409409
{
410410
kind: "action" as const,
411411
value: `thread:${thread.id}`,
412+
projectKeyFork: `${thread.environmentId}:${thread.projectId}`, // fork-hook: workspaces/palette-thread-project-key
412413
searchTerms: [
413414
thread.title,
414415
...threadPullRequestSearchTerms(thread),

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ import { buildLinkGitHubIssueActionItemFork } from "./CommandPalette.fork"; // f
5050
import { buildProjectChooserActionItemFork } from "./CommandPalette.fork"; // fork-hook: workspaces/chooser-palette
5151
import {
5252
dropNewThreadHintFork,
53-
refreshNewThreadInViewFork,
54-
scopePaletteProjectEntriesFork,
53+
paletteGroupsInputFork,
54+
scopePalettePickerProjectsFork,
55+
scopePaletteThreadItemsFork,
5556
useCommandPaletteProjectScopeFork,
5657
useNewThreadHintFork,
5758
withProjectScopeToggleFork,
@@ -628,14 +629,11 @@ function OpenCommandPaletteDialog(props: {
628629
groups: projectGroups,
629630
preferredProjectRef: contextualProjectRef,
630631
});
631-
const pickerProjects = scopePaletteProjectEntriesFork(
632-
projectPickerEntries,
633-
paletteProjectScope.projectKeys,
634-
paletteProjectScope.preserveEmpty,
635-
).map(({ group, targetProject }) => ({
632+
const pickerProjects = projectPickerEntries.map(({ group, targetProject }) => ({
636633
...targetProject,
637634
displayName: group.displayName,
638-
})); // fork-hook: workspaces/palette-scope-projects
635+
}));
636+
scopePalettePickerProjectsFork(pickerProjects, projectPickerEntries, paletteProjectScope); // fork-hook: workspaces/palette-scope-projects
639637
const projectGroupByTargetKey = new Map(
640638
projectPickerEntries.map(({ group, targetProject }) => [
641639
`${targetProject.environmentId}:${targetProject.id}`,
@@ -918,11 +916,8 @@ function OpenCommandPaletteDialog(props: {
918916
})();
919917

920918
const { threadItems: allThreadItems, isSearchPending: isThreadSearchPending } =
921-
useCommandPaletteThreadItems({
922-
activeThreadId,
923-
threadSearchQuery,
924-
projectKeysFork: paletteProjectScope.projectKeys,
925-
}); // fork-hook: workspaces/palette-scope-threads
919+
useCommandPaletteThreadItems({ activeThreadId, threadSearchQuery });
920+
scopePaletteThreadItemsFork(allThreadItems, paletteProjectScope.projectKeys); // fork-hook: workspaces/palette-scope-threads
926921
const recentThreadItems = allThreadItems.slice(0, RECENT_THREAD_LIMIT);
927922

928923
// Stable so the item builders that capture it during render never see the
@@ -1690,10 +1685,11 @@ function OpenCommandPaletteDialog(props: {
16901685
? changeThemeItem.groups
16911686
: currentView?.groups[0]?.value === "appearance"
16921687
? changeAppearanceItem.groups
1693-
: refreshNewThreadInViewFork(currentView?.groups ?? rootGroups, projectThreadItems); // fork-hook: workspaces/palette-scope-picker
1688+
: (currentView?.groups ?? rootGroups);
16941689

16951690
const filteredGroups = filterCommandPaletteGroups({
16961691
activeGroups,
1692+
...paletteGroupsInputFork(activeGroups, projectThreadItems), // fork-hook: workspaces/palette-scope-picker
16971693
query: deferredQuery,
16981694
isInSubmenu: currentView !== null,
16991695
projectSearchItems: projectSearchItems,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2-
import { scopedPaletteThreadsFork } from "./CommandPalette.fork"; // fork-hook: workspaces/palette-scope-threads-import
32
import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
43
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
54
import { useAtomValue } from "@effect/atom-react";
@@ -72,7 +71,6 @@ function useThreadSearchWithContentMatches(query: string) {
7271
export function useCommandPaletteThreadItems(input: {
7372
readonly activeThreadId: ThreadId | undefined;
7473
readonly threadSearchQuery: string;
75-
readonly projectKeysFork?: ReadonlySet<string> | null; // fork-hook: workspaces/palette-scope-threads-input
7674
}) {
7775
const { activeThreadId, threadSearchQuery } = input;
7876
const navigate = useNavigate();
@@ -84,7 +82,7 @@ export function useCommandPaletteThreadItems(input: {
8482
const { projectByKey, projectTitleById } = useProjectLookups();
8583

8684
const threadItems = buildThreadActionItems({
87-
threads: scopedPaletteThreadsFork(threads, input.projectKeysFork ?? null), // fork-hook: workspaces/palette-scope-threads
85+
threads,
8886
...(activeThreadId ? { activeThreadId } : {}),
8987
projectTitleById,
9088
sortOrder: sidebarThreadSortOrder,

0 commit comments

Comments
 (0)