From 6bb3967379cdf134baaabdd1e3c2f8bb496f4467 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Fri, 14 Oct 2022 02:12:59 +0530 Subject: [PATCH] feat: improved tab behaviour while closing a tab --- .../src/providers/ReduxStore/slices/tabs.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/tabs.js b/packages/bruno-app/src/providers/ReduxStore/slices/tabs.js index 36753db59..c34d9268d 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/tabs.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/tabs.js @@ -49,14 +49,24 @@ export const tabsSlice = createSlice({ } }, closeTabs: (state, action) => { + const activeTab = find(state.tabs, (t) => t.uid === state.activeTabUid); const tabUids = action.payload.tabUids || []; state.tabs = filter(state.tabs, (t) => !tabUids.includes(t.uid)); - if(state.tabs && state.tabs.length) { - // todo: closing tab needs to focus on the right adjacent tab - state.activeTabUid = last(state.tabs).uid; - } else { - state.activeTabUid = null; + if(activeTab && state.tabs.length) { + const { collectionUid } = activeTab; + const activeTabStillExists = find(state.tabs, (t) => t.uid === state.activeTabUid); + + if(!activeTabStillExists) { + // attempt to load sibling tabs (based on collections) of the dead tab + const siblingTabs = filter(state.tabs, (t) => t.collectionUid === collectionUid); + + if(siblingTabs && siblingTabs.length) { + state.activeTabUid = last(siblingTabs).uid; + } else { + state.activeTabUid = last(state.tabs).uid; + } + } } }, // todo: implement this