fix(web): polish session search and ordering (#551)

Align session search controls, hide the native search clear button, and keep collapsed session previews ordered by activity while still expanding previews for the selected session.
This commit is contained in:
CoColate
2026-05-03 12:51:58 +08:00
committed by GitHub
parent d9d7ed6699
commit 02bc206f8a
2 changed files with 71 additions and 29 deletions
+34 -4
View File
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import type { SessionSummary } from '@/types/api'
import { deduplicateSessionsByAgentId, getVisibleSessionPreview, normalizeSearch, sessionMatchesQuery } from './SessionList'
import { deduplicateSessionsByAgentId, expandSelectedSessionCollapseOverrides, getVisibleSessionPreview, normalizeSearch, sessionMatchesQuery } from './SessionList'
function makeSession(overrides: Partial<SessionSummary> & { id: string }): SessionSummary {
return {
@@ -102,7 +102,7 @@ describe('session list search helpers', () => {
})
describe('getVisibleSessionPreview', () => {
it('keeps selected and active sessions inside the collapsed preview', () => {
it('does not promote the selected session in collapsed previews', () => {
const sessions = Array.from({ length: 6 }, (_, index) => makeSession({
id: `s-${index + 1}`,
active: index === 4,
@@ -111,11 +111,10 @@ describe('getVisibleSessionPreview', () => {
}))
const preview = getVisibleSessionPreview(sessions, {
selectedSessionId: 's-6',
limit: 3
})
expect(preview.map(session => session.id)).toEqual(['s-6', 's-5', 's-1'])
expect(preview.map(session => session.id)).toEqual(['s-5', 's-1', 's-2'])
})
it('returns all sessions when expanded', () => {
@@ -127,3 +126,34 @@ describe('getVisibleSessionPreview', () => {
expect(getVisibleSessionPreview(sessions, { expanded: true, limit: 2 })).toHaveLength(4)
})
})
describe('expandSelectedSessionCollapseOverrides', () => {
it('expands collapsed project, machine, and session preview overrides for selected sessions', () => {
const overrides = new Map<string, boolean>([
['machine-1::/work/hapi', true],
['sessions::machine-1::/work/hapi', true],
['machine::machine-1', true]
])
const result = expandSelectedSessionCollapseOverrides(overrides, {
key: 'machine-1::/work/hapi',
machineId: 'machine-1'
})
expect(result.has('machine-1::/work/hapi')).toBe(false)
expect(result.get('sessions::machine-1::/work/hapi')).toBe(false)
expect(result.has('machine::machine-1')).toBe(false)
})
it('sets missing session preview override to expanded', () => {
const overrides = new Map<string, boolean>()
const result = expandSelectedSessionCollapseOverrides(overrides, {
key: 'machine-1::/work/hapi',
machineId: 'machine-1'
})
expect(result.get('sessions::machine-1::/work/hapi')).toBe(false)
})
})