Skip to content

Commit dce9835

Browse files
t3dotggclaude
andcommitted
fix(web): follow a project to its new group after a grouping change
Changing a checkout's grouping rule changes the group key, which left the settings page on a dead-end message (with no picker at all on mobile). The panel now remembers the last rendered group's members and redirects to whichever group they landed in, falling back to the index auto-select. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 8dab9ed commit dce9835

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,42 @@ export function ProjectSettingsPanel({
149149
? null
150150
: (groups.find((group) => group.projectKey === selectedProjectKey) ?? null);
151151

152+
// Remember the members of the last rendered group so a grouping-rule change
153+
// (which changes the group key) can follow the project to its new group.
154+
const lastSelectionRef = useRef<{ key: string; memberKeys: string[] } | null>(null);
155+
useEffect(() => {
156+
if (!selected) return;
157+
lastSelectionRef.current = {
158+
key: selected.projectKey,
159+
memberKeys: selected.memberProjects.map((member) => member.physicalProjectKey),
160+
};
161+
}, [selected]);
162+
163+
// Recover when the selected key stops matching (regroup, removal, or a
164+
// stale deep link) instead of parking on a dead-end message.
165+
useEffect(() => {
166+
if (selectedProjectKey === null || selected !== null || groups.length === 0) return;
167+
const last = lastSelectionRef.current;
168+
const successor =
169+
last?.key === selectedProjectKey
170+
? (groups.find((group) =>
171+
group.memberProjects.some((member) =>
172+
last.memberKeys.includes(member.physicalProjectKey),
173+
),
174+
) ?? null)
175+
: null;
176+
if (successor) {
177+
void navigate({
178+
to: "/settings/projects/$projectKey",
179+
params: { projectKey: successor.projectKey },
180+
replace: true,
181+
hashScrollIntoView: false,
182+
});
183+
} else {
184+
void navigate({ to: "/settings/projects", replace: true, hashScrollIntoView: false });
185+
}
186+
}, [groups, navigate, selected, selectedProjectKey]);
187+
152188
const selectProject = useCallback(
153189
(projectKey: string) => {
154190
void navigate({
@@ -207,11 +243,7 @@ export function ProjectSettingsPanel({
207243
/>
208244
) : (
209245
<div className="flex flex-1 items-center justify-center p-8 text-sm text-muted-foreground">
210-
{groups.length === 0
211-
? "Add a project from the sidebar to configure it here."
212-
: selectedProjectKey === null
213-
? null
214-
: "This project is gone or was regrouped. Pick one from the list."}
246+
{groups.length === 0 ? "Add a project from the sidebar to configure it here." : null}
215247
</div>
216248
)}
217249
</div>

0 commit comments

Comments
 (0)