Skip to content

fix: Folder Sequencing When we try to move any folder at the bottom o…#8208

Open
ravindra-bruno wants to merge 4 commits into
usebruno:mainfrom
ravindra-bruno:fix/BRU-1112
Open

fix: Folder Sequencing When we try to move any folder at the bottom o…#8208
ravindra-bruno wants to merge 4 commits into
usebruno:mainfrom
ravindra-bruno:fix/BRU-1112

Conversation

@ravindra-bruno

@ravindra-bruno ravindra-bruno commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

…f the folders list

Description

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • New Features

    • Improved collection drag-and-drop with explicit above/inside/below placement, distinct above/below visual indicators, and centralized drop validation.
    • Reordering now uses placement-aware resequencing so moves (same- or cross-collection) produce stable item ordering and prevent ancestry-invalid moves.
  • Tests

    • Added comprehensive tests for placement detection, destination path resolution, validation rules, and reorder outcomes.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 300beb27-c9d0-48a3-8dd1-0c00190307f6

📥 Commits

Reviewing files that changed from the base of the PR and between e5f950b and bc8c516.

📒 Files selected for processing (5)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/utils/collections/index.js
  • packages/bruno-app/src/utils/tests/collections/drag-and-drop.spec.js

Walkthrough

Centralizes drop placement/legality into utilities (above/inside/below), threads dropType into reordering, updates CollectionItem and collection-row hover styling to use the new contract, and adds Jest tests covering placement, pathname calculation, legality, and reordering.

Changes

Enhanced Collection Drag-and-Drop

Layer / File(s) Summary
Drop utilities and reordering
packages/bruno-app/src/utils/collections/index.js
Adds determineCollectionItemDrop() (maps hover geometry → `above
CollectionItem component drag-drop integration
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
Imports named collection utils, computes dropType via resolveDropFromMonitor(), delegates legality to canCollectionItemBeDropped(), updates useDrop handlers (hover/drop/canDrop/collect), clears dropType on hover exit, and adds drop-target-above / drop-target-below classes.
Collection row hover styling
packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js
Sets collection-to-collection hover dropType to 'above' (was 'adjacent') and updates hover class to use dropType === 'above'.
Redux action handler drop plumbing
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
Threads dropType into getReorderedItemsInTargetDirectory() for both cross-directory and same-location flows, updates handleReorderInSameLocation to accept dropType, and replaces startsWith descendant guard with isPathOrDescendant.
Drag-and-drop behavior test suite
packages/bruno-app/src/utils/tests/collections/drag-and-drop.spec.js
Adds tests for determineCollectionItemDrop, calculateDraggedItemNewPathname, canCollectionItemBeDropped, and getReorderedItemsInTargetDirectory covering above/inside/below cases, mixed content, and edge conditions.

Sequence Diagram

sequenceDiagram
  participant User as User Pointer
  participant Item as CollectionItem Component
  participant Monitor as ReactDnD_Monitor
  participant Determine as determineCollectionItemDrop
  participant Can as canCollectionItemBeDropped
  participant Action as handleCollectionItemDrop
  participant Reorder as getReorderedItemsInTargetDirectory
  participant Store as ReduxStore

  User->>Item: hover / drag over row
  Item->>Monitor: read clientOffset & hoverBoundingRect
  Monitor->>Determine: clientOffset, hoverBoundingRect, item
  Determine->>Item: dropType (above/inside/below)
  Item->>Can: draggedItem,targetItem,dropType,collection context
  Can->>Item: allow/reject
  Item->>Action: dispatch drop with dropType
  Action->>Reorder: items,targetItemUid,draggedItemUid,dropType
  Reorder->>Store: update sequences
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • usebruno/bruno#6727: Modifies handleCollectionItemDrop adjacent reorder logic and seq computation—directly related to reorder behavior changes.
  • usebruno/bruno#7584: Also edits handleCollectionItemDrop to add cross-collection move handling; intersects with this PR's drop-position plumbing.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno
  • naman-bruno
  • sid-bruno

Above or below the line the pointer slides,
Helpers judge intent while Redux decides,
Components listen, tests give a nod,
Sequences update — the drop lands odd or broad.
🎯🔀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and incomplete, using ellipsis and failing to clearly convey the main technical change: folder drag-drop sequencing improvements via dropType logic. Revise to a complete, specific title like: 'fix: Improve folder reordering by supporting above/below drop placement' or 'fix: Add dropType support for folder sequencing at list boundaries'
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 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.

@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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-app/src/utils/collections/index.js`:
- Around line 1549-1554: The current descendant check uses
targetItemPathname?.startsWith(draggedItemPathname) which incorrectly treats
siblings like "/users-archive" as descendants of "/users"; change this to a
path-segment-aware check: ensure you only treat target as a descendant when
targetItemPathname === draggedItemPathname or targetItemPathname starts with
draggedItemPathname + "/" (taking care of leading/trailing slashes), and replace
the existing startsWith check in the block that calls
calculateDraggedItemNewPathname (using draggedItemPathname and
targetItemPathname) with that logic; then apply the exact same change inside
handleCollectionItemDrop() so validation and execution use the same
separator-aware ancestry test.

In `@packages/bruno-app/src/utils/tests/collections/drag-and-drop.spec.js`:
- Around line 154-201: Add a test to cover the sibling-prefix regression for
canCollectionItemBeDropped: create two folder items whose pathnames share a
prefix but are not ancestor/descendant (e.g., parent pathname
'/collections/my-collection/users' and sibling pathname
'/collections/my-collection/users-archive'), call canCollectionItemBeDropped
with draggedItem having sourceCollectionUid equal to collectionUid and
targetItem the sibling, and assert the result is true; place this alongside the
existing descendant and same-collection tests to ensure the function
(canCollectionItemBeDropped) checks full path-segment ancestry rather than
simple string prefix matching.
- Around line 8-10: The test uses hardcoded POSIX strings for
collectionPathname, folderPathname, and requestPathname which breaks on Windows;
replace these literals with the shared path helper (e.g., path.join or the
repo's path utility) to build the input path fixtures and the expected results
so they are OS-agnostic; update the declarations that create collectionPathname,
folderPathname, requestPathname and any expectations/assertions that compare
against them (also apply the same change to the other fixtures/expectations in
the 107–137 block) so all paths use the helper instead of hardcoded '/'
separators.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 60702ceb-b8ed-47ea-919f-b9619438ebdf

📥 Commits

Reviewing files that changed from the base of the PR and between 6f47218 and c8ddf8c.

📒 Files selected for processing (4)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/utils/collections/index.js
  • packages/bruno-app/src/utils/tests/collections/drag-and-drop.spec.js

Comment thread packages/bruno-app/src/utils/collections/index.js
Comment thread packages/bruno-app/src/utils/tests/collections/drag-and-drop.spec.js Outdated
@pull-request-size pull-request-size Bot added size/XL and removed size/L labels Jun 9, 2026
Bruno-ravindra and others added 2 commits June 9, 2026 16:02
…dge zones (BRU-1112)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant