Repository navigation
fix: handle copy/paste item for requests & js file - #7656
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughChanged paste target computation in CollectionItem: when the focused item is a folder the paste target is that item's Changes
Sequence Diagram(s)Estimated code review effort🎯 3 (Moderate) | ⏱️ ~23 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
🧹 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
pasteItemaction 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
📒 Files selected for processing (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
sid-bruno
left a comment
There was a problem hiding this comment.
Needs to be further tested in the enterprise variant as well
There was a problem hiding this comment.
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 | 🟠 MajorPaste 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
📒 Files selected for processing (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
| // 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; | ||
| } |
There was a problem hiding this comment.
🧩 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=tsxRepository: 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 -80Repository: 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.jsRepository: 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:
- Update line 357 to show paste for both folders and requests
- Pass the copied item type to
handlePasteItemor read it frombrunoClipboarddirectly (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.
There was a problem hiding this comment.
🧹 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 nameAs 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
📒 Files selected for processing (1)
tests/shortcuts/bound-actions.spec.ts
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:
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
Tests