diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js index 90272636c..8aaf15e4e 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js @@ -47,7 +47,7 @@ import ExampleIcon from 'components/Icons/ExampleIcon'; import { scrollToTheActiveTab } from 'utils/tabs'; import { isTabForItemActive as isTabForItemActiveSelector, isTabForItemPresent as isTabForItemPresentSelector } from 'src/selectors/tab'; import { isEqual } from 'lodash'; -import { calculateDraggedItemNewPathname, getInitialExampleName } from 'utils/collections/index'; +import { calculateDraggedItemNewPathname, getInitialExampleName, findParentItemInCollection } from 'utils/collections/index'; import { sortByNameThenSequence } from 'utils/common/index'; import CreateExampleModal from 'components/ResponseExample/CreateExampleModal'; import { openDevtoolsAndSwitchToTerminal } from 'utils/terminal'; @@ -533,13 +533,14 @@ const CollectionItem = ({ item, collectionUid, collectionPathname, searchText }) }; const handlePasteItem = () => { - // Only allow paste into folders + // Determine target folder: if item is a folder, paste into it; otherwise paste into parent folder + let targetFolderUid = item.uid; if (!isFolder) { - toast.error('Paste is only available for folders'); - return; + const parentFolder = findParentItemInCollection(collection, item.uid); + targetFolderUid = parentFolder ? parentFolder.uid : null; } - dispatch(pasteItem(collectionUid, item.uid)) + dispatch(pasteItem(collectionUid, targetFolderUid)) .then(() => { toast.success('Item pasted successfully'); }) diff --git a/tests/request/copy-request/copy-request.spec.ts b/tests/request/copy-request/copy-request.spec.ts index 395a87ec5..f8a899371 100644 --- a/tests/request/copy-request/copy-request.spec.ts +++ b/tests/request/copy-request/copy-request.spec.ts @@ -1,5 +1,5 @@ import { test, expect } from '../../../playwright'; -import { closeAllCollections, createCollection } from '../../utils/page'; +import { closeAllCollections, createCollection, createRequest } from '../../utils/page'; test.describe('Copy and Paste Requests', () => { test.afterAll(async ({ page }) => { @@ -66,4 +66,20 @@ test.describe('Copy and Paste Requests', () => { // Verify the pasted request appears with the same name await expect(page.locator('.collection-item-name').filter({ hasText: 'original-request' })).toHaveCount(4); }); + + test('should paste request into parent folder even if request is selected', async ({ page, createTmpDir }) => { + // Create a collection and a request + await createCollection(page, 'test-collection-3', await createTmpDir('test-collection-3')); + await createRequest(page, 'request-to-copy', 'test-collection-3'); + + const modifier = process.platform === 'darwin' ? 'Meta' : 'Control'; + + // Copy the request + await page.locator('.collection-item-name').filter({ hasText: 'request-to-copy' }).click(); + await page.keyboard.press(`${modifier}+C`); + await page.keyboard.press(`${modifier}+V`); + + // Verify the pasted request appears with the same name + await expect(page.locator('.collection-item-name').filter({ hasText: 'request-to-copy' })).toHaveCount(2); + }); });