fix(web): resolve logical-to-physical key mismatch in project drag reorder#1904
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
ApprovabilityVerdict: Approved A straightforward bug fix that changes the project reorder function to handle multi-member project groups correctly. The changes are limited to UI state management for sidebar ordering, with comprehensive unit tests covering edge cases. No security, billing, or significant runtime implications. You can customize Macroscope's approvability policy. Learn more. |
For multi-environment grouped projects, reordering only the representative's physical key could leave non-representative members anchored at the old position. Add reorderProjectGroup that removes and re-inserts all member keys as a unit, and use it from the drag handler via memberProjectRefs.
|
Addressed the Bugbot feedback: for multi-environment grouped projects, the original fix only moved the representative's physical key in Changes in the follow-up commit:
Tested locally with an AppImage build: drag-and-drop reorder works and persists across restarts. I wasn't able to test the multi-environment case specifically (requires the same repo connected through multiple environments), but the new unit tests cover that path. |
…target Adjust insertion index to compensate for dragged keys removed before the target position, fixing an off-by-(N-1) overshoot when N > 1 group members sit before the drop target.
|
Good catch from Bugbot. When N > 1 dragged keys sit before the target, the stale pre-removal index overshoots by N-1 positions. The existing tests all targeted the last element in the array, masking this. Fixed by adjusting the insertion index to compensate for removed keys before the target, and added two new test cases: forward drag to a non-last target (the overshoot scenario) and backward drag (insert-before). |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c18b87b. Configure here.
|
Consolidated No behavioral changes from the previous push, just cleanup. |
Dismissing prior approval to re-evaluate 275f9fa

What Changed
The drag-end handler in
Sidebar.tsxwas passing logical project keys (fromderiveLogicalProjectKey) toreorderProjects(), butprojectOrderinuiStateStorestores physical keys (environmentId:projectId). For any project with a git remote, the logical key is thecanonicalKey(e.g.github.com/owner/repo) which doesn't match the physical key, sofindIndexreturned-1and the reorder silently did nothing.The fix resolves the representative project's physical key before calling
reorderProjects.Why
This is a v0.0.16 regression introduced in #1768, which changed
sidebarProjectsto group by logical key for multi-environment support but didn't update the drag handler to translate back to physical keys. Manual sort drag-and-drop is completely broken for any project with a git remote.Fixes #1902
Checklist
I included before/after screenshots for any UI changes(no visual change, behavior fix only)I included a video for animation/interaction changes(N/A)Tested by building a local AppImage from this branch and confirming drag-and-drop reorder works and persists across restarts.
Note
Medium Risk
Changes the project drag-and-drop reorder algorithm and its store API to move groups of project keys together; mistakes could corrupt or unexpectedly reshuffle persisted manual ordering but the impact is limited to sidebar UI state.
Overview
Fixes manual sidebar project drag-and-drop for multi-environment/grouped projects by reordering physical member project keys instead of a single logical key.
reorderProjectsnow accepts arrays of dragged/target IDs and removes/inserts all dragged members as a unit, with expanded unit tests covering missing keys, scattered members, relative insertion, and multi-member targets.Reviewed by Cursor Bugbot for commit 275f9fa. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix logical-to-physical key mismatch in project drag-and-drop reorder
reorderProjectslogic passed a single key, causing only one environment's entry to move.reorderProjectsin uiStateStore.ts now accepts arrays ofdraggedProjectIdsandtargetProjectIds, moving all member keys of a group together.scopedProjectKeysfor both the dragged and target projects before callingreorderProjects.reorderProjectsnow expects arrays instead of single strings; callers passing a single ID must wrap it in an array.Macroscope summarized 275f9fa.