Skip to content

feat(sidebar): add ascending/descending order to workspace sort - #6900

Open
jtalborough wants to merge 1 commit into
stablyai:mainfrom
jtalborough:feat/sidebar-sort-direction
Open

jtalborough wants to merge 1 commit into
stablyai:mainfrom
jtalborough:feat/sidebar-sort-direction

Conversation

@jtalborough

@jtalborough jtalborough commented Jun 30, 2026 •

Copy link
Copy Markdown

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.

  • asc is each mode's natural order (Name A→Z, Recent newest-first, …); desc reverses it.
  • Default is asc, so existing ordering is unchanged until you flip it.
  • Hidden for Manual sort — that's a fixed, user-dragged order, so a direction toggle would be meaningless (and it's never applied there).
  • Wraps the shared worktree comparator, so it works in every view (flat and grouped).

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

  • New persisted sortDirection: 'asc' | 'desc' UI state, plumbed through PersistedUIState, the default UI state, the main-process normalizer (mirroring sortBy), the store slice, hydration, and the debounced UI writer.
  • applySortDirection(comparator, direction) in smart-sort.ts reverses the comparator for desc; the sort site passes 'asc' for manual so the fixed order is never touched.

Review summary (cross-cutting checks)

  • Cross-platform: no platform branches; menu + comparator only.
  • SSH / remote: unaffected — UI state + client-side sort, no runtime/IPC surface beyond the existing ui.set persistence path.
  • Agents / integrations / git providers: neutral.
  • Performance: the comparator wrapper is an O(1) negation; no extra passes over the worktree list.
  • UI quality: reuses the existing dropdown radio-group pattern in the Sort-by submenu; no new tokens.
  • Security: none.

Tests

smart-sort.test.ts adds coverage for applySortDirection (asc keeps order, desc reverses). Full pnpm lint, tsgo typecheck (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


Open in Stage

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.

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]>
@ghost

ghost commented Jun 30, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 6 individual chapters for you:

Title
1 Define sort direction types and defaults
2 Implement sort direction persistence and normalization
3 Add sort direction to renderer store
4 Implement comparator reversal logic and tests
5 Apply sort direction to worktree list
6 Add sort direction controls to UI
Open in Stage

Chapters generated by Stage for commit df7b5db on Jun 30, 2026 12:37pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new sortDirection field ('asc' | 'desc') is added to PersistedUIStateandgetDefaultUIState. The Zustand UI slice gains a sortDirectionstate value andsetSortDirectionsetter, with hydration support. The main-process persistence store adds anormalizeSortDirectionhelper used ingetUI()andupdateUI(). A new applySortDirectionutility insmart-sort.tswraps a worktree comparator to invert order for descending;WorktreeListapplies this based on the store value.SidebarWorkspaceOptionsMenurenders an asc/desc radio group whensortByis not'manual'. App.tsxincludessortDirection` in the debounced persistence payload. Localization strings are added across all five locale files.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and directly describes the added ascending/descending workspace sort order.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description covers the change, rationale, implementation, review notes, tests, and UI impact, though it does not follow the template headings exactly.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a71959f7-1332-4bf4-97bb-2d8327007ba8

📥 Commits

Reviewing files that changed from the base of the PR and between be3f30e and df7b5db.

📒 Files selected for processing (15)
  • src/main/persistence.ts
  • src/renderer/src/App.tsx
  • src/renderer/src/components/sidebar/SidebarWorkspaceOptionsMenu.tsx
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/smart-sort.test.ts
  • src/renderer/src/components/sidebar/smart-sort.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/startup-ui-hydration.ts
  • src/renderer/src/store/slices/ui.ts
  • src/shared/constants.ts
  • src/shared/types.ts

Comment on lines +5223 to +5228
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
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants