From 6a0eb1ccdedee6385ad304135ca4b9b983a0d1df Mon Sep 17 00:00:00 2001 From: naman-bruno Date: Tue, 11 Feb 2025 14:03:04 +0530 Subject: [PATCH] fix: nonReplaceableTabTypes getting duplicate --- .../src/providers/ReduxStore/slices/tabs.js | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/tabs.js b/packages/bruno-app/src/providers/ReduxStore/slices/tabs.js index 91b39b33d..219655d70 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/tabs.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/tabs.js @@ -11,24 +11,35 @@ const initialState = { activeTabUid: null }; +const tabTypeAlreadyExists = (tabs, collectionUid, type) => { + return find(tabs, (tab) => tab.collectionUid === collectionUid && tab.type === type); +}; + export const tabsSlice = createSlice({ name: 'tabs', initialState, reducers: { addTab: (state, action) => { const { uid, collectionUid, type, requestPaneTab, preview } = action.payload; - - const existingTab = find(state.tabs, (tab) => tab.uid === uid); - - if (existingTab) { - state.activeTabUid = existingTab.uid; - return; - } const nonReplaceableTabTypes = [ "variables", "collection-runner", "security-settings", ]; + + const existingTab = find(state.tabs, (tab) => tab.uid === uid); + if (existingTab) { + state.activeTabUid = existingTab.uid; + return; + } + + if (nonReplaceableTabTypes.includes(type)) { + const existingTab = tabTypeAlreadyExists(state.tabs, collectionUid, type); + if (existingTab) { + state.activeTabUid = existingTab.uid; + return; + } + } const lastTab = state.tabs[state.tabs.length - 1]; if (state.tabs.length > 0 && lastTab.preview) { @@ -39,7 +50,9 @@ export const tabsSlice = createSlice({ requestPaneTab: requestPaneTab || 'params', responsePaneTab: 'response', type: type || 'request', - preview: true, + preview: preview !== undefined + ? preview + : !nonReplaceableTabTypes.includes(type), ...(uid ? { folderUid: uid } : {}) }