fix(desktop): new v2 workspaces appear at top of their project in sidebar#3619
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughNew logic changes how top-level (ungrouped) workspace sidebar records get their Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Greptile SummaryThis PR fixes a UX bug where newly created v2 workspaces were appended to the bottom of their project's sidebar list instead of the top. The fix introduces a Key changes:
Confidence Score: 5/5Safe to merge — the change is minimal, logically correct, and any transient tabOrder edge cases are self-healing on the next drag-reorder. The fix is a small, focused two-function change. No files require special attention. The single changed file is self-contained.
|
| Filename | Overview |
|---|---|
| apps/desktop/src/renderer/routes/_authenticated/hooks/useDashboardSidebarState/useDashboardSidebarState.ts | Adds getPrependTabOrder helper returning min - 1 and switches ensureSidebarWorkspaceRecord to use it, so new workspaces land at the top of their project in the sidebar instead of the bottom. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/routes/_authenticated/hooks/useDashboardSidebarState/useDashboardSidebarState.ts
Line: 15-22
Comment:
**Empty-project seed value is `0` while the rest of the codebase uses `1`-based ordering**
When `items` is empty (first workspace in a brand-new project) `getPrependTabOrder` returns `0`, whereas every other insertion helper (`getNextTabOrder`, `reorderProjectChildren`, `reorderWorkspaces`, `moveWorkspaceToSectionAtIndex`) normalises to `1`-based tabOrders on the next drag. This is functionally harmless — `0 < 1` so the workspace still sorts first — but it is a mild inconsistency worth documenting or aligning with `1`.
If you want to keep the `1`-based convention you could return `1` instead:
```suggestion
function getPrependTabOrder(items: Array<{ tabOrder: number }>): number {
if (items.length === 0) return 1;
const minTabOrder = items.reduce(
(minValue, item) => Math.min(minValue, item.tabOrder),
Number.POSITIVE_INFINITY,
);
return minTabOrder - 1;
}
```
This way the first workspace starts at `1`, the second at `0`, the third at `-1`, etc. — all still sorts correctly and matches the "index + 1" convention used by the reorder helpers.
Not blocking; leaving as a suggestion.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(desktop): place new v2 workspaces at..." | Re-trigger Greptile
| function getPrependTabOrder(items: Array<{ tabOrder: number }>): number { | ||
| if (items.length === 0) return 0; | ||
| const minTabOrder = items.reduce( | ||
| (minValue, item) => Math.min(minValue, item.tabOrder), | ||
| Number.POSITIVE_INFINITY, | ||
| ); | ||
| return minTabOrder - 1; | ||
| } |
There was a problem hiding this comment.
Empty-project seed value is
0 while the rest of the codebase uses 1-based ordering
When items is empty (first workspace in a brand-new project) getPrependTabOrder returns 0, whereas every other insertion helper (getNextTabOrder, reorderProjectChildren, reorderWorkspaces, moveWorkspaceToSectionAtIndex) normalises to 1-based tabOrders on the next drag. This is functionally harmless — 0 < 1 so the workspace still sorts first — but it is a mild inconsistency worth documenting or aligning with 1.
If you want to keep the 1-based convention you could return 1 instead:
| function getPrependTabOrder(items: Array<{ tabOrder: number }>): number { | |
| if (items.length === 0) return 0; | |
| const minTabOrder = items.reduce( | |
| (minValue, item) => Math.min(minValue, item.tabOrder), | |
| Number.POSITIVE_INFINITY, | |
| ); | |
| return minTabOrder - 1; | |
| } | |
| function getPrependTabOrder(items: Array<{ tabOrder: number }>): number { | |
| if (items.length === 0) return 1; | |
| const minTabOrder = items.reduce( | |
| (minValue, item) => Math.min(minValue, item.tabOrder), | |
| Number.POSITIVE_INFINITY, | |
| ); | |
| return minTabOrder - 1; | |
| } |
This way the first workspace starts at 1, the second at 0, the third at -1, etc. — all still sorts correctly and matches the "index + 1" convention used by the reorder helpers.
Not blocking; leaving as a suggestion.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/routes/_authenticated/hooks/useDashboardSidebarState/useDashboardSidebarState.ts
Line: 15-22
Comment:
**Empty-project seed value is `0` while the rest of the codebase uses `1`-based ordering**
When `items` is empty (first workspace in a brand-new project) `getPrependTabOrder` returns `0`, whereas every other insertion helper (`getNextTabOrder`, `reorderProjectChildren`, `reorderWorkspaces`, `moveWorkspaceToSectionAtIndex`) normalises to `1`-based tabOrders on the next drag. This is functionally harmless — `0 < 1` so the workspace still sorts first — but it is a mild inconsistency worth documenting or aligning with `1`.
If you want to keep the `1`-based convention you could return `1` instead:
```suggestion
function getPrependTabOrder(items: Array<{ tabOrder: number }>): number {
if (items.length === 0) return 1;
const minTabOrder = items.reduce(
(minValue, item) => Math.min(minValue, item.tabOrder),
Number.POSITIVE_INFINITY,
);
return minTabOrder - 1;
}
```
This way the first workspace starts at `1`, the second at `0`, the third at `-1`, etc. — all still sorts correctly and matches the "index + 1" convention used by the reorder helpers.
Not blocking; leaving as a suggestion.
How can I resolve this? If you propose a fix, please make it concise.…sidebar New workspaces were inserted with tabOrder = max + 1, burying them at the bottom of the project's list. Prepend with min - 1 instead so freshly created workspaces surface at the top without disturbing existing order.
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
ensureSidebarWorkspaceRecordusedgetNextTabOrder(max + 1).getPrependTabOrderhelper that returnsmin - 1and switched the insert to use it, so newly created workspaces land at the top of the project.Test plan
Summary by cubic
New v2 workspaces now appear at the top of their project in the desktop sidebar. This makes new workspaces visible right away without changing existing order.
getPrependTabOrder(min − 1) and used it when creating a workspace to prepend it in the project list.tabOrderat 1 to match reorder helpers; drag-reorder still normalizes values, so any negative seeds are temporary.Written for commit 067526a. Summary will update on new commits.
Summary by CodeRabbit