Skip to content

Commit f39f48f

Browse files
authored
fix(ui): hiding a catalog makes its adopted sessions vanish from the entire sidebar (#123481)
* fix(ui): hiding a catalog no longer makes its adopted sessions vanish everywhere The adopted-key exclusion set was computed from the unfiltered catalog list while the renderer shows only visible catalogs (hidden ids filtered; none under the Archived filter). Hiding a catalog therefore removed its adopted sessions — possibly running, unread, or selected — from the entire sidebar with no row anywhere. One visibleSessionCatalogs() projection now feeds both the renderer and the exclusion; the subclass's duplicate filter is deleted. * refactor: fold sidebar catalog projection into its owner module The visibleSessionCatalogs projection and adopted-PR-row merge pushed app-sidebar-session-navigation.ts over the 700-line lint cap. Move the projection predicate to app-sidebar-session-catalogs.ts (the catalog helper owner) and the PR-row merge to the navigation-logic module, inlining the single-caller passthrough into the indicators controller.
1 parent f49eaf8 commit f39f48f

6 files changed

Lines changed: 88 additions & 26 deletions

File tree

‎ui/src/components/app-sidebar-session-catalogs.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ export function adoptedCatalogSessionKeys(catalogs: readonly SessionCatalog[]):
4343
return keys;
4444
}
4545

