History

fix: ignore subagents when sorting sidebar projects

Yusuf007R committed 3 months ago

Commit 13543cd1 parent 97a04be3 files · +70 −3Browse files

Unified · Split

3 files
  1. apps/web/src/components/Sidebar.logic.test.ts +49 −0
  2. apps/web/src/components/Sidebar.logic.ts +19 −1
  3. apps/web/src/components/SidebarV2.tsx +2 −2
apps/web/src/components/Sidebar.logic.test.ts+49−0
@@ -26,6 +26,7 @@ import { · 25 unmodified lines
2626 shouldNavigateAfterProjectRemoval,
2727 shouldClearThreadSelectionOnMouseDown,
2828 sortLogicalProjectsForSidebar,
29+ sortSidebarV2ProjectGroups,
2930 sortSettledThreadsForSidebarV2,
3031 sortThreadsForSidebarV2,
3132 sortScopedProjectsForSidebar,
@@ -1502,3 +1503,51 @@ describe("sortLogicalProjectsForSidebar", () => { · 1470 unmodified lines
15021503 ).toEqual(["logical-newer", "logical-older"]);
15031504 });
15041505 });
1506+
1507+describe("sortSidebarV2ProjectGroups", () => {
1508+ it("does not let a hidden subagent thread reorder projects", () => {
1509+ const olderProjectId = ProjectId.make("project-older");
1510+ const newerProjectId = ProjectId.make("project-newer");
1511+ const olderRootThreadId = ThreadId.make("thread-older-root");
1512+ const projects = [
1513+ {
1514+ ...makeProject({ id: olderProjectId, title: "A older project" }),
1515+ projectKey: "logical-older",
1516+ memberProjectRefs: [{ environmentId: localEnvironmentId, projectId: olderProjectId }],
1517+ },
1518+ {
1519+ ...makeProject({ id: newerProjectId, title: "Z newer project" }),
1520+ projectKey: "logical-newer",
1521+ memberProjectRefs: [{ environmentId: localEnvironmentId, projectId: newerProjectId }],
1522+ },
1523+ ];
1524+ const threads = [
1525+ makeThread({
1526+ id: olderRootThreadId,
1527+ projectId: olderProjectId,
1528+ updatedAt: "2026-03-09T10:01:00.000Z",
1529+ }),
1530+ makeThread({
1531+ id: ThreadId.make("thread-newer-root"),
1532+ projectId: newerProjectId,
1533+ updatedAt: "2026-03-09T10:05:00.000Z",
1534+ }),
1535+ makeThread({
1536+ id: ThreadId.make("thread-hidden-subagent"),
1537+ projectId: olderProjectId,
1538+ updatedAt: "2026-03-09T10:10:00.000Z",
1539+ lineage: {
1540+ rootThreadId: olderRootThreadId,
1541+ parentThreadId: olderRootThreadId,
1542+ relationshipToParent: "subagent",
1543+ },
1544+ }),
1545+ ];
1546+
1547+ expect(
1548+ sortSidebarV2ProjectGroups(projects, threads, "updated_at").map(
1549+ (project) => project.projectKey,
1550+ ),
1551+ ).toEqual(["logical-newer", "logical-older"]);
1552+ });
1553+});
apps/web/src/components/Sidebar.logic.ts+19−1
@@ -97,7 +97,10 @@ export function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "line · 96 unmodified lines
9797 }
9898
9999 export function filterSidebarV2VisibleThreads<
100− T extends Pick<SidebarThreadSummary, "archivedAt" | "environmentId" | "lineage" | "projectId">,
100+ T extends Pick<SidebarThreadSummary, "archivedAt" | "lineage"> & {
101+ environmentId: string;
102+ projectId: string;
103+ },
101104 >(threads: readonly T[], scopedProjectKeys: ReadonlySet<string> | null): T[] {
102105 return threads.filter(
103106 (thread) =>
@@ -827,6 +830,21 @@ export function sortLogicalProjectsForSidebar< · 723 unmodified lines
827830 );
828831 }
829832
833+export function sortSidebarV2ProjectGroups<
834+ TProject extends LogicalSidebarProject,
835+ TThread extends ScopedSidebarThread & Pick<SidebarThreadSummary, "lineage">,
836+>(
837+ projects: readonly TProject[],
838+ threads: readonly TThread[],
839+ sortOrder: SidebarProjectSortOrder,
840+): TProject[] {
841+ return sortLogicalProjectsForSidebar(
842+ projects,
843+ filterSidebarV2VisibleThreads(threads, null),
844+ sortOrder,
845+ );
846+}
847+
830848 /**
831849 * Sorts the cross-environment project collection used by landing surfaces.
832850 * Project ids are only unique within an environment, and archived threads
apps/web/src/components/SidebarV2.tsx+2−2
@@ -112,7 +112,7 @@ import { · 111 unmodified lines
112112 resolveSidebarV2Status,
113113 resolveWorkingStartedAt,
114114 shouldNavigateAfterProjectRemoval,
115− sortLogicalProjectsForSidebar,
115+ sortSidebarV2ProjectGroups,
116116 sortSettledThreadsForSidebarV2,
117117 sortThreadsForSidebarV2,
118118 } from "./Sidebar.logic";
@@ -1104,7 +1104,7 @@ export default function SidebarV2() { · 985 unmodified lines
11041104 ],
11051105 );
11061106 const projectGroups = useMemo(
1107− () => sortLogicalProjectsForSidebar(unsortedProjectGroups, threads, sidebarProjectSortOrder),
1107+ () => sortSidebarV2ProjectGroups(unsortedProjectGroups, threads, sidebarProjectSortOrder),
11081108 [sidebarProjectSortOrder, threads, unsortedProjectGroups],
11091109 );
11101110 const serverProviders = useAtomValue(primaryServerProvidersAtom);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t