@@ -13,7 +13,14 @@ import '@reach/menu-button/styles.css';
1313import '@reach/tooltip/styles.css' ;
1414
1515import * as React from 'react' ;
16- import { useCallback , useEffect , useLayoutEffect , useMemo , useRef } from 'react' ;
16+ import {
17+ useCallback ,
18+ useContext ,
19+ useEffect ,
20+ useLayoutEffect ,
21+ useMemo ,
22+ useRef ,
23+ } from 'react' ;
1724import Store from '../store' ;
1825import {
1926 BridgeContext ,
@@ -27,7 +34,10 @@ import SuspenseTab from './SuspenseTab/SuspenseTab';
2734import TabBar from './TabBar' ;
2835import EditorPane from './Editor/EditorPane' ;
2936import InspectedElementPane from './InspectedElement/InspectedElementPane' ;
30- import { SettingsContextController } from './Settings/SettingsContext' ;
37+ import {
38+ SettingsContext ,
39+ SettingsContextController ,
40+ } from './Settings/SettingsContext' ;
3141import { TreeContextController } from './Components/TreeContext' ;
3242import ViewElementSourceContext from './Components/ViewElementSourceContext' ;
3343import FetchFileWithCachingContext from './Components/FetchFileWithCachingContext' ;
@@ -135,7 +145,46 @@ const suspenseTab = {
135145 title : 'React Suspense' ,
136146} ;
137147
138- const tabs = [ componentsTab , profilerTab , suspenseTab ] ;
148+ const allTabs = [ componentsTab , profilerTab , suspenseTab ] ;
149+
150+ function DevToolsNavigationTabBar ( {
151+ currentTab,
152+ selectTab,
153+ } : {
154+ currentTab : TabID ,
155+ selectTab : ( tabId : TabID ) => void ,
156+ } ) : React . Node {
157+ const { hideProfilerTab, hideSuspenseTab} = useContext ( SettingsContext ) ;
158+ const visibleTabs = useMemo (
159+ ( ) =>
160+ allTabs . filter (
161+ t =>
162+ ! ( hideProfilerTab && t . id === 'profiler' ) &&
163+ ! ( hideSuspenseTab && t . id === 'suspense' ) ,
164+ ) ,
165+ [ hideProfilerTab , hideSuspenseTab ] ,
166+ ) ;
167+
168+ // If the active tab is hidden, switch to components
169+ useEffect ( ( ) => {
170+ if (
171+ ( hideProfilerTab && currentTab === 'profiler' ) ||
172+ ( hideSuspenseTab && currentTab === 'suspense' )
173+ ) {
174+ selectTab ( 'components' ) ;
175+ }
176+ } , [ hideProfilerTab , hideSuspenseTab , currentTab , selectTab ] ) ;
177+
178+ return (
179+ < TabBar
180+ currentTab = { currentTab }
181+ id = "DevTools"
182+ selectTab = { selectTab }
183+ tabs = { visibleTabs }
184+ type = "navigation"
185+ />
186+ ) ;
187+ }
139188
140189export default function DevTools ( {
141190 bridge,
@@ -248,18 +297,18 @@ export default function DevTools({
248297 if ( event . ctrlKey || event . metaKey ) {
249298 switch ( event . key ) {
250299 case '1' :
251- selectTab ( tabs [ 0 ] . id ) ;
300+ selectTab ( allTabs [ 0 ] . id ) ;
252301 event . preventDefault ( ) ;
253302 event . stopPropagation ( ) ;
254303 break ;
255304 case '2' :
256- selectTab ( tabs [ 1 ] . id ) ;
305+ selectTab ( allTabs [ 1 ] . id ) ;
257306 event . preventDefault ( ) ;
258307 event . stopPropagation ( ) ;
259308 break ;
260309 case '3' :
261- if ( tabs . length > 2 ) {
262- selectTab ( tabs [ 2 ] . id ) ;
310+ if ( allTabs . length > 2 ) {
311+ selectTab ( allTabs [ 2 ] . id ) ;
263312 event . preventDefault ( ) ;
264313 event . stopPropagation ( ) ;
265314 }
@@ -321,12 +370,9 @@ export default function DevTools({
321370 { process . env . DEVTOOLS_VERSION }
322371 </ span >
323372 < div className = { styles . Spacer } />
324- < TabBar
373+ < DevToolsNavigationTabBar
325374 currentTab = { tab }
326- id = "DevTools"
327375 selectTab = { selectTab }
328- tabs = { tabs }
329- type = "navigation"
330376 />
331377 </ div >
332378 ) }
0 commit comments