mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
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:
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user