Skip to content

fix(web): resolve logical-to-physical key mismatch in project drag reorder#1904

Merged
juliusmarminge merged 7 commits intopingdotgg:mainfrom
mwolson:fix/manual-sort-drag-drop
Apr 11, 2026
Merged

fix(web): resolve logical-to-physical key mismatch in project drag reorder#1904
juliusmarminge merged 7 commits intopingdotgg:mainfrom
mwolson:fix/manual-sort-drag-drop

Conversation

@mwolson
Copy link
Copy Markdown
Contributor

@mwolson mwolson commented Apr 10, 2026

What Changed

The drag-end handler in Sidebar.tsx was passing logical project keys (from deriveLogicalProjectKey) to reorderProjects(), but projectOrder in uiStateStore stores physical keys (environmentId:projectId). For any project with a git remote, the logical key is the canonicalKey (e.g. github.com/owner/repo) which doesn't match the physical key, so findIndex returned -1 and 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 sidebarProjects to 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

  • This PR is small and focused
  • I explained what changed and why
  • 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.

reorderProjects now 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

  • Multi-environment projects share a logical group but have separate physical keys. The previous reorderProjects logic passed a single key, causing only one environment's entry to move.
  • reorderProjects in uiStateStore.ts now accepts arrays of draggedProjectIds and targetProjectIds, moving all member keys of a group together.
  • Sidebar.tsx collects all member scopedProjectKeys for both the dragged and target projects before calling reorderProjects.
  • Insertion position is determined by whether the dragged group was before or after the target group in the existing order.
  • Behavioral Change: reorderProjects now expects arrays instead of single strings; callers passing a single ID must wrap it in an array.

Macroscope summarized 275f9fa.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ba91d7a6-2eb6-4003-9dcb-6745c77ac1ae

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@github-actions github-actions bot added size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 10, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 10, 2026

Approvability

Verdict: 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.
@mwolson
Copy link
Copy Markdown
Contributor Author

mwolson commented Apr 10, 2026

Addressed the Bugbot feedback: for multi-environment grouped projects, the original fix only moved the representative's physical key in projectOrder, but non-representative member keys could anchor the group at the old position.

Changes in the follow-up commit:

  • Added reorderProjectGroup to uiStateStore that removes all member keys of the dragged group and re-inserts them together at the target position
  • Updated handleProjectDragEnd to pass all memberProjectRefs for both the dragged and target groups
  • Added test coverage for reorderProjects and reorderProjectGroup (single-member, multi-member contiguous, multi-member scattered, and no-op cases)

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.

@github-actions github-actions bot added size:M 30-99 changed lines (additions + deletions). and removed size:S 10-29 changed lines (additions + deletions). labels Apr 10, 2026
…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.
@mwolson
Copy link
Copy Markdown
Contributor Author

mwolson commented Apr 10, 2026

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).

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

@mwolson
Copy link
Copy Markdown
Contributor Author

mwolson commented Apr 11, 2026

Consolidated reorderProjectGroup back into reorderProjects (replaced the original single-key signature with array-based one) to keep the diff clean and avoid dangling dead code. Also picked up Julian's merge from main.

No behavioral changes from the previous push, just cleanup.

macroscopeapp[bot]
macroscopeapp bot previously approved these changes Apr 11, 2026
@macroscopeapp macroscopeapp bot dismissed their stale review April 11, 2026 01:31

Dismissing prior approval to re-evaluate 275f9fa

@juliusmarminge juliusmarminge merged commit 97880e8 into pingdotgg:main Apr 11, 2026
12 checks passed
@mwolson mwolson deleted the fix/manual-sort-drag-drop branch April 11, 2026 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: v0.0.16 regression: drag-and-drop project reordering silently fails when sort is set to Manual

2 participants