Repository navigation
feat(sidebar): add ascending/descending order to workspace sort - #6900
jtalborough wants to merge 1 commit into
Conversation
The workspace options menu let you pick a sort mode (Name, Recent, Smart,
Project) but not a direction. Add an Order control (Ascending / Descending)
under "Sort by" that wraps the shared worktree comparator, so every sort
mode and every view can be reversed.
- New persisted `sortDirection` UI state ('asc' default — existing order is
unchanged until toggled); normalized in the main process like `sortBy`.
- `applySortDirection` reverses the comparator for 'desc'. 'manual' is a
fixed drag order, so direction is never applied and the control is hidden.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Ready to review this PR? Stage has broken it down into 6 individual chapters for you: Chapters generated by Stage for commit df7b5db on Jun 30, 2026 12:37pm UTC. |
📝 WalkthroughWalkthroughA new 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a71959f7-1332-4bf4-97bb-2d8327007ba8
📒 Files selected for processing (15)
src/main/persistence.tssrc/renderer/src/App.tsxsrc/renderer/src/components/sidebar/SidebarWorkspaceOptionsMenu.tsxsrc/renderer/src/components/sidebar/WorktreeList.tsxsrc/renderer/src/components/sidebar/smart-sort.test.tssrc/renderer/src/components/sidebar/smart-sort.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/lib/startup-ui-hydration.tssrc/renderer/src/store/slices/ui.tssrc/shared/constants.tssrc/shared/types.ts
| nonArchivedWorktrees.sort( | ||
| // Why: 'manual' is a fixed user-defined order, so direction never reverses it. | ||
| applySortDirection( | ||
| buildWorktreeComparator(sortBy, repoMap, now, attentionByWorktree), | ||
| sortBy === 'manual' ? 'asc' : sortDirection | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Apply sortDirection in the smart cold-start fallback too.
When sortBy === 'smart' && !sessionHasHadPty.current, the early return above this block exits before applySortDirection(...) runs. That means a persisted "desc" preference is ignored after launch until a live PTY appears, so Smart sort briefly falls back to ascending-only behavior.
Possible fix
- nonArchivedWorktrees.sort(
- (a, b) => b.sortOrder - a.sortOrder || a.displayName.localeCompare(b.displayName)
- )
+ nonArchivedWorktrees.sort(
+ sortDirection === 'desc'
+ ? (a, b) => a.sortOrder - b.sortOrder || b.displayName.localeCompare(a.displayName)
+ : (a, b) => b.sortOrder - a.sortOrder || a.displayName.localeCompare(b.displayName)
+ )Also applies to: 5235-5235
What
The workspace options menu (Workspaces → ⚙️ → Sort by) lets you choose a sort mode — Name, Recent, Smart, Project — but not a direction. This adds an Order control (Ascending / Descending) beneath the sort modes.
ascis each mode's natural order (Name A→Z, Recent newest-first, …);descreverses it.asc, so existing ordering is unchanged until you flip it.Why
Several sort modes only make sense in both directions (e.g. oldest-first vs newest-first by activity, or Z→A by name), but there was no way to reverse them.
How
sortDirection: 'asc' | 'desc'UI state, plumbed throughPersistedUIState, the default UI state, the main-process normalizer (mirroringsortBy), the store slice, hydration, and the debounced UI writer.applySortDirection(comparator, direction)insmart-sort.tsreverses the comparator fordesc; the sort site passes'asc'formanualso the fixed order is never touched.Review summary (cross-cutting checks)
ui.setpersistence path.Tests
smart-sort.test.tsadds coverage forapplySortDirection(asc keeps order, desc reverses). Fullpnpm lint,tsgotypecheck (node + web),oxfmt, and localization catalog/coverage all pass. Localization strings added across en/es/ja/ko/zh.Visual
UI change (new Order control in the Sort-by submenu) — screenshot to be attached to the PR conversation.
🤖 Generated with Claude Code
ELI5
Workspace sort gets Ascending/Descending in addition to Name, Recent, Smart, and Project. Manual sort hides the direction control because drag order already defines sequence.