fix(web): keep session sidebar stable after selection (#1173)

This commit is contained in:
SSU-WEI HUANG
2026-07-26 15:02:52 +08:00
committed by GitHub
parent bd5e87898a
commit c305c5ce31
3 changed files with 33 additions and 7 deletions
@@ -321,4 +321,29 @@ describe('SessionList collapse behavior', () => {
expect(getProjectPanel().getAttribute('data-open')).toBe('true')
})
})
it('keeps the previous selected path open when selection moves', async () => {
const sessions = [
makeSession({
id: 'session-first',
updatedAt: 100,
metadata: { path: '/work/first', name: 'First task', flavor: 'codex' },
}),
makeSession({
id: 'session-second',
updatedAt: 90,
metadata: { path: '/work/second', name: 'Second task', flavor: 'codex' },
})
]
const { rerender } = render(renderSessionList(sessions, 'session-first'))
const firstPanel = screen.getByTitle('/work/first').nextElementSibling
expect(firstPanel?.getAttribute('data-open')).toBe('true')
rerender(renderSessionList(sessions, 'session-second'))
await waitFor(() => {
expect(firstPanel?.getAttribute('data-open')).toBe('true')
})
})
})
+2 -2
View File
@@ -441,9 +441,9 @@ describe('expandSelectedSessionCollapseOverrides', () => {
machineId: 'machine-1'
})
expect(result.has('machine-1::/work/hapi')).toBe(false)
expect(result.get('machine-1::/work/hapi')).toBe(false)
expect(result.get('sessions::machine-1::/work/hapi')).toBe(true)
expect(result.has('machine::machine-1')).toBe(false)
expect(result.get('machine::machine-1')).toBe(false)
})
it('leaves missing session preview override unset', () => {
+6 -5
View File
@@ -283,15 +283,16 @@ export function expandSelectedSessionCollapseOverrides(
const next = new Map(overrides)
let changed = false
// Expand project group if collapsed. Project and machine keys use true = collapsed.
if (overrides.has(group.key) && overrides.get(group.key)) {
next.delete(group.key)
// Keep auto-expanded paths open after selection moves so content above the
// clicked row does not collapse and displace the sidebar viewport.
if (overrides.get(group.key) !== false) {
next.set(group.key, false)
changed = true
}
const machineKey = `machine::${group.machineId ?? UNKNOWN_MACHINE_ID}`
if (overrides.has(machineKey) && overrides.get(machineKey)) {
next.delete(machineKey)
if (overrides.get(machineKey) !== false) {
next.set(machineKey, false)
changed = true
}