Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 3afb4a9

Browse files
shivamhwpjuliusmarmingecodex
authored
Restore grouped project filtering in Sidebar V2 (pingdotgg#4282)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
1 parent 315b273 commit 3afb4a9

5 files changed

Lines changed: 405 additions & 74 deletions

File tree

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
resolveThreadStatusPill,
2323
shouldNavigateAfterProjectRemoval,
2424
shouldClearThreadSelectionOnMouseDown,
25+
sortLogicalProjectsForSidebar,
2526
sortThreadsForSidebarV2,
2627
sortProjectsForSidebar,
2728
sortScopedProjectsForSidebar,
@@ -1353,3 +1354,40 @@ describe("sortScopedProjectsForSidebar", () => {
13531354
]);
13541355
});
13551356
});
1357+
1358+
describe("sortLogicalProjectsForSidebar", () => {
1359+
it("uses saved order only in manual mode and activity order otherwise", () => {
1360+
const olderProjectId = ProjectId.make("project-older");
1361+
const newerProjectId = ProjectId.make("project-newer");
1362+
const projects = [
1363+
{
1364+
...makeProject({ id: olderProjectId, title: "Older project" }),
1365+
projectKey: "logical-older",
1366+
memberProjectRefs: [{ environmentId: localEnvironmentId, projectId: olderProjectId }],
1367+
},
1368+
{
1369+
...makeProject({ id: newerProjectId, title: "Newer project" }),
1370+
projectKey: "logical-newer",
1371+
memberProjectRefs: [{ environmentId: localEnvironmentId, projectId: newerProjectId }],
1372+
},
1373+
];
1374+
const threads = [
1375+
makeThread({
1376+
projectId: olderProjectId,
1377+
updatedAt: "2026-03-09T10:01:00.000Z",
1378+
}),
1379+
makeThread({
1380+
id: ThreadId.make("thread-newer"),
1381+
projectId: newerProjectId,
1382+
updatedAt: "2026-03-09T10:05:00.000Z",
1383+
}),
1384+
];
1385+
1386+
expect(sortLogicalProjectsForSidebar(projects, threads, "manual")).toEqual(projects);
1387+
expect(
1388+
sortLogicalProjectsForSidebar(projects, threads, "updated_at").map(
1389+
(project) => project.projectKey,
1390+
),
1391+
).toEqual(["logical-newer", "logical-older"]);
1392+
});
1393+
});

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ type ScopedSidebarThread = ThreadSortInput & {
3636
archivedAt: string | null;
3737
};
3838

39+
type LogicalSidebarProject = SidebarProject & {
40+
projectKey: string;
41+
memberProjectRefs: readonly {
42+
environmentId: string;
43+
projectId: string;
44+
}[];
45+
};
46+
3947
export type ThreadTraversalDirection = "previous" | "next";
4048

4149
export async function archiveSelectedThreadEntries<
@@ -727,6 +735,44 @@ export function sortProjectsForSidebar<
727735
);
728736
}
729737

738+
export function sortLogicalProjectsForSidebar<
739+
TProject extends LogicalSidebarProject,
740+
TThread extends ScopedSidebarThread,
741+
>(
742+
projects: readonly TProject[],
743+
threads: readonly TThread[],
744+
sortOrder: SidebarProjectSortOrder,
745+
): TProject[] {
746+
const groupKeyByProjectRef = new Map(
747+
projects.flatMap((project) =>
748+
project.memberProjectRefs.map(
749+
(projectRef) =>
750+
[`${projectRef.environmentId}\0${projectRef.projectId}`, project.projectKey] as const,
751+
),
752+
),
753+
);
754+
const threadsByProjectKey = new Map<string, TThread[]>();
755+
for (const thread of threads) {
756+
if (thread.archivedAt !== null) continue;
757+
const projectKey = groupKeyByProjectRef.get(`${thread.environmentId}\0${thread.projectId}`);
758+
if (!projectKey) continue;
759+
const existing = threadsByProjectKey.get(projectKey);
760+
if (existing) {
761+
existing.push(thread);
762+
} else {
763+
threadsByProjectKey.set(projectKey, [thread]);
764+
}
765+
}
766+
767+
return sortProjectsByActivity(
768+
projects,
769+
sortOrder,
770+
(project) => threadsByProjectKey.get(project.projectKey) ?? [],
771+
(left, right) =>
772+
left.title.localeCompare(right.title) || left.projectKey.localeCompare(right.projectKey),
773+
);
774+
}
775+
730776
/**
731777
* Sorts the cross-environment project collection used by landing surfaces.
732778
* Project ids are only unique within an environment, and archived threads

0 commit comments

Comments
 (0)