Centralize AI Vault view defaults and fix reset state alignment

Consolidate the default values for sorting, grouping, and hiding empty
sessions into a single place. This prevents inconsistencies between the
initial state, the badge count adjustment checks, and the "Reset" view
action, where the reset previously toggled hideEmptySessions to true
contrary to the initial false value.
This commit is contained in:
Jinjing
2026-07-08 18:04:42 -07:00
parent 9d5c4e971a
commit 8519c5b05c
3 changed files with 102 additions and 12 deletions
@@ -20,6 +20,12 @@ import {
getRestorableAiVaultScope,
normalizeAiVaultScopeForContext
} from './ai-vault-scope-state'
import {
countAiVaultViewAdjustments,
DEFAULT_AI_VAULT_GROUP,
DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS,
DEFAULT_AI_VAULT_SORT
} from './ai-vault-view-defaults'
import { buildAiVaultProjectContext } from './ai-vault-session-projects'
import {
resolveAiVaultSessionResumeActions,
@@ -68,9 +74,9 @@ export default function AiVaultPanel(): React.JSX.Element {
useAiVaultOriginalPaneActions()
const [query, setQuery] = useState('')
const [scope, setScope] = useState<AiVaultScope>(DEFAULT_AI_VAULT_SCOPE)
const [sort, setSort] = useState<AiVaultSort>('updated')
const [group, setGroup] = useState<AiVaultGroup>('project')
const [hideEmptySessions, setHideEmptySessions] = useState(false)
const [sort, setSort] = useState<AiVaultSort>(DEFAULT_AI_VAULT_SORT)
const [group, setGroup] = useState<AiVaultGroup>(DEFAULT_AI_VAULT_GROUP)
const [hideEmptySessions, setHideEmptySessions] = useState(DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS)
const [agents, setAgents] = useState<AiVaultAgent[]>([...AI_VAULT_AGENTS])
const [collapsedGroups, setCollapsedGroups] = useState<Set<string>>(() => new Set())
const userChangedScopeRef = useRef(false)
@@ -155,12 +161,12 @@ export default function AiVaultPanel(): React.JSX.Element {
targetState: resumeTargetState,
agentCmdOverrides
})
const hasAllAgentsSelected = agents.length === AI_VAULT_AGENTS.length
const viewAdjustmentCount =
(hasAllAgentsSelected ? 0 : 1) +
(sort === 'updated' ? 0 : 1) +
(group === 'project' ? 0 : 1) +
(hideEmptySessions ? 1 : 0)
const viewAdjustmentCount = countAiVaultViewAdjustments({
agents,
sort,
group,
hideEmptySessions
})
// Workspace is the preferred default, but unavailable context still falls back to All.
useEffect(() => {
@@ -286,9 +292,9 @@ export default function AiVaultPanel(): React.JSX.Element {
const resetViewOptions = useCallback(() => {
setAgents([...AI_VAULT_AGENTS])
setSort('updated')
setGroup('project')
setHideEmptySessions(true)
setSort(DEFAULT_AI_VAULT_SORT)
setGroup(DEFAULT_AI_VAULT_GROUP)
setHideEmptySessions(DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS)
}, [])
const handleScopeChange = useCallback((nextScope: AiVaultScope) => {
@@ -0,0 +1,58 @@
import { describe, expect, it } from 'vitest'
import { AI_VAULT_AGENTS } from '../../../../shared/ai-vault-types'
import {
countAiVaultViewAdjustments,
DEFAULT_AI_VAULT_GROUP,
DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS,
DEFAULT_AI_VAULT_SORT
} from './ai-vault-view-defaults'
describe('ai-vault-view-defaults', () => {
it('shows empty sessions by default', () => {
expect(DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS).toBe(false)
})
it('counts zero adjustments for the default view', () => {
expect(
countAiVaultViewAdjustments({
agents: [...AI_VAULT_AGENTS],
sort: DEFAULT_AI_VAULT_SORT,
group: DEFAULT_AI_VAULT_GROUP,
hideEmptySessions: DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS
})
).toBe(0)
})
it('treats hiding empty sessions as an adjustment from the new default', () => {
expect(
countAiVaultViewAdjustments({
agents: [...AI_VAULT_AGENTS],
sort: DEFAULT_AI_VAULT_SORT,
group: DEFAULT_AI_VAULT_GROUP,
hideEmptySessions: true
})
).toBe(1)
})
it('does not count showing empty sessions as an adjustment', () => {
expect(
countAiVaultViewAdjustments({
agents: [...AI_VAULT_AGENTS],
sort: DEFAULT_AI_VAULT_SORT,
group: DEFAULT_AI_VAULT_GROUP,
hideEmptySessions: false
})
).toBe(0)
})
it('counts other non-default view options independently', () => {
expect(
countAiVaultViewAdjustments({
agents: ['claude'],
sort: 'created',
group: 'agent',
hideEmptySessions: true
})
).toBe(4)
})
})
@@ -0,0 +1,26 @@
import {
AI_VAULT_AGENTS,
type AiVaultAgent,
type AiVaultGroup,
type AiVaultSort
} from '../../../../shared/ai-vault-types'
// Why: hide-empty used to default true; keep initial state, badge count, and Reset view
// on one constant so a default flip cannot leave Reset pointing at the old value.
export const DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS = false
export const DEFAULT_AI_VAULT_SORT: AiVaultSort = 'updated'
export const DEFAULT_AI_VAULT_GROUP: AiVaultGroup = 'project'
export function countAiVaultViewAdjustments(options: {
agents: readonly AiVaultAgent[]
sort: AiVaultSort
group: AiVaultGroup
hideEmptySessions: boolean
}): number {
return (
(options.agents.length === AI_VAULT_AGENTS.length ? 0 : 1) +
(options.sort === DEFAULT_AI_VAULT_SORT ? 0 : 1) +
(options.group === DEFAULT_AI_VAULT_GROUP ? 0 : 1) +
(options.hideEmptySessions === DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS ? 0 : 1)
)
}