fix: pasting request ito parent folder even if request is selected (#6446)

This commit is contained in:
Pooja
2025-12-24 12:14:37 +05:30
committed by GitHub
parent c2acc25461
commit 1f05ffd469
2 changed files with 23 additions and 6 deletions

View File

@@ -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');
})

View File

@@ -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);
});
});