46+
/** Catalogs the sidebar actually renders. Adopted-key exclusion must read this
47+
same projection: excluding a key whose catalog is hidden (or whose section
48+
the archived filter suppresses) deletes the session from the entire sidebar
49+
with no row anywhere. */
50+
export function visibleSessionCatalogProjection(
51+
catalogs: readonly SessionCatalog[],
52+
hiddenCatalogIds: ReadonlySet<string>,
53+
archivedFilter: boolean,
54+
): SessionCatalog[] {
55+
return archivedFilter ? [] : catalogs.filter((catalog) => !hiddenCatalogIds.has(catalog.id));
56+
}
57+
4658
export function visibleCatalogHosts(
4759
hosts: readonly SessionCatalogHost[],
4860
creatorId?: string | null,

‎ui/src/components/app-sidebar-session-navigation-logic.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,28 @@ export function applySidebarSessionCreatorFilter(input: {
582582
activeCreatorId,
583583
};
584584
}
585+
586+
/** Merge adopted catalog sessions into the visible PR-indicator rows so an
587+
adopted session hidden from the regular list still surfaces its PR state. */
588+
export function mergeAdoptedSessionPullRequestRows(input: {
589+
rows: SidebarRecentSession[];
590+
adopted: ReadonlySet<string>;
591+
sessionsResult: SessionsListResult | null;
592+
sessionRowsByAgent: Record<string, GatewaySessionRow[]>;
593+
navigationState: SidebarSessionNavigationState;
594+
}): SidebarRecentSession[] {
595+
if (input.adopted.size === 0) {
596+
return input.rows;
597+
}
598+
const byKey = new Map(input.rows.map((row) => [row.key, row]));
599+
const liveRows = [
600+
...(input.sessionsResult?.sessions ?? []),
601+
...Object.values(input.sessionRowsByAgent).flat(),
602+
];
603+
for (const row of liveRows) {
604+
if (input.adopted.has(row.key) && !byKey.has(row.key)) {
605+
byKey.set(row.key, input.navigationState.toSidebarSession(row));
606+
}
607+
}
608+
return [...byKey.values()];
609+
}

‎ui/src/components/app-sidebar-session-navigation.ts‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import {
2222
resolveUiDefaultAgentId,
2323
} from "../lib/sessions/session-key.ts";
2424
import { AppSidebarBase } from "./app-sidebar-base.ts";
25-
import { adoptedCatalogSessionKeys } from "./app-sidebar-session-catalogs.ts";
25+
import {
26+
adoptedCatalogSessionKeys,
27+
visibleSessionCatalogProjection,
28+
} from "./app-sidebar-session-catalogs.ts";
2629
import {
2730
applySidebarSessionCreatorFilter,
2831
buildReconciledSidebarZone,
@@ -35,6 +38,7 @@ import {
3538
findSidebarMainSessionRow,
3639
findProjectedSidebarSession,
3740
latestVisibleAgentSessionRow,
41+
mergeAdoptedSessionPullRequestRows,
3842
partitionSidebarVisibleSections,
3943
promoteSidebarSessionCreatedOrder,
4044
resolveSidebarAgentChipSubtitle,
@@ -46,6 +50,7 @@ import {
4650
} from "./app-sidebar-session-navigation-logic.ts";
4751
import { SessionPullRequestIndicatorsController } from "./app-sidebar-session-pr-indicators.ts";
4852
import { projectSessionTree } from "./app-sidebar-session-tree.ts";
53+
import { loadStoredHiddenSessionCatalogIds } from "./app-sidebar-session-types.ts";
4954
import {
5055
loadStoredSidebarSessionStatusFilter,
5156
loadStoredSidebarSessionsGrouping,
@@ -68,7 +73,14 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
6873
readonly sessionData = new SessionDataController(this);
6974
private readonly sessionPullRequestIndicators = new SessionPullRequestIndicatorsController(this, {
7075
getConnected: () => this.connected,
71-
getRows: () => this.visibleSessionPullRequestRows(),
76+
getRows: () =>
77+
mergeAdoptedSessionPullRequestRows({
78+
rows: this.visibleSessionRowsInOrder(),
79+
adopted: adoptedCatalogSessionKeys(this.visibleSessionCatalogs()),
80+
sessionsResult: this.sessionData.sessionsResult,
81+
sessionRowsByAgent: this.sessionData.sessionRowsByAgent,
82+
navigationState: this.getSessionNavigationState(),
83+
}),
7284
getSelectedAgentId: () => this.selectedAgentIdForSessions(),
7385
getGateway: () => this.context?.gateway,
7486
});
@@ -122,6 +134,14 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
122134
@state() sessionsShowSystem = loadStoredSidebarSessionsShowSystem();
123135
@state() sessionsStatusFilter: SidebarSessionStatusFilter =
124136
loadStoredSidebarSessionStatusFilter();
137+
@state() hiddenSessionCatalogIds = loadStoredHiddenSessionCatalogIds();
138+
139+
visibleSessionCatalogs = () =>
140+
visibleSessionCatalogProjection(
141+
this.sessionData.sessionCatalogs,
142+
this.hiddenSessionCatalogIds,
143+
this.sessionsStatusFilter === "archived",
144+
);
125145

126146
private sessionSelectionAnchor: string | null = null;
127147
private collapsedActiveRouteKey: string | null = null;
@@ -161,25 +181,6 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
161181
return this.sessionPullRequestIndicators.state(sessionKey, worktreeId);
162182
}
163183

164-
private visibleSessionPullRequestRows(): SidebarRecentSession[] {
165-
const rows = this.visibleSessionRowsInOrder();
166-
const adopted = adoptedCatalogSessionKeys(this.sessionData.sessionCatalogs);
167-
if (adopted.size === 0) {
168-
return rows;
169-
}
170-
const byKey = new Map(rows.map((row) => [row.key, row]));
171-
const liveRows = [
172-
...(this.sessionData.sessionsResult?.sessions ?? []),
173-
...Object.values(this.sessionData.sessionRowsByAgent).flat(),
174-
];
175-
for (const row of liveRows) {
176-
if (adopted.has(row.key) && !byKey.has(row.key)) {
177-
byKey.set(row.key, this.getSessionNavigationState().toSidebarSession(row));
178-
}
179-
}
180-
return [...byKey.values()];
181-
}
182-
183184
override updated(changedProperties: PropertyValues<this>) {
184185
super.updated(changedProperties);
185186
const selectedId = this.sessionCreatorFilterId;
@@ -596,7 +597,7 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
596597
protected selectedAgentSessionRows(
597598
navigationState: SidebarSessionNavigationState,
598599
): SidebarRecentSession[] {
599-
const adopted = adoptedCatalogSessionKeys(this.sessionData.sessionCatalogs);
600+
const adopted = adoptedCatalogSessionKeys(this.visibleSessionCatalogs());
600601
const selected = this.expandedAgentId();
601602
const loadedAgentId = normalizeAgentId(this.sessionData.sessionsAgentId ?? "");
602603
const routeAgentId = normalizeAgentId(navigationState.selectedAgentId);

‎ui/src/components/app-sidebar.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class AppSidebar extends AppSidebarSessionNavigationElement implements SessionLi
107107
);
108108

109109
@state() catalogProjectGrouping = loadStoredSidebarCatalogGrouping();
110-
@state() hiddenSessionCatalogIds = loadStoredHiddenSessionCatalogIds();
111110

112111
constructor() {
113112
super();
@@ -416,9 +415,7 @@ class AppSidebar extends AppSidebarSessionNavigationElement implements SessionLi
416415
...Object.values(this.sessionData.sessionRowsByAgent).flat(),
417416
];
418417
const { sections: allSections } = this.zonedVisibleSections(visibleSessions);
419-
const catalogs = this.sessionData.sessionCatalogs.filter(
420-
(catalog) => !this.hiddenSessionCatalogIds.has(catalog.id),
421-
);
418+
const catalogs = this.visibleSessionCatalogs();
422419
const visibleCatalogIds = new Set(catalogs.map((catalog) => catalog.id));
423420
const sections = allSections.filter(
424421
(section) => !section.id.startsWith("catalog:") || visibleCatalogIds.has(section.id.slice(8)),

‎ui/src/test-helpers/app-sidebar-cases/interactions.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,4 +711,30 @@ describe("AppSidebar catalog session rows", () => {
711711
vi.useRealTimers();
712712
}
713713
});
714+
715+
it("returns an adopted session to the thread list when its catalog is hidden", async () => {
716+
vi.useFakeTimers();
717+
try {
718+
const { sidebar } = await mountWithCatalog(
719+
catalogList([
720+
{
721+
threadId: "thread-1",
722+
name: "Release checklist",
723+
sessionKey: "agent:main:adopted-codex",
724+
},
725+
]),
726+
["agent:main:main", "agent:main:adopted-codex"],
727+
);
728+
// Hiding the catalog removes the live row; the adopted key must fall
729+
// back to a regular thread row, not vanish from the entire sidebar.
730+
sidebar.hiddenSessionCatalogIds = new Set(["codex"]);
731+
await sidebar.updateComplete;
732+
733+
const rows = [...sidebar.querySelectorAll('[data-session-key="agent:main:adopted-codex"]')];
734+
expect(rows).toHaveLength(1);
735+
expect(rows[0]?.closest('[data-session-section="catalog:codex"]')).toBeNull();
736+
} finally {
737+
vi.useRealTimers();
738+
}
739+
});
714740
});

‎ui/src/test-helpers/app-sidebar.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const sidebarSessionGatewayBindings = new WeakMap<
4545
>();
4646

4747
export type SidebarLifecycleState = HTMLElement & {
48+
hiddenSessionCatalogIds: ReadonlySet<string>;
4849
activeRouteId?: string;
4950
activeWorkboardBoardId: string;
5051
enabledRouteIds?: readonly NavigationRouteId[];

0 commit comments

Comments
 (0)