Skip to content

The agent that grows with you

refactor(desktop): one ordering for sidebar groupings shared by the menu and the keybind

kshitijk4poor206e054063e6
diff --git a/apps/desktop/src/app/chat/sidebar/filter-menu.tsx b/apps/desktop/src/app/chat/sidebar/filter-menu.tsx
index 657db9997de..6d78799a87e 100644
--- a/apps/desktop/src/app/chat/sidebar/filter-menu.tsx
+++ b/apps/desktop/src/app/chat/sidebar/filter-menu.tsx
@@ -43,6 +43,7 @@ import {
setSidebarShowAllSessions,
setSidebarShowArchived,
setWorkspaceNodesOpen,
+ SIDEBAR_GROUPING_ORDER,
type SidebarGrouping,
type SidebarOrdering,
type SidebarRowMeta,
@@ -75,12 +76,14 @@ interface Option<T extends string = string> {
label: string
}
-const GROUPINGS: Option<SidebarGrouping>[] = [
- { icon: 'clock', id: 'date', label: 'Updated' },
- { icon: 'root-folder', id: 'project', label: 'Project' },
- { icon: 'pulse', id: 'status', label: 'Status' },
- { icon: 'account', id: 'profile', label: 'Profile' }
-]
+const GROUPING_OPTIONS: Record<SidebarGrouping, Omit<Option<SidebarGrouping>, 'id'>> = {
+ date: { icon: 'clock', label: 'Updated' },
+ profile: { icon: 'account', label: 'Profile' },
+ project: { icon: 'root-folder', label: 'Project' },
+ status: { icon: 'pulse', label: 'Status' }
+}
+
+const GROUPINGS: Option<SidebarGrouping>[] = SIDEBAR_GROUPING_ORDER.map(id => ({ id, ...GROUPING_OPTIONS[id] }))
const ORDERINGS: Option<SidebarOrdering>[] = [
{ icon: 'clock', id: 'updated', label: 'Updated' },
diff --git a/apps/desktop/src/store/layout.ts b/apps/desktop/src/store/layout.ts
index 16721860a5a..2893c689543 100644
--- a/apps/desktop/src/store/layout.ts
+++ b/apps/desktop/src/store/layout.ts
@@ -253,7 +253,9 @@ export const $sidebarAgentsGrouped: ReadableAtom<boolean> = computed(
* default (Today / Yesterday / Last week dividers). `profile` only means
* anything while the sidebar is showing every profile at once. */
export type SidebarGrouping = 'date' | 'profile' | 'project' | 'status'
-export const SIDEBAR_GROUPING_CYCLE: readonly SidebarGrouping[] = ['date', 'project', 'status', 'profile']
+/** The one ordering of groupings: the filter menu lists them in it and the
+ * `view.cycleSidebarGrouping` keybind walks it, so the two cannot drift. */
+export const SIDEBAR_GROUPING_ORDER: readonly SidebarGrouping[] = ['date', 'project', 'status', 'profile']
/** What ranks rows within whatever grouping is active. */
export type SidebarOrdering = 'cost' | 'created' | 'manual' | 'status' | 'tokens' | 'updated'
/** The sort keys the menu offers; `manual` is entered by dragging, not picked. */
@@ -658,10 +660,9 @@ export function setSidebarGrouping(grouping: SidebarGrouping) {
}
export function cycleSidebarGrouping() {
- const currentIndex = SIDEBAR_GROUPING_CYCLE.indexOf($sidebarGrouping.get())
- const nextIndex = (currentIndex + 1) % SIDEBAR_GROUPING_CYCLE.length
+ const currentIndex = SIDEBAR_GROUPING_ORDER.indexOf($sidebarGrouping.get())
- setSidebarGrouping(SIDEBAR_GROUPING_CYCLE[nextIndex])
+ setSidebarGrouping(SIDEBAR_GROUPING_ORDER[(currentIndex + 1) % SIDEBAR_GROUPING_ORDER.length])
}
export function setSidebarOrdering(ordering: SidebarOrdering) {