fix: example tab not closing post delete, tab not found issue when i delete intermediate example (#6561)

This commit is contained in:
sanish chirayath
2025-12-30 14:44:57 +05:30
committed by GitHub
parent 5dad137631
commit d7cef7aa4e
3 changed files with 33 additions and 3 deletions

View File

@@ -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,

View File

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

View File

@@ -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) {