Skip to content

feat(workspace): move external collections into the workspace - #8196

Merged
naman-bruno merged 5 commits into
usebruno:mainfrom
gopu-bruno:feat/move-external-collection-to-workspace
Jun 12, 2026
Merged

naman-bruno merged 5 commits into
usebruno:mainfrom
gopu-bruno:feat/move-external-collection-to-workspace

Conversation

@gopu-bruno

@gopu-bruno gopu-bruno commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

Description

When a collection is opened from a path outside the workspace folder, there is no way to bring it under the workspace. This means the collection cannot be managed by the workspace's Git setup. The only workaround today is to manually move the collection folder into <workspace>/collections on disk.
JIRA

Solution

Adds a Move into Workspace option to the collection context menu for external collections. It moves the collection's files into <workspace>/collections/<name> and registers it in workspace.yml so it can be managed through workspace Git.

The action is only shown when the collection lives outside that workspace root detected via a new shared isPathExternalToBasePath helper.

Changes

  • Added renderer:move-collection-to-workspace IPC handler.
  • Added a reusable moveCollectionDirectory filesystem helper, with unit tests.
  • Added the moveCollectionToWorkspace thunk to coordinate close → move → reopen.
  • Added menu gating via a shared isPathExternalToBasePath helper.
  • Added handling for unsaved drafts via a save/discard prompt.

Screen Recording

Screen.Recording.2026-06-08.at.11.50.25.AM.mov

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

    • Move collections into the active workspace via a modal that detects unsaved drafts and offers Save All, Discard All, or per-draft save; shows success/error toasts and disables controls while moving. UI/styling added for move flow and draft warnings.
  • Tests

    • Added unit tests for path utilities and filesystem move behavior, plus end-to-end integration tests for the move-to-workspace flow and draft handling.

@coderabbitai

coderabbitai Bot commented Jun 8, 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: 174f9516-6c52-4ce5-8549-f89ff5a34157

📥 Commits

Reviewing files that changed from the base of the PR and between 4be96ad and e0448af.

📒 Files selected for processing (1)
  • tests/workspace/move-collection-to-workspace.spec.ts

Walkthrough

Moves external collections into the active workspace: adds path containment checks, a Windows-safe filesystem move, Electron IPC orchestration with UID remapping and workspace.yml registration (with rollback), a Redux thunk to coordinate the move, draft-confirmation modals, sidebar action wiring, and integration tests.

Changes

Move Collections into Workspace

Layer / File(s) Summary
Path detection utility
packages/bruno-app/src/utils/common/path.js, packages/bruno-app/src/utils/common/path.spec.js, packages/bruno-app/src/utils/common/path.windows.spec.js
isPathExternalToBasePath utility detects whether a target path is outside a base path. Unix and Windows tests verify nested paths, sibling-prefix edge cases, dot-segment normalization, trailing separators, drive letters, and missing-input handling.
Filesystem directory move utility
packages/bruno-electron/src/utils/filesystem.js, packages/bruno-electron/src/utils/filesystem.test.js
moveCollectionDirectory moves collection directories with a Windows-safe temp-copy fallback and recovery attempts. Tests verify nested content moves and collision behavior that preserves the source on failure.
Electron IPC handler for collection move
packages/bruno-electron/src/ipc/collection.js
Adds renderer:move-collection-to-workspace: validates workspace path, computes destination folder name, removes old watchers, moves directory (with rollback on move/registration failure), remaps request UIDs, registers the collection in workspace.yml, updates last-opened collections and env mappings, and returns { newPath, newUid, folderName }. Also refactors remove-collection cleanup import.
Redux thunk for move orchestration
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
New moveCollectionToWorkspace(collectionUid) thunk validates collection and active workspace, blocks already-internal collections, calls the IPC move, closes tabs, removes and re-adds collection state as needed, and ensures active tab/workspace consistency with error handling.
Frontend modal components for move workflow
packages/bruno-app/src/components/Sidebar/Collections/Collection/MoveToWorkspace/StyledWrapper.js, packages/bruno-app/src/components/Sidebar/Collections/Collection/MoveToWorkspace/ConfirmMoveDrafts.js, packages/bruno-app/src/components/Sidebar/Collections/Collection/MoveToWorkspace/index.js
Adds StyledWrapper for themed UI, ConfirmMoveDrafts modal that lists regular and transient drafts with batch save/discard and per-transient save actions, and MoveToWorkspace main modal that shows destination path, guards re-entry with isMoving, dispatches the move thunk, and routes to draft confirmation when needed.
Sidebar collection action and modal wiring
packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js
Adds isPathExternalToBasePath import, computes isMoveToWorkspaceVisible, injects a "Move into Workspace" dropdown action, and renders the MoveToWorkspace modal when triggered. Also updates Tabler icon imports.
Integration tests
tests/workspace/move-collection-to-workspace.spec.ts
Playwright/Electron tests that verify a successful move of an external collection into a workspace, that the action is hidden for internal collections, and that unsaved-draft discard flow prompts and completes with on-disk validation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • usebruno/bruno#6264: The main PR’s move-to-workspace flow builds on the workspace-aware collection IPC/state introduced in #6264, directly extending the same Electron renderer:remove-collection/collection-workspace integration area and the workspace-aware collections Redux plumbing in slices/collections/actions.js.

