fix: cross-collection drag and drop tab and format issues (#7584)

Close the open tab when a request is moved to a different collection
via drag and drop, preventing the "Request no longer exists" error.

Add format conversion when dragging requests between collections with
different formats (.bru vs .yml). A new IPC handler parses the source
file and re-serializes it in the target collection's format. Folder
cross-format moves are blocked with a toast error.

Co-authored-by: Chirag Chandrashekhar <cchirag85@gmail.com>
This commit is contained in:
Chirag Chandrashekhar
2026-03-26 20:32:29 +05:30
committed by GitHub
parent 03dcb6b7b9
commit ff975c44f2
9 changed files with 206 additions and 4 deletions

View File

@@ -1448,6 +1448,40 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
}
});
ipcMain.handle('renderer:move-item-cross-format', async (event, { targetDirname, sourcePathname, sourceFormat, targetFormat }) => {
try {
if (!fs.existsSync(sourcePathname)) {
throw new Error(`Source path: ${sourcePathname} does not exist`);
}
if (!fs.existsSync(targetDirname)) {
throw new Error(`Target directory: ${targetDirname} does not exist`);
}
const sourceBasename = path.basename(sourcePathname);
const filenameWithoutExt = sourceBasename.replace(/\.(bru|yml|yaml)$/, '');
const targetExt = targetFormat === 'yml' ? 'yml' : 'bru';
const targetFilename = `${filenameWithoutExt}.${targetExt}`;
const targetPathname = path.join(targetDirname, targetFilename);
if (fs.existsSync(targetPathname)) {
throw new Error(`A file with the name "${targetFilename}" already exists in the target location`);
}
const sourceContent = await fs.promises.readFile(sourcePathname, 'utf8');
const parsedRequest = parseRequest(sourceContent, { format: sourceFormat });
const finalContent = stringifyRequest(parsedRequest, { format: targetFormat });
await writeFile(targetPathname, finalContent);
await removePath(sourcePathname);
moveRequestUid(sourcePathname, targetPathname);
return { newPathname: targetPathname };
} catch (error) {
return Promise.reject(error);
}
});
ipcMain.handle('renderer:move-folder-item', async (event, folderPath, destinationPath) => {
try {
const folderName = path.basename(folderPath);