Skip to content

fix(desktop): stable createdAt tiebreaker in v2 workspaces list sort#3967

Merged
saddlepaddle merged 1 commit intomainfrom
sort-workspace-created-at
May 1, 2026
Merged

fix(desktop): stable createdAt tiebreaker in v2 workspaces list sort#3967
saddlepaddle merged 1 commit intomainfrom
sort-workspace-created-at

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented May 1, 2026

Summary

  • In the v2 workspaces list, the within-host createdAt tiebreaker was being inverted whenever the user toggled the host (device) sort direction, because the directional flip wrapped both the primary comparison and the tiebreaker.
  • Apply the asc/desc flip to the primary-field comparison only, then always use newest-first createdAt as the final tiebreaker. After grouping by device, workspaces on the same device now sort by createdAt consistently regardless of direction.

Test plan

  • Open the v2 workspaces list with multiple workspaces on the same device
  • Sort by Host asc — within each device, newest workspace appears first
  • Toggle to Host desc — within each device, newest still appears first
  • Sort by Name / Branch / In sidebar — ties also break newest-first
  • Sort by Created — primary direction still works as before

Summary by cubic

Fixes sorting in the v2 workspaces list by making createdAt a stable, newest-first tiebreaker. Within each device, the newest workspace stays first regardless of Host sort direction; Created sorting still respects asc/desc.

  • Bug Fixes
    • Direction flip now applies only to the primary field.
    • Ties break by createdAt consistently across Host, Name, Branch, and Sidebar.

Written for commit d98e36b. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Improved workspace list sorting logic to ensure consistent ordering when workspaces share the same primary sort criteria. Workspaces are now ordered by creation date as a secondary sort option.

…aces

The within-host createdAt order was being flipped by the host sort
direction toggle. Apply the directional flip to the primary field
only, then always use newest-first createdAt as the tiebreaker.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2b82ecb6-478b-46a0-913e-0b2bf2c9ace8

📥 Commits

Reviewing files that changed from the base of the PR and between c75c857 and d98e36b.

📒 Files selected for processing (1)
  • apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspaces/components/V2WorkspacesList/V2WorkspacesList.tsx

📝 Walkthrough

Walkthrough

The compareWorkspaces function's sorting logic has been refactored to compute a single directional comparison result and return it immediately when non-zero, applying a hardcoded createdAt tiebreaker only when the primary comparison is tied.

Changes

Cohort / File(s) Summary
Workspace List Sorting Logic
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspaces/components/V2WorkspacesList/V2WorkspacesList.tsx
Refactored compareWorkspaces comparison function to compute directional result once and apply createdAt tiebreaker only on tied comparisons, simplifying the prior logic flow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A hop and a skip through sorting we go,
Comparisons streamlined, more clarity flow,
Tiebreakers hop in when values align,
The workspace dance—now much more divine! ✨

🚥 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 clearly and specifically describes the main change: fixing the createdAt tiebreaker in the v2 workspaces list sort to be stable.
Description check ✅ Passed The description includes a clear summary of the bug, the fix applied, a detailed test plan, and additional context from an auto-generated summary, covering the essential information needed.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sort-workspace-created-at

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
Review rate limit: 3/8 reviews remaining, refill in 34 minutes and 26 seconds.

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

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 1, 2026

Greptile Summary

This PR fixes a one-liner sort bug in compareWorkspaces: the old code applied the ascending/descending flip to both the primary comparison and the createdAt tiebreaker, so toggling to "desc" silently reversed the tiebreaker to oldest-first. The fix separates the two concerns — apply the direction flip to the primary result only, then always fall through to a newest-first createdAt tiebreaker — which is correct and minimal.

Confidence Score: 5/5

Safe to merge — the change is a minimal, correct fix with no logic regressions.

Single-file, three-line change that correctly separates the directional flip from the stable tiebreaker. The old and new tiebreaker activation conditions are equivalent (both fire when cmp === 0), and the 'created' field edge case is handled cleanly. No new state, no new dependencies, no security surface.

No files require special attention.

Important Files Changed

Filename Overview
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspaces/components/V2WorkspacesList/V2WorkspacesList.tsx Fixed compareWorkspaces tiebreaker so the createdAt newest-first fallback is applied after the directional flip rather than before, making it stable regardless of sort direction.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["compareWorkspaces(a, b, field, direction)"] --> B["switch(field): compute cmp"]
    B --> C["directional = direction==='asc' ? cmp : -cmp"]
    C --> D{directional !== 0?}
    D -- Yes --> E["return directional\n(primary sort wins)"]
    D -- No --> F["return b.createdAt - a.createdAt\n(always newest-first tiebreaker)"]
Loading

Reviews (1): Last reviewed commit: "fix(desktop): keep createdAt tiebreaker ..." | Re-trigger Greptile

@saddlepaddle saddlepaddle merged commit f34f1e2 into main May 1, 2026
7 of 8 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch

Thank you for your contribution! 🎉

@Kitenite Kitenite deleted the sort-workspace-created-at branch May 6, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant