Skip to content

Commit c70e28b

Browse files
fix(web): project settings can reach each checkout on one environment
When a project has several checkouts on one environment with different actions, Settings hides the list and asks you to choose an environment, which cannot separate them. Add and reset then change every checkout. Show a checkout menu in the scope line when an environment cannot tell the selected checkouts apart, using the existing checkout scope. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent edc37c9 commit c70e28b

6 files changed

Lines changed: 174 additions & 9 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,17 @@ export function ProjectActionsSettings() {
172172
/>
173173
{mixed ? (
174174
<SettingsRow
175-
title="Different actions across environments"
176-
description="Choose one environment to edit its list. Adding an action here adds it on every selected environment."
175+
{...(targets.every((candidate) => candidate.environmentId === target?.environmentId)
176+
? {
177+
title: "Different actions across checkouts",
178+
description:
179+
"Choose one checkout above to edit its list. Adding an action here adds it to every checkout.",
180+
}
181+
: {
182+
title: "Different actions across environments",
183+
description:
184+
"Choose one environment to edit its list. Adding an action here adds it on every selected environment.",
185+
})}
177186
/>
178187
) : (
179188
<ProjectActionsList

‎apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,46 @@ describe("project settings scope", () => {
602602
await expect.element(remoteOption()).not.toBeInTheDocument();
603603
});
604604

605+
it("reaches each checkout on one environment and returns to all of them", async () => {
606+
setup();
607+
const [first] = state.projects;
608+
state.projects = [
609+
{ ...first!, id: ProjectId.make("clone-a"), workspaceRoot: "/work/clone-a" },
610+
{ ...first!, id: ProjectId.make("clone-b"), workspaceRoot: "/work/clone-b" },
611+
];
612+
const key = projectKey();
613+
await using screen = await mountSettings({ project: key, machine: primaryId });
614+
615+
await userEvent.click(page.getByRole("button", { name: "Checkout scope: All checkouts" }));
616+
await userEvent.click(page.getByRole("menuitemradio", { name: /clone-b/ }));
617+
618+
await expect
619+
.element(page.getByRole("button", { name: "Checkout scope: clone-b" }))
620+
.toBeVisible();
621+
expect(screen.router.state.location.search).toMatchObject({
622+
project: key,
623+
machine: primaryId,
624+
checkout: expect.stringContaining("clone-b"),
625+
});
626+
627+
await userEvent.click(page.getByRole("button", { name: "Checkout scope: clone-b" }));
628+
await userEvent.click(page.getByRole("menuitemradio", { name: "All checkouts" }));
629+
630+
await vi.waitFor(() =>
631+
expect(screen.router.state.location.search).toEqual({ project: key, machine: primaryId }),
632+
);
633+
});
634+
635+
it("hides the checkout menu when each environment has one checkout", async () => {
636+
setup();
637+
await using _screen = await mountSettings({ project: projectKey(), machine: primaryId });
638+
639+
await expect.element(page.getByRole("textbox", { name: "Project name" })).toBeVisible();
640+
await expect
641+
.element(page.getByRole("button", { name: /^Checkout scope:/ }))
642+
.not.toBeInTheDocument();
643+
});
644+
605645
it("keeps an unknown project recoverable from any environment", async () => {
606646
setup();
607647
state.projects = state.projects.filter((project) => project.environmentId === primaryId);

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { resolveEnvironmentMachineKind } from "@t3tools/contracts";
2+
import { fileBasename } from "@t3tools/shared/path";
23
import { useLocation } from "@tanstack/react-router";
3-
import { CheckIcon, ChevronDownIcon, LayersIcon } from "lucide-react";
4+
import { CheckIcon, ChevronDownIcon, FolderIcon, LayersIcon } from "lucide-react";
45
import { Fragment, useState, type ReactNode } from "react";
56

67
import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
@@ -29,13 +30,16 @@ import {
2930
import { useOptionalSettingsScope } from "./SettingsScopeContext";
3031
import { resolveSettingsScope, type SettingsScopeSearch } from "./settingsScope";
3132
import {
33+
ALL_CHECKOUTS_VALUE,
3234
ALL_ENVIRONMENTS_VALUE,
3335
ALL_PROJECTS_VALUE,
3436
environmentAxisValue,
3537
projectAxisValue,
3638
projectScopeMenuGroups,
39+
selectCheckoutAxis,
3740
selectEnvironmentAxis,
3841
selectProjectAxis,
42+
settingsScopeCheckoutChoices,
3943
settingsScopeEnvironmentAddress,
4044
settingsScopeEnvironmentLabel,
4145
settingsScopeEnvironmentLabels,
@@ -86,6 +90,7 @@ export function SettingsScopeSentence() {
8690
</span>
8791
<EnvironmentScopeMenu {...props} />
8892
</span>
93+
<CheckoutScopeMenu {...props} />
8994
</p>
9095
);
9196
}
@@ -303,6 +308,45 @@ function EnvironmentScopeMenu({
303308
);
304309
}
305310

311+
function CheckoutScopeMenu({ value, groups, onChange }: SettingsScopeMenuProps) {
312+
const group = groups.find((candidate) => candidate.projectKey === value.project);
313+
const checkouts = group ? settingsScopeCheckoutChoices(group, value) : [];
314+
if (checkouts.length === 0) return null;
315+
const selected = checkouts.find((member) => member.physicalProjectKey === value.checkout);
316+
return (
317+
<span className="flex min-w-0 items-center gap-1.5">
318+
<span className="shrink-0">in</span>
319+
<ScopeMenu
320+
ariaLabel="Checkout scope"
321+
icon={<FolderIcon aria-hidden className="size-3.5 shrink-0" />}
322+
label={
323+
selected
324+
? fileBasename(selected.workspaceRoot)
325+
: value.checkout
326+
? "Unavailable checkout"
327+
: "All checkouts"
328+
}
329+
value={value.checkout ?? ALL_CHECKOUTS_VALUE}
330+
onChange={(next) =>
331+
onChange(
332+
selectCheckoutAxis(
333+
value,
334+
checkouts.find((member) => member.physicalProjectKey === next) ?? null,
335+
),
336+
)
337+
}
338+
searchLabel="Search checkouts"
339+
allOption={{ value: ALL_CHECKOUTS_VALUE, label: "All checkouts" }}
340+
options={checkouts.map((member) => ({
341+
value: member.physicalProjectKey,
342+
label: fileBasename(member.workspaceRoot),
343+
secondary: member.workspaceRoot,
344+
}))}
345+
/>
346+
</span>
347+
);
348+
}
349+
306350
function ProjectScopeMenu({ value, groups, environments, onChange }: SettingsScopeMenuProps) {
307351
const selected = groups.find((group) => group.projectKey === value.project);
308352
const projects = projectScopeMenuGroups(groups, value).map((group) => ({
Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,47 @@
11
import { describe, expect, it } from "vite-plus/test";
22

3-
import { selectEnvironmentAxis, selectProjectAxis } from "./settingsScopeAxis";
3+
import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
4+
import {
5+
selectCheckoutAxis,
6+
selectEnvironmentAxis,
7+
selectProjectAxis,
8+
settingsScopeCheckoutChoices,
9+
} from "./settingsScopeAxis";
10+
11+
const checkout = (environmentId: string, physicalProjectKey: string) =>
12+
({ environmentId, physicalProjectKey }) as SidebarProjectSnapshot["memberProjects"][number];
13+
const group = (...memberProjects: SidebarProjectSnapshot["memberProjects"]) =>
14+
({ memberProjects }) as SidebarProjectSnapshot;
415

516
describe("settings scope axes", () => {
617
it("drops a checkout narrowing from older links when either axis changes", () => {
7-
const checkout = { project: "app", checkout: "app@first", machine: "first" };
8-
expect(selectEnvironmentAxis(checkout, "second")).toEqual({
18+
const legacy = { project: "app", checkout: "app@first", machine: "first" };
19+
expect(selectEnvironmentAxis(legacy, "second")).toEqual({
920
project: "app",
1021
machine: "second",
1122
});
12-
expect(selectProjectAxis(checkout, "app")).toEqual({ project: "app", machine: "first" });
23+
expect(selectProjectAxis(legacy, "app")).toEqual({ project: "app", machine: "first" });
24+
});
25+
26+
it("offers checkouts only where an environment cannot tell them apart", () => {
27+
const a = checkout("laptop", "a");
28+
const b = checkout("laptop", "b");
29+
const c = checkout("server", "c");
30+
31+
expect(settingsScopeCheckoutChoices(group(a, b, c), { machine: "laptop" })).toEqual([a, b]);
32+
expect(settingsScopeCheckoutChoices(group(a, b), {})).toEqual([a, b]);
33+
expect(settingsScopeCheckoutChoices(group(a, b, c), { checkout: "b" })).toEqual([a, b]);
34+
expect(settingsScopeCheckoutChoices(group(a, b, c), {})).toEqual([]);
35+
expect(settingsScopeCheckoutChoices(group(a, b, c), { machine: "server" })).toEqual([]);
36+
});
37+
38+
it("narrows to one checkout and back without losing the chosen environment", () => {
39+
const search = { project: "app", machine: "laptop" };
40+
const narrowed = selectCheckoutAxis(search, checkout("laptop", "b"));
41+
42+
expect(narrowed).toEqual({ project: "app", machine: "laptop", checkout: "b" });
43+
expect(selectCheckoutAxis(narrowed, null)).toEqual(search);
44+
expect(selectCheckoutAxis({ project: "app" }, checkout("laptop", "b"))).toEqual(narrowed);
45+
expect(selectCheckoutAxis({ project: "app", checkout: "b" }, null)).toEqual({ project: "app" });
1346
});
1447
});

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
1+
import type {
2+
SidebarProjectGroupMember,
3+
SidebarProjectSnapshot,
4+
} from "../../sidebarProjectGrouping";
25
import type { EnvironmentPresentation } from "../../state/environments";
36
import type { ResolvedSettingsScope, SettingsScopeSearch } from "./settingsScope";
47

@@ -57,6 +60,7 @@ export function settingsScopeProjectMachines(
5760

5861
export const ALL_ENVIRONMENTS_VALUE = "all";
5962
export const ALL_PROJECTS_VALUE = "all";
63+
export const ALL_CHECKOUTS_VALUE = "all";
6064

6165
export function environmentAxisValue(
6266
search: SettingsScopeSearch,
@@ -97,6 +101,40 @@ export function selectProjectAxis(search: SettingsScopeSearch, value: string): S
97101
return next;
98102
}
99103

104+
/** Empty unless the selection spans several checkouts of one environment, which only this axis can split. */
105+
export function settingsScopeCheckoutChoices(
106+
group: SidebarProjectSnapshot,
107+
search: Pick<SettingsScopeSearch, "machine" | "checkout">,
108+
): readonly SidebarProjectGroupMember[] {
109+
const selected = group.memberProjects.find(
110+
(member) => member.physicalProjectKey === search.checkout,
111+
);
112+
const environmentId = search.machine ?? selected?.environmentId;
113+
const members =
114+
environmentId === undefined
115+
? group.memberProjects
116+
: group.memberProjects.filter((member) => member.environmentId === environmentId);
117+
return members.length > 1 &&
118+
members.every((member) => member.environmentId === members[0]!.environmentId)
119+
? members
120+
: [];
121+
}
122+
123+
export function selectCheckoutAxis(
124+
search: SettingsScopeSearch,
125+
checkout: SidebarProjectGroupMember | null,
126+
): SettingsScopeSearch {
127+
const next: SettingsScopeSearch = {};
128+
if (search.project) next.project = search.project;
129+
if (checkout) {
130+
next.machine = checkout.environmentId;
131+
next.checkout = checkout.physicalProjectKey;
132+
} else if (search.machine) {
133+
next.machine = search.machine;
134+
}
135+
return next;
136+
}
137+
100138
export function selectSingleEnvironmentScope(
101139
search: SettingsScopeSearch,
102140
scope: ResolvedSettingsScope,

‎docs/user/project-settings.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ project crumb.
172172
The Projects category, under Code, holds the project's name, icon, actions,
173173
checkouts and removal. Actions belong to a project: editing them creates the project's own list
174174
on each selected environment, and reset returns to the environment's shared list. A project's
175-
`t3.json` actions can be imported there.
175+
`t3.json` actions can be imported there. When a project has several checkouts on one environment,
176+
choose one in the scope line at the top to see or change only that checkout's settings.
176177

177178
Settings a repository can also declare in `t3.json`, such as the workspace for new threads,
178179
resolve in one order: a project override, then the environment setting, then `t3.json`, then the

0 commit comments

Comments
 (0)