Skip to content

Commit 8de61d4

Browse files
fix(client): merge No project filters across environments (pingdotgg#17050)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 8863990 commit 8de61d4

14 files changed

Lines changed: 704 additions & 28 deletions

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
77
import { Platform, useWindowDimensions } from "react-native";
88

99
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
10+
import { resolveScratchProjectScopeKey } from "@t3tools/client-runtime/state/project-grouping";
1011

1112
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/StackHeader";
1213
import { useProjects } from "../../state/entities";
@@ -119,7 +120,16 @@ export function HomeRouteScreen() {
119120
setSelectedProjectKey,
120121
} = useHomeListOptions(availableEnvironmentIds);
121122
const selectedEnvironmentId = listOptions.selectedEnvironmentId;
122-
const selectedProjectKey = listOptions.selectedProjectKey;
123+
const projectScopeKey = listOptions.selectedProjectKey;
124+
const selectedProjectKey = resolveScratchProjectScopeKey(projectScopeKey, projects, {
125+
sidebarProjectGroupingMode: listOptions.projectGroupingMode,
126+
sidebarProjectGroupingOverrides: {},
127+
});
128+
useEffect(() => {
129+
if (selectedProjectKey !== projectScopeKey) {
130+
setSelectedProjectKey(selectedProjectKey);
131+
}
132+
}, [projectScopeKey, selectedProjectKey, setSelectedProjectKey]);
123133
const projectFilterOptions = useMemo(
124134
() =>
125135
buildHomeProjectScopes({

‎apps/mobile/src/features/home/homeThreadList.test.ts‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
sortHomeProjectScopes,
1212
} from "./homeThreadList";
1313
import { makeThreadShellFixture } from "../../test-fixtures";
14+
import { buildThreadListV2Items } from "../threads/threadListV2";
1415

1516
function makeProject(
1617
input: Partial<EnvironmentProject> & Pick<EnvironmentProject, "environmentId" | "id" | "title">,
@@ -48,6 +49,79 @@ function makeThread(
4849
}
4950

5051
describe("home project scopes", () => {
52+
it("filters threads across both scratch hosts while retaining the selected environment boundary", () => {
53+
const localEnvironmentId = EnvironmentId.make("local");
54+
const remoteEnvironmentId = EnvironmentId.make("remote");
55+
const projects = [
56+
makeProject({
57+
environmentId: localEnvironmentId,
58+
id: ProjectId.make("scratch-local"),
59+
title: "No project",
60+
workspaceRoot: "/local/scratch",
61+
isScratch: true,
62+
}),
63+
makeProject({
64+
environmentId: remoteEnvironmentId,
65+
id: ProjectId.make("scratch-remote"),
66+
title: "No project",
67+
workspaceRoot: "/remote/scratch",
68+
isScratch: true,
69+
}),
70+
makeProject({
71+
environmentId: remoteEnvironmentId,
72+
id: ProjectId.make("ordinary"),
73+
title: "No project",
74+
}),
75+
];
76+
const threads = projects.map((project) =>
77+
makeThread({
78+
environmentId: project.environmentId,
79+
projectId: project.id,
80+
id: ThreadId.make(`thread-${project.id}`),
81+
title: project.id,
82+
}),
83+
);
84+
const scopes = buildHomeProjectScopes({
85+
projects,
86+
environmentId: null,
87+
projectGroupingMode: "separate",
88+
});
89+
expect(scopes).toHaveLength(2);
90+
const scratchScope = scopes.find((scope) => scope.representative.isScratch)!;
91+
const filtered = buildThreadListV2Items({
92+
threads,
93+
environmentId: null,
94+
projectRefs: scratchScope.projectRefs,
95+
searchQuery: "",
96+
now: "2026-06-01T00:00:00.000Z",
97+
});
98+
expect(filtered.items.map((item) => item.thread.id).sort()).toEqual(
99+
threads
100+
.slice(0, 2)
101+
.map((thread) => thread.id)
102+
.sort(),
103+
);
104+
const remoteScopes = buildHomeProjectScopes({
105+
projects,
106+
environmentId: remoteEnvironmentId,
107+
projectGroupingMode: "separate",
108+
});
109+
const remoteScratch = remoteScopes.find((scope) => scope.representative.isScratch)!;
110+
expect(remoteScratch.key).toBe(scratchScope.key);
111+
expect(remoteScratch.projectRefs).toEqual([
112+
{ environmentId: remoteEnvironmentId, projectId: projects[1]!.id },
113+
]);
114+
expect(
115+
buildThreadListV2Items({
116+
threads,
117+
environmentId: remoteEnvironmentId,
118+
projectRefs: remoteScratch.projectRefs,
119+
searchQuery: "",
120+
now: "2026-06-01T00:00:00.000Z",
121+
}).items.map((item) => item.thread.id),
122+
).toEqual([threads[1]!.id]);
123+
});
124+
51125
it("builds one v2 scope for the same repository across environments", () => {
52126
const localEnvironmentId = EnvironmentId.make("environment-local");
53127
const remoteEnvironmentId = EnvironmentId.make("environment-remote");

‎apps/mobile/src/features/home/homeThreadList.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export function buildHomeProjectScopes(input: {
5050
);
5151
return buildProjectGroups({
5252
projects,
53+
groupScratchProjects: true,
5354
settings: {
5455
sidebarProjectGroupingMode: input.projectGroupingMode,
5556
sidebarProjectGroupingOverrides: {},

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useAndroidControlSizing } from "../../components/useAndroidControlSizing";
2+
import { resolveScratchProjectScopeKey } from "@t3tools/client-runtime/state/project-grouping";
23
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
34
import { computeThreadMoveAvailability } from "./threadOrder";
45
import type {
@@ -206,7 +207,16 @@ function ThreadNavigationSidebarPane(
206207
() => new Set(threadSearch.matches.map(threadSearchMatchKey)),
207208
[threadSearch.matches],
208209
);
209-
const selectedProjectKey = options.selectedProjectKey;
210+
const projectScopeKey = options.selectedProjectKey;
211+
const selectedProjectKey = resolveScratchProjectScopeKey(projectScopeKey, projects, {
212+
sidebarProjectGroupingMode: options.projectGroupingMode,
213+
sidebarProjectGroupingOverrides: {},
214+
});
215+
useEffect(() => {
216+
if (selectedProjectKey !== projectScopeKey) {
217+
setSelectedProjectKey(selectedProjectKey);
218+
}
219+
}, [projectScopeKey, selectedProjectKey, setSelectedProjectKey]);
210220
const projectScopes = useMemo(
211221
() =>
212222
buildHomeProjectScopes({

‎apps/mobile/src/state/projects.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { createProjectEnvironmentAtoms } from "@t3tools/client-runtime/state/pro
44
import { environmentCatalog } from "../connection/catalog";
55
import { connectionAtomRuntime } from "../connection/runtime";
66
import { environmentSnapshotAtom } from "./shell";
7+
import { serverEnvironment } from "./server";
78

89
export const environmentProjects = createEnvironmentProjectAtoms({
910
catalogValueAtom: environmentCatalog.catalogValueAtom,
1011
snapshotAtom: environmentSnapshotAtom,
12+
serverConfigValueAtom: serverEnvironment.configValueAtom,
1113
});
1214
export const projectEnvironment = createProjectEnvironmentAtoms(connectionAtomRuntime, {
1315
projectAtom: environmentProjects.projectAtom,

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

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type EnvironmentId } from "@t3tools/contracts";
1+
import { type EnvironmentId, type ScopedProjectRef } from "@t3tools/contracts";
22
import { ThreadHoverCard, ThreadHoverCardPopup } from "./ThreadHoverCard";
33
import { CollapsibleSectionHeader } from "./ui/collapsible-section-header";
44
import { setThreadChangeRequestSnapshot } from "./ThreadStatusIndicators";
@@ -129,6 +129,8 @@ import { getProjectOrderKey, selectProjectGroupingSettings } from "../logicalPro
129129
import {
130130
buildSidebarProjectSnapshots,
131131
projectGroupsSpanEnvironments,
132+
resolveSidebarProjectScopeKey,
133+
getSidebarProjectSettingsKey,
132134
type SidebarProjectSnapshot,
133135
} from "../sidebarProjectGrouping";
134136
import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
@@ -158,6 +160,7 @@ import {
158160
useThreadShells,
159161
} from "../state/entities";
160162
import { environmentServerConfigsAtom, primaryServerKeybindingsAtom } from "../state/server";
163+
import { environmentProjects } from "../state/projects";
161164
import { vcsEnvironment } from "../state/vcs";
162165
import { threadEnvironment } from "../state/threads";
163166
import { useEnvironmentQuery } from "../state/query";
@@ -2562,6 +2565,7 @@ export default function Sidebar() {
25622565
() =>
25632566
buildSidebarProjectSnapshots({
25642567
projects: sidebarProjectSortOrder === "manual" ? orderedProjects : projects,
2568+
groupScratchProjects: true,
25652569
settings: projectGroupingSettings,
25662570
primaryEnvironmentId,
25672571
resolveEnvironmentLabel: (environmentId) => environmentLabelById.get(environmentId) ?? null,
@@ -2625,8 +2629,17 @@ export default function Sidebar() {
26252629
// The selection lives in the persisted UI store next to the other sidebar
26262630
// project preferences, so routes that unmount the sidebar (Settings) and
26272631
// app restarts keep it.
2628-
const projectScopeKey = useUiStateStore((store) => store.sidebarProjectScopeKey);
2632+
const persistedProjectScopeKey = useUiStateStore((store) => store.sidebarProjectScopeKey);
26292633
const setProjectScopeKey = useUiStateStore((store) => store.setSidebarProjectScopeKey);
2634+
const projectScopeKey = useMemo(
2635+
() =>
2636+
resolveSidebarProjectScopeKey({
2637+
groups: projectGroups,
2638+
key: persistedProjectScopeKey,
2639+
settings: projectGroupingSettings,
2640+
}),
2641+
[persistedProjectScopeKey, projectGroups, projectGroupingSettings],
2642+
);
26302643
// {value, label} items let Base UI drive the combobox selection contract
26312644
// while the popup search filters the same collection.
26322645
const projectScopeItems = useMemo(
@@ -2709,15 +2722,28 @@ export default function Sidebar() {
27092722
),
27102723
[scopedProjectGroup],
27112724
);
2712-
// A persisted scope whose project is gone falls back to all projects, but
2713-
// only after every catalog environment has a live project snapshot. Cached
2714-
// or disconnected environments cannot establish that the project is gone.
2725+
// Configs identify scratch projects, so both they and live project snapshots
2726+
// must arrive before a persisted scope can be considered missing.
27152727
const allProjectSnapshotsReady = useAllEnvironmentProjectSnapshotsReady();
2728+
const allProjectConfigsReady = useAtomValue(environmentProjects.projectConfigsReadyAtom);
27162729
useEffect(() => {
2717-
if (projectScopeKey !== null && allProjectSnapshotsReady && scopedProjectGroup === null) {
2718-
setProjectScopeKey(null);
2730+
const nextKey = resolveSidebarProjectScopeKey({
2731+
groups: projectGroups,
2732+
key: persistedProjectScopeKey,
2733+
settings: projectGroupingSettings,
2734+
canClearMissingScope: allProjectSnapshotsReady && allProjectConfigsReady,
2735+
});
2736+
if (nextKey !== persistedProjectScopeKey) {
2737+
setProjectScopeKey(nextKey);
27192738
}
2720-
}, [allProjectSnapshotsReady, projectScopeKey, scopedProjectGroup, setProjectScopeKey]);
2739+
}, [
2740+
allProjectConfigsReady,
2741+
allProjectSnapshotsReady,
2742+
persistedProjectScopeKey,
2743+
projectGroups,
2744+
projectGroupingSettings,
2745+
setProjectScopeKey,
2746+
]);
27212747
// Count-only subscription: the parent needs "are there draft rows" for the
27222748
// empty state, while SidebarDraftBlock owns the per-keystroke content
27232749
// subscription. Selecting a number keeps typing in a draft composer from
@@ -2751,16 +2777,23 @@ export default function Sidebar() {
27512777
}, [clearSelection, projectScopeKey]);
27522778

27532779
const openProjectSettings = useCallback(
2754-
(projectGroup: SidebarProjectSnapshot) => {
2780+
(projectGroup: SidebarProjectSnapshot, projectRef?: ScopedProjectRef) => {
27552781
if (isMobile) {
27562782
setOpenMobile(false);
27572783
}
27582784
void router.navigate({
27592785
to: "/projects/$projectKey",
2760-
params: { projectKey: projectGroup.projectKey },
2786+
params: {
2787+
projectKey: getSidebarProjectSettingsKey(
2788+
projectGroup,
2789+
projectGroupingSettings,
2790+
projects,
2791+
projectRef,
2792+
),
2793+
},
27612794
});
27622795
},
2763-
[isMobile, router, setOpenMobile],
2796+
[isMobile, projectGroupingSettings, projects, router, setOpenMobile],
27642797
);
27652798
// Anchor for the scope popup: the header search field, not its icon trigger.
27662799
const headerSearchRef = useRef<HTMLDivElement | null>(null);
@@ -4579,7 +4612,11 @@ export default function Sidebar() {
45794612
if (clicked._tag === "Failure") return;
45804613
switch (clicked.value) {
45814614
case "project-settings":
4582-
if (projectGroup) openProjectSettings(projectGroup);
4615+
if (projectGroup)
4616+
openProjectSettings(projectGroup, {
4617+
environmentId: session.environmentId,
4618+
projectId: session.projectId,
4619+
});
45834620
return;
45844621
case "copy-path":
45854622
if (workspacePath) copyPathToClipboard(workspacePath, { path: workspacePath });
@@ -4703,7 +4740,11 @@ export default function Sidebar() {
47034740
}
47044741
return;
47054742
case "project-settings":
4706-
if (threadProjectGroup) openProjectSettings(threadProjectGroup);
4743+
if (threadProjectGroup)
4744+
openProjectSettings(threadProjectGroup, {
4745+
environmentId: threadRef.environmentId,
4746+
projectId: thread.projectId,
4747+
});
47074748
return;
47084749
case "new-thread-on-branch": {
47094750
// Explicit branch carry-over: reuse the thread's worktree when it

0 commit comments

Comments
 (0)