Skip to content

fix: handle copy/paste item for requests & js file - #7656

Merged
sid-bruno merged 4 commits into
usebruno:mainfrom
shubh-bruno:fix/handle-paste
Apr 2, 2026
Merged

sid-bruno merged 4 commits into
usebruno:mainfrom
shubh-bruno:fix/handle-paste

Conversation

@shubh-bruno

@shubh-bruno shubh-bruno commented Apr 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Problem :
Paste always placed items as siblings, and the "Paste" menu option only appeared on folders — not on requests.
Solution :
handlePasteItem now reads the clipboard to check the copied item type: if focused on a folder and the copied item is a request, it pastes inside the folder; otherwise it pastes as a sibling. The "Paste" dropdown menu item now shows on both folders and requests.

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

  • Bug Fixes

    • Improved paste behavior in the collections sidebar: when a folder is focused, pasted items go into that folder; otherwise they’re pasted alongside the focused item in its parent—reducing accidental placements and matching expected folder-focused behavior.
  • Tests

    • Updated sidebar copy/paste and search assertions to match the new paste placement and a more reliable search input selector.

@coderabbitai

coderabbitai Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

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: bbabc79a-a0a0-4209-a6b4-2e05bbb574b0

📥 Commits

Reviewing files that changed from the base of the PR and between 750fdf4 and cb860f2.

📒 Files selected for processing (2)
  • packages/bruno-app/src/components/Sidebar/Collections/CollectionSearch/index.js
  • tests/shortcuts/bound-actions.spec.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/bruno-app/src/components/Sidebar/Collections/CollectionSearch/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/shortcuts/bound-actions.spec.ts

Walkthrough

Changed paste target computation in CollectionItem: when the focused item is a folder the paste target is that item's uid; when it's not a folder the paste target resolves to the parent folder's uid. Added a data-testid to the sidebar search input and adjusted related test assertions; minor JSX indentation tweak.

Changes

Cohort / File(s) Summary
CollectionItem paste logic
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
Updated handlePasteItem to use the focused item's uid when that item is a folder; otherwise resolve parent-folder uid. Minor JSX indentation change in indent block.
CollectionSearch — test id added
packages/bruno-app/src/components/Sidebar/Collections/CollectionSearch/index.js
Added data-testid="sidebar-search-input" to the search input for stable test selection.
Tests — copy/paste & search assertions
tests/shortcuts/bound-actions.spec.ts
Switched sidebar search selection to getByTestId('sidebar-search-input'); adjusted timeouts and changed copy/paste assertions to expect base folder name count (toHaveCount(2)) instead of suffixed duplicate name visibility.

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~23 minutes

Possibly related PRs

Suggested reviewers

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

Poem

🗂️ A focused folder holds the spot,
Paste finds home where it sits, not the lot.
Tests now target, inputs named,
Indents neat, no logic maimed,
Small tweak — tidy, quick, and hot.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing copy/paste item handling for requests and JavaScript files, which aligns with the core issue described in the PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

