refactor: centralize tab management (#6494)

* refactor: centralize tab management by removing redundant hide calls in Collection components

- Removed dispatch calls for hiding home and API spec pages from Collection and CollectionItem components.
- Added logic in app slice to automatically hide these pages when a tab is added or focused, improving code maintainability.

* refactor: remove redundant hideHomePage dispatches from components
This commit is contained in:
Abhishek S Lal
2025-12-23 19:19:25 +05:30
committed by GitHub
parent aeb6b12b06
commit d93d1eacdb
7 changed files with 16 additions and 19 deletions

View File

@@ -6,7 +6,6 @@ import { useDispatch, useSelector } from 'react-redux';
import { isItemARequest, itemIsOpenedInTabs } from 'utils/tabs/index';
import { getDefaultRequestPaneTab } from 'utils/collections/index';
import { addTab, focusTab } from 'providers/ReduxStore/slices/tabs';
import { hideHomePage } from 'providers/ReduxStore/slices/app';
const RequestsNotLoaded = ({ collection }) => {
const dispatch = useDispatch();
@@ -21,7 +20,6 @@ const RequestsNotLoaded = ({ collection }) => {
const handleRequestClick = (item) => (e) => {
e.preventDefault();
if (isItemARequest(item)) {
dispatch(hideHomePage());
if (itemIsOpenedInTabs(item, tabs)) {
dispatch(
focusTab({

View File

@@ -10,7 +10,6 @@ import {
} from '@tabler/icons';
import { flattenItems, isItemARequest, isItemAFolder, findParentItemInCollection } from 'utils/collections';
import { addTab, focusTab } from 'providers/ReduxStore/slices/tabs';
import { hideHomePage } from 'providers/ReduxStore/slices/app';
import { toggleCollectionItem, toggleCollection } from 'providers/ReduxStore/slices/collections';
import { mountCollection } from 'providers/ReduxStore/slices/collections/actions';
import { getDefaultRequestPaneTab } from 'utils/collections';
@@ -246,8 +245,6 @@ const GlobalSearchModal = ({ isOpen, onClose }) => {
expandItemPath(result);
if (result.type === SEARCH_TYPES.REQUEST) {
dispatch(hideHomePage());
const existingTab = tabs.find((tab) => tab.uid === result.item.uid);
if (existingTab) {

View File

@@ -37,7 +37,6 @@ import GenerateCodeItem from './GenerateCodeItem';
import { isItemARequest, isItemAFolder } from 'utils/tabs';
import { doesRequestMatchSearchText, doesFolderHaveItemsMatchSearchText } from 'utils/collections/search';
import { getDefaultRequestPaneTab } from 'utils/collections';
import { hideHomePage, hideApiSpecPage } from 'providers/ReduxStore/slices/app';
import toast from 'react-hot-toast';
import StyledWrapper from './StyledWrapper';
import NetworkError from 'components/ResponsePane/NetworkError/index';
@@ -214,8 +213,6 @@ const CollectionItem = ({ item, collectionUid, collectionPathname, searchText })
setTimeout(scrollToTheActiveTab, 50);
const isRequest = isItemARequest(item);
if (isRequest) {
dispatch(hideHomePage());
dispatch(hideApiSpecPage());
if (isTabForItemPresent) {
dispatch(
focusTab({
@@ -233,8 +230,6 @@ const CollectionItem = ({ item, collectionUid, collectionPathname, searchText })
})
);
} else {
dispatch(hideHomePage());
dispatch(hideApiSpecPage());
dispatch(
addTab({
uid: item.uid,

View File

@@ -24,7 +24,6 @@ import {
import { toggleCollection, collapseFullCollection } from 'providers/ReduxStore/slices/collections';
import { mountCollection, moveCollectionAndPersist, handleCollectionItemDrop, pasteItem, showInFolder, saveCollectionSecurityConfig } from 'providers/ReduxStore/slices/collections/actions';
import { useDispatch, useSelector } from 'react-redux';
import { hideApiSpecPage, hideHomePage } from 'providers/ReduxStore/slices/app';
import { addTab, makeTabPermanent } from 'providers/ReduxStore/slices/tabs';
import toast from 'react-hot-toast';
import NewRequest from 'components/Sidebar/NewRequest';
@@ -111,8 +110,6 @@ const Collection = ({ collection, searchText }) => {
}
if (!isChevronClick) {
dispatch(hideHomePage()); // @TODO Playwright tests are often stuck on home page, rather than collection settings tab. Revisit for a proper fix.
dispatch(hideApiSpecPage());
dispatch(
addTab({
uid: collection.uid,

View File

@@ -3,7 +3,6 @@ import { useSelector, useDispatch } from 'react-redux';
import { IconBox, IconTrash, IconEdit, IconShare, IconDots } from '@tabler/icons';
import { removeCollectionFromWorkspaceAction } from 'providers/ReduxStore/slices/workspaces/actions';
import { addTab } from 'providers/ReduxStore/slices/tabs';
import { hideHomePage } from 'providers/ReduxStore/slices/app';
import { mountCollection } from 'providers/ReduxStore/slices/collections/actions';
import { normalizePath } from 'utils/common/path';
import toast from 'react-hot-toast';
@@ -117,8 +116,6 @@ const CollectionsList = ({ workspace }) => {
})
);
dispatch(hideHomePage());
dispatch(
addTab({
uid: collection.uid,

View File

@@ -2,7 +2,7 @@ import get from 'lodash/get';
import each from 'lodash/each';
import filter from 'lodash/filter';
import { createListenerMiddleware } from '@reduxjs/toolkit';
import { removeTaskFromQueue, hideHomePage } from 'providers/ReduxStore/slices/app';
import { removeTaskFromQueue } from 'providers/ReduxStore/slices/app';
import { addTab } from 'providers/ReduxStore/slices/tabs';
import { collectionAddFileEvent, collectionChangeFileEvent } from 'providers/ReduxStore/slices/collections';
import { findCollectionByUid, findItemInCollectionByPathname, getDefaultRequestPaneTab, findItemInCollectionByItemUid } from 'utils/collections/index';
@@ -37,7 +37,6 @@ taskMiddleware.startListening({
requestPaneTab: getDefaultRequestPaneTab(item)
})
);
listenerApi.dispatch(hideHomePage());
}
}
@@ -80,7 +79,6 @@ taskMiddleware.startListening({
type: 'response-example',
itemUid: item.uid
}));
listenerApi.dispatch(hideHomePage());
}
}
}

View File

@@ -1,6 +1,7 @@
import { createSlice } from '@reduxjs/toolkit';
import filter from 'lodash/filter';
import brunoClipboard from 'utils/bruno-clipboard';
import { addTab, focusTab } from './tabs';
const initialState = {
isDragging: false,
@@ -127,6 +128,20 @@ export const appSlice = createSlice({
// Update clipboard UI state
state.clipboard.hasCopiedItems = action.payload.hasCopiedItems;
}
},
extraReducers: (builder) => {
// Automatically hide special pages when any tab is added or focused
builder
.addCase(addTab, (state) => {
state.showHomePage = false;
state.showApiSpecPage = false;
state.showManageWorkspacePage = false;
})
.addCase(focusTab, (state) => {
state.showHomePage = false;
state.showApiSpecPage = false;
state.showManageWorkspacePage = false;
});
}
});