From 8519c5b05c18edf3819f861048646b2a4e58daba Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Wed, 8 Jul 2026 18:04:42 -0700 Subject: [PATCH] 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. --- .../components/right-sidebar/AiVaultPanel.tsx | 30 ++++++---- .../ai-vault-view-defaults.test.ts | 58 +++++++++++++++++++ .../right-sidebar/ai-vault-view-defaults.ts | 26 +++++++++ 3 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts create mode 100644 src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts diff --git a/src/renderer/src/components/right-sidebar/AiVaultPanel.tsx b/src/renderer/src/components/right-sidebar/AiVaultPanel.tsx index ce09c2e241b..c03192f4054 100644 --- a/src/renderer/src/components/right-sidebar/AiVaultPanel.tsx +++ b/src/renderer/src/components/right-sidebar/AiVaultPanel.tsx @@ -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(DEFAULT_AI_VAULT_SCOPE) - const [sort, setSort] = useState('updated') - const [group, setGroup] = useState('project') - const [hideEmptySessions, setHideEmptySessions] = useState(false) + const [sort, setSort] = useState(DEFAULT_AI_VAULT_SORT) + const [group, setGroup] = useState(DEFAULT_AI_VAULT_GROUP) + const [hideEmptySessions, setHideEmptySessions] = useState(DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS) const [agents, setAgents] = useState([...AI_VAULT_AGENTS]) const [collapsedGroups, setCollapsedGroups] = useState>(() => 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) => { diff --git a/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts b/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts new file mode 100644 index 00000000000..b297c768645 --- /dev/null +++ b/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts @@ -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) + }) +}) diff --git a/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts b/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts new file mode 100644 index 00000000000..e4fc9629513 --- /dev/null +++ b/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts @@ -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) + ) +}