Skip to content

Commit fa8949a

Browse files
fix(web): project settings can reach each checkout on one environment (#29441)
Co-authored-by: Julius Marminge <[email protected]>
1 parent c0df40a commit fa8949a

6 files changed

Lines changed: 160 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ export function ProjectActionsSettings() {
173173
/>
174174
{mixed ? (
175175
<SettingsRow
176-
title="Different actions across environments"
177-
description="Choose one environment to edit its list. Adding an action here adds it on every selected environment."
176+
title="Different actions across checkouts"
177+
description="Narrow the selection above to one checkout to edit its list. Adding an action here adds it to every selected checkout."
178178
/>
179179
) : (
180180
<ProjectActionsList

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,36 @@ 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+
605635
it("keeps an unknown project recoverable from any environment", async () => {
606636
setup();
607637
state.projects = state.projects.filter((project) => project.environmentId === primaryId);

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

Lines changed: 46 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,17 @@ 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,
43+
settingsScopeCheckoutLabel,
3944
settingsScopeEnvironmentAddress,
4045
settingsScopeEnvironmentLabel,
4146
settingsScopeEnvironmentLabels,
@@ -86,6 +91,7 @@ export function SettingsScopeSentence() {
8691
</span>
8792
<EnvironmentScopeMenu {...props} />
8893
</span>
94+
<CheckoutScopeMenu {...props} />
8995
</p>
9096
);
9197
}
@@ -303,6 +309,45 @@ function EnvironmentScopeMenu({
303309
);
304310
}
305311

312+
function CheckoutScopeMenu({ value, groups, onChange }: SettingsScopeMenuProps) {
313+
const group = groups.find((candidate) => candidate.projectKey === value.project);
314+
const checkouts = group ? settingsScopeCheckoutChoices(group, value) : [];
315+
if (checkouts.length === 0) return null;
316+
const selected = checkouts.find((member) => member.physicalProjectKey === value.checkout);
317+
return (
318+
<span className="flex min-w-0 items-center gap-1.5">
319+
<span className="shrink-0">in</span>
320+
<ScopeMenu
321+
ariaLabel="Checkout scope"
322+
icon={<FolderIcon aria-hidden className="size-3.5 shrink-0" />}
323+
label={
324+
selected
325+
? settingsScopeCheckoutLabel(selected, checkouts)
326+
: value.checkout
327+
? "Unavailable checkout"
328+
: "All checkouts"
329+
}
330+
value={value.checkout ?? ALL_CHECKOUTS_VALUE}
331+
onChange={(next) =>
332+
onChange(
333+
selectCheckoutAxis(
334+
value,
335+
checkouts.find((member) => member.physicalProjectKey === next) ?? null,
336+
),
337+
)
338+
}
339+
searchLabel="Search checkouts"
340+
allOption={{ value: ALL_CHECKOUTS_VALUE, label: "All checkouts" }}
341+
options={checkouts.map((member) => ({
342+
value: member.physicalProjectKey,
343+
label: fileBasename(member.workspaceRoot),
344+
secondary: member.workspaceRoot,
345+
}))}
346+
/>
347+
</span>
348+
);
349+
}
350+
306351
function ProjectScopeMenu({ value, groups, environments, onChange }: SettingsScopeMenuProps) {
307352
const selected = groups.find((group) => group.projectKey === value.project);
308353
const projects = projectScopeMenuGroups(groups, value).map((group) => ({

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
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+
selectEnvironmentAxis,
6+
selectProjectAxis,
7+
settingsScopeCheckoutChoices,
8+
settingsScopeCheckoutLabel,
9+
} from "./settingsScopeAxis";
10+
11+
const member = (environmentId: string, physicalProjectKey: string, workspaceRoot = "") =>
12+
({
13+
environmentId,
14+
physicalProjectKey,
15+
workspaceRoot,
16+
}) as SidebarProjectSnapshot["memberProjects"][number];
17+
const group = (...memberProjects: SidebarProjectSnapshot["memberProjects"]) =>
18+
({ memberProjects }) as SidebarProjectSnapshot;
419

520
describe("settings scope axes", () => {
621
it("drops a checkout narrowing from older links when either axis changes", () => {
@@ -11,4 +26,25 @@ describe("settings scope axes", () => {
1126
});
1227
expect(selectProjectAxis(checkout, "app")).toEqual({ project: "app", machine: "first" });
1328
});
29+
30+
it("offers checkouts only where an environment cannot tell them apart", () => {
31+
const a = member("laptop", "a");
32+
const b = member("laptop", "b");
33+
const c = member("server", "c");
34+
35+
expect(settingsScopeCheckoutChoices(group(a, b, c), { machine: "laptop" })).toEqual([a, b]);
36+
expect(settingsScopeCheckoutChoices(group(a, b), {})).toEqual([a, b]);
37+
expect(settingsScopeCheckoutChoices(group(a, b, c), { checkout: "b" })).toEqual([a, b]);
38+
expect(settingsScopeCheckoutChoices(group(a, b, c), {})).toEqual([]);
39+
expect(settingsScopeCheckoutChoices(group(a, b, c), { machine: "server" })).toEqual([]);
40+
});
41+
42+
it("labels a checkout by its full path only when its folder name repeats", () => {
43+
const first = member("laptop", "a", "/work/one/app");
44+
const second = member("laptop", "b", "C:\\work\\two\\app");
45+
const other = member("laptop", "c", "/work/tools");
46+
47+
expect(settingsScopeCheckoutLabel(second, [first, second, other])).toBe("C:\\work\\two\\app");
48+
expect(settingsScopeCheckoutLabel(other, [first, second, other])).toBe("tools");
49+
});
1450
});

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { fileBasename } from "@t3tools/shared/path";
12
import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
23
import type { EnvironmentPresentation } from "../../state/environments";
34
import type { ResolvedSettingsScope, SettingsScopeSearch } from "./settingsScope";
45

6+
type ScopeCheckout = SidebarProjectSnapshot["memberProjects"][number];
57
type ScopeEnvironment = Pick<EnvironmentPresentation, "environmentId" | "label" | "displayUrl">;
68

79
export function settingsScopeEnvironmentAddress(environment: ScopeEnvironment) {
@@ -57,6 +59,7 @@ export function settingsScopeProjectMachines(
5759

5860
export const ALL_ENVIRONMENTS_VALUE = "all";
5961
export const ALL_PROJECTS_VALUE = "all";
62+
export const ALL_CHECKOUTS_VALUE = "all";
6063

6164
export function environmentAxisValue(
6265
search: SettingsScopeSearch,
@@ -97,6 +100,46 @@ export function selectProjectAxis(search: SettingsScopeSearch, value: string): S
97100
return next;
98101
}
99102

103+
/** Empty unless the selection spans several checkouts of one environment, which only this axis can split. */
104+
export function settingsScopeCheckoutChoices(
105+
group: SidebarProjectSnapshot,
106+
search: Pick<SettingsScopeSearch, "machine" | "checkout">,
107+
): readonly ScopeCheckout[] {
108+
const selected = group.memberProjects.find(
109+
(member) => member.physicalProjectKey === search.checkout,
110+
);
111+
const environmentId = search.machine ?? selected?.environmentId;
112+
const members =
113+
environmentId === undefined
114+
? group.memberProjects
115+
: group.memberProjects.filter((member) => member.environmentId === environmentId);
116+
return members.length > 1 &&
117+
members.every((member) => member.environmentId === members[0]!.environmentId)
118+
? members
119+
: [];
120+
}
121+
122+
export function selectCheckoutAxis(
123+
search: SettingsScopeSearch,
124+
checkout: ScopeCheckout | null,
125+
): SettingsScopeSearch {
126+
const { checkout: _previous, ...rest } = search;
127+
return checkout
128+
? { ...rest, machine: checkout.environmentId, checkout: checkout.physicalProjectKey }
129+
: rest;
130+
}
131+
132+
/** Repeated folder names fall back to the full path so the closed menu still identifies the checkout. */
133+
export function settingsScopeCheckoutLabel(
134+
checkout: ScopeCheckout,
135+
checkouts: readonly ScopeCheckout[],
136+
) {
137+
const name = fileBasename(checkout.workspaceRoot);
138+
return checkouts.filter((other) => fileBasename(other.workspaceRoot) === name).length > 1
139+
? checkout.workspaceRoot
140+
: name;
141+
}
142+
100143
export function selectSingleEnvironmentScope(
101144
search: SettingsScopeSearch,
102145
scope: ResolvedSettingsScope,

‎docs/user/project-settings.md‎

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

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

0 commit comments

Comments
 (0)