Suggested reviewers

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

Collections on the move, paths old to new,
Windows copies whisper, then swap in view,
Drafts ask softly: save or discard,
IPC, Redux, and modals act unmarred,
Workspaces welcome the collection crew. ✨

size/XXL

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature: enabling collections outside the workspace to be moved into it, which matches the core functionality across all changed files.
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

🧹 Nitpick comments (1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (1)

2463-2471: 💤 Low value

Consider validating result.newPath before proceeding.

If the IPC succeeds but result.newPath is falsy, the collection is removed from Redux without being re-opened—yet the promise resolves, showing a success toast to the user. Based on the IPC contract described in the stack context, newPath should always be present on success, but defensive validation would make this more robust.

💡 Optional: Add early validation
       .then(async (result) => {
+        if (!result?.newPath) {
+          throw new Error('Move operation did not return new collection path');
+        }
         dispatch(closeAllCollectionTabs({ collectionUid }));
         dispatch(removeCollectionFromWorkspace({
           workspaceUid: activeWorkspace.uid,
           collectionLocation: collection.pathname
         }));
         await waitForNextTick();
         dispatch(_removeCollection({ collectionUid }));

-        if (result?.newPath) {
-          const openResult = await dispatch(openMultipleCollections([result.newPath], { workspacePath: activeWorkspace.pathname }));
-          const reopened = (openResult?.opened || []).some(
-            (openedPath) => normalizePath(openedPath) === normalizePath(result.newPath)
-          );
-          if (!reopened) {
-            throw new Error('Collection was moved into the workspace but could not be re-opened. Reload the workspace to access it.');
-          }
+        const openResult = await dispatch(openMultipleCollections([result.newPath], { workspacePath: activeWorkspace.pathname }));
+        const reopened = (openResult?.opened || []).some(
+          (openedPath) => normalizePath(openedPath) === normalizePath(result.newPath)
+        );
+        if (!reopened) {
+          throw new Error('Collection was moved into the workspace but could not be re-opened. Reload the workspace to access it.');
         }
         dispatch(ensureActiveTabInCurrentWorkspace());
       })
🤖 Prompt for 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.

In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`
around lines 2463 - 2471, The code assumes result.newPath exists after the IPC
call; add a defensive check before attempting to re-open the moved collection:
validate that result && result.newPath is a non-empty string (or a valid path)
and if missing, throw or reject with an explicit error (so the success toast
isn't shown and Redux state rollback/compensating logic can run). Update the
block around result.newPath and the
dispatch(openMultipleCollections([result.newPath], { workspacePath:
activeWorkspace.pathname })) call to first assert the value (e.g., if (!result
|| !result.newPath) throw new Error('Missing newPath after move')), then proceed
to call openMultipleCollections and use normalizePath as before to confirm it
reopened.
🤖 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/components/Sidebar/Collections/Collection/index.js`:
- Around line 455-460: The new dropdown action object with id
'move-to-workspace' (label 'Move into Workspace', leftSection
IconFileArrowRight, onClick using setShowMoveToWorkspaceModal) lacks a stable
test selector; update the action definition to include a testId/data-testid
property (e.g., testId: 'collection-action-move-to-workspace') so Playwright can
reliably select it, ensuring the added property follows existing action naming
conventions used elsewhere in the component.

In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/MoveToWorkspace/ConfirmMoveDrafts.js`:
- Around line 173-206: Add stable data-testid attributes to the action buttons
in ConfirmMoveDrafts so Playwright can reliably select them: add
data-testid="save-draft-<id>" (or similar unique key) on the per-item Save
Button tied to handleSaveTransient(item), data-testid="discard-all-and-move" on
the Button that calls handleDiscardAll, data-testid="cancel-move" on the Button
that calls onClose, and data-testid="save-all-and-move" on the Button that calls
handleSaveAll (also consider including state info like
data-testid="save-all-and-move--moving" when isMoving true or deriving tests
from currentDrafts/currentTransientDrafts). Ensure identifiers reference the
existing props/handlers (handleSaveTransient, handleDiscardAll, onClose,
handleSaveAll) and use currentDrafts/currentTransientDrafts to generate any
per-item test ids.

In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/MoveToWorkspace/index.js`:
- Line 60: Replace the hardcoded path construction for targetLocation with an
OS-agnostic join: instead of using string interpolation
`${activeWorkspace.pathname}/collections`, call the project's path-join helper
(or Node's path.join) to join activeWorkspace.pathname and 'collections' inside
the MoveToWorkspace component (symbol: targetLocation and
activeWorkspace.pathname) so the destination path is platform-independent.

---

Nitpick comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 2463-2471: The code assumes result.newPath exists after the IPC
call; add a defensive check before attempting to re-open the moved collection:
validate that result && result.newPath is a non-empty string (or a valid path)
and if missing, throw or reject with an explicit error (so the success toast
isn't shown and Redux state rollback/compensating logic can run). Update the
block around result.newPath and the
dispatch(openMultipleCollections([result.newPath], { workspacePath:
activeWorkspace.pathname })) call to first assert the value (e.g., if (!result
|| !result.newPath) throw new Error('Missing newPath after move')), then proceed
to call openMultipleCollections and use normalizePath as before to confirm it
reopened.
🪄 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: 98e0eaf1-2ecb-48f3-822d-ff4c307eddf4

📥 Commits

Reviewing files that changed from the base of the PR and between 913214e and a8d2bcb.

📒 Files selected for processing (11)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/MoveToWorkspace/ConfirmMoveDrafts.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/MoveToWorkspace/StyledWrapper.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/MoveToWorkspace/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/common/path.js
  • packages/bruno-app/src/utils/common/path.spec.js
  • packages/bruno-app/src/utils/common/path.windows.spec.js
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/utils/filesystem.js
  • packages/bruno-electron/src/utils/filesystem.test.js

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

🧹 Nitpick comments (1)
tests/workspace/move-collection-to-workspace.spec.ts (1)

59-68: ⚡ Quick win

Use locator variables for repeated test selectors.

In these flow-critical steps, selectors are inlined repeatedly (page.getByTestId(...), page.getByText(...)). Please extract them into local locator variables for readability and easier maintenance.

As per coding guidelines, in tests/**/**.* you should “Use locator variables for locators.”

Also applies to: 148-157

🤖 Prompt for 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.

In `@tests/workspace/move-collection-to-workspace.spec.ts` around lines 59 - 68,
Extract repeated inline selectors into local locator variables: assign
page.getByTestId('collection-actions-move-to-workspace') to a variable (e.g.,
moveActionBtn), reuse the existing moveModal locator for the 'Move' button
(e.g., moveButton = locators.modal.button('Move')), and assign
page.getByText('Collection moved into workspace') to a successToast variable;
then replace the inline calls in the test step (and similarly at lines 148-157)
to use these locator variables. Keep references to openCollectionMenu(page,
collectionName), moveModal, and locators.modal.button('Move') so the changes are
minimal and improve readability/maintenance.

Source: Coding guidelines

🤖 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 `@tests/workspace/move-collection-to-workspace.spec.ts`:
- Around line 148-161: The test currently only checks that the collection was
moved (fs.existsSync on sourcePath/destinationPath) but not that the draft
changes were discarded; after the discard click in the test step (inside the
'Move shows the drafts confirmation, then discard and move' step, after await
page.getByTestId('move-workspace-discard-all').click() and before asserting the
move notification), read the moved collection file(s) at destinationPath (using
the same variables sourcePath/destinationPath and fs) and assert that the
on-disk request content does NOT contain the modified draft change (e.g., the
changed URL or modified body) to prove discard happened; keep existing
expectations (expect(fs.existsSync...)) and also use
locators.sidebar.collection(collectionName) to ensure UI consistency.

---

Nitpick comments:
In `@tests/workspace/move-collection-to-workspace.spec.ts`:
- Around line 59-68: Extract repeated inline selectors into local locator
variables: assign page.getByTestId('collection-actions-move-to-workspace') to a
variable (e.g., moveActionBtn), reuse the existing moveModal locator for the
'Move' button (e.g., moveButton = locators.modal.button('Move')), and assign
page.getByText('Collection moved into workspace') to a successToast variable;
then replace the inline calls in the test step (and similarly at lines 148-157)
to use these locator variables. Keep references to openCollectionMenu(page,
collectionName), moveModal, and locators.modal.button('Move') so the changes are
minimal and improve readability/maintenance.
🪄 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: 0aba1750-4c32-4ec1-ad1c-c39d4fa1780e

📥 Commits

Reviewing files that changed from the base of the PR and between 9ff797b and 4be96ad.

📒 Files selected for processing (1)
  • tests/workspace/move-collection-to-workspace.spec.ts

@gopu-bruno
gopu-bruno force-pushed the feat/move-external-collection-to-workspace branch from 9d8b971 to 4be96ad Compare June 9, 2026 11:08

@utkarsh-bruno utkarsh-bruno left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks fine to me

@naman-bruno
naman-bruno merged commit 1d3a412 into usebruno:main Jun 12, 2026
18 of 20 checks passed
abhishekp-bruno pushed a commit to abhishekp-bruno/bruno that referenced this pull request Jun 17, 2026
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.

3 participants