Skip to content

Commit dd1394c

Browse files
fix(web): settings project picker lists only the chosen environment's projects
1 parent e688034 commit dd1394c

3 files changed

Lines changed: 70 additions & 2 deletions

File tree

‎apps/web/src/components/settings/SettingsScopeSentence.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
ALL_PROJECTS_VALUE,
2525
environmentAxisValue,
2626
projectAxisValue,
27+
projectScopeMenuGroups,
2728
selectEnvironmentAxis,
2829
selectProjectAxis,
2930
settingsScopeEnvironmentLabel,
@@ -210,7 +211,7 @@ function ProjectScopeMenu({ value, groups, onChange }: SettingsScopeMenuProps) {
210211
</span>
211212
</MenuRadioItem>
212213
<MenuSeparator />
213-
{groups.map((group) => (
214+
{projectScopeMenuGroups(groups, value).map((group) => (
214215
<MenuRadioItem key={group.projectKey} value={group.projectKey} closeOnClick>
215216
<span className="flex min-w-0 items-center gap-2">
216217
<ProjectFavicon project={group} className="size-3.5" />

‎apps/web/src/components/settings/settingsScopeAxis.test.ts‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { EnvironmentId } from "@t3tools/contracts";
1+
import { EnvironmentId, ProjectId } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33

4+
import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
45
import {
56
environmentAxisValue,
67
projectAxisValue,
8+
projectScopeMenuGroups,
79
selectEnvironmentAxis,
810
selectProjectAxis,
911
settingsScopeEnvironmentLabel,
@@ -86,3 +88,55 @@ describe("environmentAxisValue", () => {
8688
expect(environmentAxisValue({ machine: "desk" }, "laptop")).toBe("desk");
8789
});
8890
});
91+
92+
describe("settings project picker", () => {
93+
const fedora = EnvironmentId.make("fedora");
94+
const laptop = EnvironmentId.make("laptop");
95+
96+
function group(projectKey: string, environmentIds: readonly EnvironmentId[]) {
97+
const members = environmentIds.map((environmentId) => ({
98+
id: ProjectId.make(`${projectKey}-${environmentId}`),
99+
environmentId,
100+
title: projectKey,
101+
workspaceRoot: `/repos/${projectKey}`,
102+
physicalProjectKey: `${environmentId}:/repos/${projectKey}`,
103+
environmentLabel: null,
104+
defaultModelSelection: null,
105+
scripts: [],
106+
createdAt: "2026-10-11T00:00:00.000Z",
107+
updatedAt: "2026-10-11T00:00:00.000Z",
108+
}));
109+
return {
110+
...members[0]!,
111+
projectKey,
112+
displayName: projectKey,
113+
memberProjects: members,
114+
memberProjectRefs: members.map((member) => ({
115+
environmentId: member.environmentId,
116+
projectId: member.id,
117+
})),
118+
groupedProjectCount: members.length,
119+
environmentPresence: "mixed",
120+
allRemoteMembersAreDesktopLocal: false,
121+
allRemoteMembersAreWsl: false,
122+
remoteEnvironmentLabels: [],
123+
} as unknown as SidebarProjectSnapshot;
124+
}
125+
126+
const groups = [
127+
group("api", [fedora]),
128+
group("shared", [laptop, fedora]),
129+
group("notes", [laptop]),
130+
];
131+
const keys = (search: { machine?: string }) =>
132+
projectScopeMenuGroups(groups, search).map((entry) => entry.projectKey);
133+
134+
it("lists only projects with a checkout on the chosen environment", () => {
135+
expect(keys({ machine: fedora })).toEqual(["api", "shared"]);
136+
expect(keys({ machine: laptop })).toEqual(["shared", "notes"]);
137+
});
138+
139+
it("lists every project across all environments", () => {
140+
expect(keys({})).toEqual(["api", "shared", "notes"]);
141+
});
142+
});

‎apps/web/src/components/settings/settingsScopeAxis.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
12
import type { EnvironmentPresentation } from "../../state/environments";
23
import type { ResolvedSettingsScope, SettingsScopeSearch } from "./settingsScope";
34

@@ -54,6 +55,18 @@ export function selectProjectAxis(search: SettingsScopeSearch, value: string): S
5455
return next;
5556
}
5657

58+
/** The project picker offers only projects with a checkout on the chosen environment. */
59+
export function projectScopeMenuGroups(
60+
groups: readonly SidebarProjectSnapshot[],
61+
search: Pick<SettingsScopeSearch, "machine">,
62+
): readonly SidebarProjectSnapshot[] {
63+
const { machine } = search;
64+
if (machine === undefined) return groups;
65+
return groups.filter((group) =>
66+
group.memberProjects.some((member) => member.environmentId === machine),
67+
);
68+
}
69+
5770
/** Provider configuration always belongs to one environment, including project scopes. */
5871
export function selectSingleEnvironmentScope(
5972
search: SettingsScopeSearch,

0 commit comments

Comments
 (0)