mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
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:
committed by
GitHub
parent
03dcb6b7b9
commit
ff975c44f2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user