Skip to content

Commit 0fa21a1

Browse files
fix(web): preserve session preview folding (#666)
1 parent c417330 commit 0fa21a1

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

web/src/components/SessionList.test.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ describe('session list search helpers', () => {
102102
})
103103

104104
describe('getVisibleSessionPreview', () => {
105-
it('keeps selected and active sessions inside the collapsed preview without promoting them', () => {
105+
it('keeps selected and pending sessions inside the collapsed preview without promoting them', () => {
106106
const sessions = Array.from({ length: 6 }, (_, index) => makeSession({
107107
id: `s-${index + 1}`,
108-
active: index === 4,
108+
pendingRequestsCount: index === 4 ? 1 : 0,
109109
metadata: { path: '/work/hapi' },
110110
updatedAt: 100 - index
111111
}))
@@ -118,6 +118,19 @@ describe('getVisibleSessionPreview', () => {
118118
expect(preview.map(session => session.id)).toEqual(['s-1', 's-5', 's-6'])
119119
})
120120

121+
it('does not exceed the limit just because many sessions are active', () => {
122+
const sessions = Array.from({ length: 6 }, (_, index) => makeSession({
123+
id: `s-${index + 1}`,
124+
active: true,
125+
metadata: { path: '/work/hapi' },
126+
updatedAt: 100 - index
127+
}))
128+
129+
const preview = getVisibleSessionPreview(sessions, { limit: 4 })
130+
131+
expect(preview.map(session => session.id)).toEqual(['s-1', 's-2', 's-3', 's-4'])
132+
})
133+
121134
it('does not move an already-visible selected session to the top', () => {
122135
const sessions = Array.from({ length: 6 }, (_, index) => makeSession({
123136
id: `s-${index + 1}`,
@@ -145,7 +158,7 @@ describe('getVisibleSessionPreview', () => {
145158

146159

147160
describe('expandSelectedSessionCollapseOverrides', () => {
148-
it('expands collapsed project, machine, and session preview overrides for selected sessions', () => {
161+
it('expands collapsed project and machine, but preserves session preview folding', () => {
149162
const overrides = new Map<string, boolean>([
150163
['machine-1::/work/hapi', true],
151164
['sessions::machine-1::/work/hapi', true],
@@ -158,18 +171,18 @@ describe('expandSelectedSessionCollapseOverrides', () => {
158171
})
159172

160173
expect(result.has('machine-1::/work/hapi')).toBe(false)
161-
expect(result.get('sessions::machine-1::/work/hapi')).toBe(false)
174+
expect(result.get('sessions::machine-1::/work/hapi')).toBe(true)
162175
expect(result.has('machine::machine-1')).toBe(false)
163176
})
164177

165-
it('sets missing session preview override to expanded', () => {
178+
it('leaves missing session preview override unset', () => {
166179
const overrides = new Map<string, boolean>()
167180

168181
const result = expandSelectedSessionCollapseOverrides(overrides, {
169182
key: 'machine-1::/work/hapi',
170183
machineId: 'machine-1'
171184
})
172185

173-
expect(result.get('sessions::machine-1::/work/hapi')).toBe(false)
186+
expect(result.has('sessions::machine-1::/work/hapi')).toBe(false)
174187
})
175188
})

web/src/components/SessionList.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ export function expandSelectedSessionCollapseOverrides(
191191
changed = true
192192
}
193193

194-
// Session preview keys use inverted semantics: false = expanded, true/missing = collapsed.
195-
const sessionPreviewKey = `sessions::${group.key}`
196-
if (overrides.get(sessionPreviewKey) !== false) {
197-
next.set(sessionPreviewKey, false)
198-
changed = true
199-
}
200-
201194
const machineKey = `machine::${group.machineId ?? UNKNOWN_MACHINE_ID}`
202195
if (overrides.has(machineKey) && overrides.get(machineKey)) {
203196
next.delete(machineKey)
@@ -438,7 +431,7 @@ export function getVisibleSessionPreview(
438431

439432
const requiredIds = new Set<string>()
440433
for (const session of sessions) {
441-
if (session.active) requiredIds.add(session.id)
434+
if (session.pendingRequestsCount > 0) requiredIds.add(session.id)
442435
}
443436
if (options.selectedSessionId && sessions.some(session => session.id === options.selectedSessionId)) {
444437
requiredIds.add(options.selectedSessionId)

0 commit comments

Comments
 (0)