mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-15 11:51:30 +00:00
fix: example tab not closing post delete, tab not found issue when i delete intermediate example (#6561)
This commit is contained in:
@@ -4,11 +4,14 @@ import Portal from 'components/Portal';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { deleteResponseExample } from 'providers/ReduxStore/slices/collections';
|
||||
import { saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import { closeTabs } from 'providers/ReduxStore/slices/tabs';
|
||||
|
||||
const DeleteResponseExampleModal = ({ onClose, example, item, collection }) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const onConfirm = () => {
|
||||
const onConfirm = (e) => {
|
||||
e.stopPropagation();
|
||||
dispatch(closeTabs({ tabUids: [example.uid] }));
|
||||
dispatch(deleteResponseExample({
|
||||
itemUid: item.uid,
|
||||
collectionUid: collection.uid,
|
||||
|
||||
26
packages/bruno-electron/src/cache/requestUids.js
vendored
26
packages/bruno-electron/src/cache/requestUids.js
vendored
@@ -49,9 +49,33 @@ const getExampleUid = (pathname, index) => {
|
||||
return uid;
|
||||
};
|
||||
|
||||
/**
|
||||
* Syncs the example UID cache with the current state of examples being saved.
|
||||
* This ensures the cache stays consistent when examples are added, deleted, or reordered.
|
||||
*
|
||||
* @param {string} pathname - The file path of the request
|
||||
* @param {Array} examples - The examples array being saved (each with a uid property)
|
||||
*/
|
||||
const syncExampleUidsCache = (pathname, examples = []) => {
|
||||
// Clear all existing cache entries for this pathname
|
||||
for (const key of exampleUids.keys()) {
|
||||
if (key.startsWith(`${pathname}-`)) {
|
||||
exampleUids.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
// Rebuild cache with current example UIDs at their new indices
|
||||
examples.forEach((example, index) => {
|
||||
if (example.uid) {
|
||||
exampleUids.set(`${pathname}-${index}`, example.uid);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getRequestUid,
|
||||
moveRequestUid,
|
||||
deleteRequestUid,
|
||||
getExampleUid
|
||||
getExampleUid,
|
||||
syncExampleUidsCache
|
||||
};
|
||||
|
||||
@@ -51,7 +51,7 @@ const {
|
||||
} = require('../utils/filesystem');
|
||||
const { openCollectionDialog, openCollectionsByPathname } = require('../app/collections');
|
||||
const { generateUidBasedOnHash, stringifyJson, safeStringifyJSON, safeParseJSON } = require('../utils/common');
|
||||
const { moveRequestUid, deleteRequestUid } = require('../cache/requestUids');
|
||||
const { moveRequestUid, deleteRequestUid, syncExampleUidsCache } = require('../cache/requestUids');
|
||||
const { deleteCookiesForDomain, getDomainsWithCookies, addCookieForDomain, modifyCookieForDomain, parseCookieString, createCookieString, deleteCookie } = require('../utils/cookies');
|
||||
const EnvironmentSecretsStore = require('../store/env-secrets');
|
||||
const CollectionSecurityStore = require('../store/collection-security');
|
||||
@@ -349,6 +349,9 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
throw new Error(`path: ${pathname} does not exist`);
|
||||
}
|
||||
|
||||
// Sync example UIDs cache to maintain consistency when examples are added/deleted/reordered
|
||||
syncExampleUidsCache(pathname, request.examples);
|
||||
|
||||
const content = await stringifyRequestViaWorker(request, { format });
|
||||
await writeFile(pathname, content);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user