🧹 Nitpick comments (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js (1)

568-581: Consider adding a guard for empty clipboard to avoid unnecessary dispatch.

The function reads clipboard directly but doesn't short-circuit when empty. While the pasteItem action will reject gracefully, you could exit early to avoid the dispatch and improve clarity.

🔧 Optional early return
 const handlePasteItem = () => {
   const clipboard = brunoClipboard.read();
+  if (!clipboard.hasData) {
+    toast.error('No item in clipboard');
+    return;
+  }
   const copiedItem = clipboard.hasData ? clipboard.items[0] : null;
   let targetFolderUid;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js`
around lines 568 - 581, handlePasteItem currently reads the clipboard via
brunoClipboard.read() but proceeds even when clipboard is empty; add an early
guard that returns immediately if clipboard.hasData is false (or if copiedItem
is null) before computing targetFolderUid or dispatching pasteItem to avoid
unnecessary dispatches; update logic around clipboard.hasData / copiedItem
checks in handlePasteItem (and keep existing isFolder, isItemAFolder,
findParentItemInCollection usage) so nothing else changes except the early
return when the clipboard is empty.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js`:
- Around line 568-581: handlePasteItem currently reads the clipboard via
brunoClipboard.read() but proceeds even when clipboard is empty; add an early
guard that returns immediately if clipboard.hasData is false (or if copiedItem
is null) before computing targetFolderUid or dispatching pasteItem to avoid
unnecessary dispatches; update logic around clipboard.hasData / copiedItem
checks in handlePasteItem (and keep existing isFolder, isItemAFolder,
findParentItemInCollection usage) so nothing else changes except the early
return when the clipboard is empty.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bb4c79d4-1c34-4db4-992b-ceccaa0dfa5b

📥 Commits

Reviewing files that changed from the base of the PR and between 7ddd2d3 and 176e654.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js

@sid-bruno sid-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.

Needs to be further tested in the enterprise variant as well

sid-bruno
sid-bruno previously approved these changes Apr 2, 2026

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js (1)

357-364: ⚠️ Potential issue | 🟠 Major

Paste menu is still hidden for request items

Line 357 still requires isFolder && hasCopiedItems, so requests never show the Paste action.

Proposed fix
-    if (isFolder && hasCopiedItems) {
+    if (hasCopiedItems) {
       items.push({
         id: 'paste',
         leftSection: IconClipboard,
         label: 'Paste',
         onClick: handlePasteItem
       });
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js`
around lines 357 - 364, The Paste action is gated by the wrong condition; update
the conditional that adds the paste menu entry so it only checks for
hasCopiedItems (remove the isFolder check) so requests can receive the Paste
entry; specifically modify the block that pushes the item ({ id: 'paste',
leftSection: IconClipboard, label: 'Paste', onClick: handlePasteItem }) so it
runs when hasCopiedItems is true rather than when isFolder && hasCopiedItems is
true.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js`:
- Around line 568-573: The paste menu should be visible for folders and requests
(not only folders) and must not reference the non-existent Redux key
clipboardCopiedItemType; change the visibility check (where isFolder and
hasCopiedItems are used) to allow paste when (isFolder || isRequest) &&
hasCopiedItems, and update the paste handler so it obtains the copied item type
from brunoClipboard.read().items[0] (or accept it as an explicit argument)
instead of reading a Redux field; then keep the existing destination logic in
handlePasteItem/pasteItem that uses findParentItemInCollection, targetFolderUid,
collection and item.uid to decide whether to paste into the folder or the parent
folder.

---

Outside diff comments:
In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js`:
- Around line 357-364: The Paste action is gated by the wrong condition; update
the conditional that adds the paste menu entry so it only checks for
hasCopiedItems (remove the isFolder check) so requests can receive the Paste
entry; specifically modify the block that pushes the item ({ id: 'paste',
leftSection: IconClipboard, label: 'Paste', onClick: handlePasteItem }) so it
runs when hasCopiedItems is true rather than when isFolder && hasCopiedItems is
true.
🪄 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: 82087a52-6898-4d50-96b0-8892c172e068

📥 Commits

Reviewing files that changed from the base of the PR and between 176e654 and dec2f77.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js

Comment on lines +568 to +573
// Determine target folder: if item is a folder, paste into it; otherwise paste into parent folder
let targetFolderUid = item.uid;
if (!isFolder) {
const parentFolder = findParentItemInCollection(collection, item.uid);
targetFolderUid = parentFolder ? parentFolder.uid : null;
}

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Clipboard state shape =="
rg -n -C4 "clipboard|hasCopiedItems|copiedItem|copyRequest" --type=js --type=jsx --type=ts --type=tsx

echo
echo "== pasteItem action definition and target handling =="
rg -n -C12 "pasteItem\\s*\\(|export\\s+const\\s+pasteItem|function\\s+pasteItem" --type=js --type=jsx --type=ts --type=tsx

echo
echo "== call sites of pasteItem in sidebar components =="
rg -n -C3 "dispatch\\(pasteItem\\(" --type=js --type=jsx --type=ts --type=tsx

Repository: usebruno/bruno

Length of output: 130


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Clipboard state shape =="
rg -n -C4 "clipboard|hasCopiedItems|copiedItem|copyRequest" --type=js --type=ts 2>/dev/null || echo "Search completed with possible partial results"

echo
echo "== pasteItem action definition and target handling =="
rg -n -C12 "pasteItem\s*\(|export\s+(const|function)\s+pasteItem|function\s+pasteItem" --type=js --type=ts 2>/dev/null || echo "Search completed"

echo
echo "== call sites of pasteItem in sidebar components =="
rg -n -C3 "dispatch\(pasteItem\(" --type=js --type=ts 2>/dev/null || echo "Search completed"

Repository: usebruno/bruno

Length of output: 50370


🏁 Script executed:

#!/bin/bash
echo "=== CollectionItem/index.js lines 357-375 (paste menu visibility) ==="
sed -n '357,375p' packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js

echo
echo "=== CollectionItem/index.js lines 568-580 (handlePasteItem logic) ==="
sed -n '568,580p' packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js

echo
echo "=== brunoClipboard structure ==="
rg -n -A30 "export.*brunoClipboard|class.*brunoClipboard" --type=js --type=ts | head -80

Repository: usebruno/bruno

Length of output: 1358


🏁 Script executed:

#!/bin/bash
echo "=== Full brunoClipboard implementation ==="
cat packages/bruno-app/src/utils/bruno-clipboard.js

echo
echo "=== pasteItem action full logic (lines 960-1040) ==="
sed -n '960,1040p' packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js

Repository: usebruno/bruno

Length of output: 3843


Paste menu visibility should allow requests, but proposed fix references non-existent state property

Line 357 correctly limits paste menu to folders only (if (isFolder && hasCopiedItems)), but based on the PR objective, this should also appear on requests. However, the proposed fix incorrectly references clipboardCopiedItemType, which does not exist in Redux state.

The clipboard item type is available from brunoClipboard.read().items[0] (downstream in the pasteItem action), not from Redux state. The Redux clipboard state only tracks hasCopiedItems boolean. To fix this properly:

  1. Update line 357 to show paste for both folders and requests
  2. Pass the copied item type to handlePasteItem or read it from brunoClipboard directly (not from non-existent Redux property)

The paste destination logic at lines 568–573 is correct: folders paste into themselves, requests paste into their parent folder (as siblings).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js`
around lines 568 - 573, The paste menu should be visible for folders and
requests (not only folders) and must not reference the non-existent Redux key
clipboardCopiedItemType; change the visibility check (where isFolder and
hasCopiedItems are used) to allow paste when (isFolder || isRequest) &&
hasCopiedItems, and update the paste handler so it obtains the copied item type
from brunoClipboard.read().items[0] (or accept it as an explicit argument)
instead of reading a Redux field; then keep the existing destination logic in
handlePasteItem/pasteItem that uses findParentItemInCollection, targetFolderUid,
collection and item.uid to decide whether to paste into the folder or the parent
folder.

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

🧹 Nitpick comments (2)
tests/shortcuts/bound-actions.spec.ts (2)

1341-1342: Same concern: assertion doesn't validate hierarchy.

Consistent with the previous test, this assertion verifies count but not the actual paste location. The comment and assertion are misaligned.

🔧 Suggested fix
-        // Verify copied item appears in sidebar as child of folder
-        await expect(page.locator('.collection-item-name').filter({ hasText: 'kb-folder-copy-src' })).toHaveCount(2);
+        // Verify copied folder appears in sidebar with deduplicated name
+        await expect(page.locator('.collection-item-name').filter({ hasText: 'kb-folder-copy-src (1)' })).toBeVisible({ timeout: 2000 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/shortcuts/bound-actions.spec.ts` around lines 1341 - 1342, The
assertion only checks there are two elements with text 'kb-folder-copy-src' but
doesn't verify that the copy is nested under the target folder; update the test
to locate the target folder node (e.g. find the folder element used in this
test) and then assert that within that folder's subtree there is exactly one
child with '.collection-item-name' and text 'kb-folder-copy-src' (instead of the
global count). Use the existing selectors ('.collection-item-name' and the
folder locator used elsewhere in this spec) to scope the lookup and validate
hierarchy.

1263-1264: Assertion doesn't verify the parent-child relationship claimed in the comment.

The comment states the copied item should appear "as child of folder," but toHaveCount(2) only verifies two elements containing 'kb-folder' text exist—it doesn't confirm hierarchy. This would pass whether the pasted folder is a child inside 'kb-folder' or a sibling next to it.

Consider asserting the nested structure explicitly, or adjust the comment to reflect what's actually being verified.

🔧 Suggested approach to verify child relationship
-        // Verify copied item appears in sidebar as child of folder
-        await expect(page.locator('.collection-item-name').filter({ hasText: 'kb-folder' })).toHaveCount(2);
+        // Verify copied folder appears as sibling or child (expand folder first if child)
+        // If pasted as child, we need to expand the folder to see it
+        await page.locator('.collection-item-name').filter({ hasText: 'kb-folder' }).first().click();
+        await expect(page.locator('.collection-item-name').filter({ hasText: 'kb-folder (1)' })).toBeVisible({ timeout: 2000 });

Alternatively, if the intent is just to verify a duplicate exists (without verifying location), update the comment:

-        // Verify copied item appears in sidebar as child of folder
+        // Verify copied folder appears in sidebar with deduplicated name

As per coding guidelines: "Aim for tests that fail usefully. When a test fails, it should clearly indicate what behaviour broke and why."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/shortcuts/bound-actions.spec.ts` around lines 1263 - 1264, The
assertion currently checks only that two elements contain 'kb-folder' (await
expect(page.locator('.collection-item-name').filter({ hasText: 'kb-folder'
})).toHaveCount(2)) but does not verify a parent-child relationship; replace
this with an assertion that explicitly finds the parent folder element (e.g.,
the folder row or container with text 'kb-folder' using the same
'.collection-item-name' locator) and then queries within that element for a
nested child named 'kb-folder' (using locator.locator(...) or a descendant
selector) and assert that the nested child exists (or counts to 1). If the
intent was only to assert a duplicate exists, instead update the test comment to
state that it verifies a duplicate appears rather than a nested child.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/shortcuts/bound-actions.spec.ts`:
- Around line 1341-1342: The assertion only checks there are two elements with
text 'kb-folder-copy-src' but doesn't verify that the copy is nested under the
target folder; update the test to locate the target folder node (e.g. find the
folder element used in this test) and then assert that within that folder's
subtree there is exactly one child with '.collection-item-name' and text
'kb-folder-copy-src' (instead of the global count). Use the existing selectors
('.collection-item-name' and the folder locator used elsewhere in this spec) to
scope the lookup and validate hierarchy.
- Around line 1263-1264: The assertion currently checks only that two elements
contain 'kb-folder' (await expect(page.locator('.collection-item-name').filter({
hasText: 'kb-folder' })).toHaveCount(2)) but does not verify a parent-child
relationship; replace this with an assertion that explicitly finds the parent
folder element (e.g., the folder row or container with text 'kb-folder' using
the same '.collection-item-name' locator) and then queries within that element
for a nested child named 'kb-folder' (using locator.locator(...) or a descendant
selector) and assert that the nested child exists (or counts to 1). If the
intent was only to assert a duplicate exists, instead update the test comment to
state that it verifies a duplicate appears rather than a nested child.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 239b4305-3508-49a5-b238-4a6fcf944372

📥 Commits

Reviewing files that changed from the base of the PR and between dec2f77 and 750fdf4.

📒 Files selected for processing (1)
  • tests/shortcuts/bound-actions.spec.ts

@sid-bruno
sid-bruno merged commit 5cd3e7a into usebruno:main Apr 2, 2026
11 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Apr 2, 2026
6 tasks
maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 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.

2 participants