Skip to content

Commit 6775756

Browse files
committed
Add initial support for collapsing devtools
1 parent a8ad575 commit 6775756

File tree

4 files changed

+85
-64
lines changed

4 files changed

+85
-64
lines changed
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading

dash/dash-renderer/src/components/error/menu/DebugMenu.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
right: 8px;
118118
display: flex;
119119
color: black;
120-
flex-direction: column;
120+
flex-direction: row;
121121
font-family: Verdana, sans-serif !important;
122122
font-size: 14px;
123123
justify-content: center;

dash/dash-renderer/src/components/error/menu/DebugMenu.react.js

Lines changed: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {Component} from 'react';
1+
import React, {useState} from 'react';
22
import PropTypes from 'prop-types';
33
import {concat} from 'ramda';
44

@@ -9,13 +9,24 @@ import ClockIcon from '../icons/ClockIcon.svg';
99
import ErrorIcon from '../icons/ErrorIcon.svg';
1010
import GraphIcon from '../icons/GraphIcon.svg';
1111
import OffIcon from '../icons/OffIcon.svg';
12+
import Collapse from '../icons/Collapse.svg';
13+
import Expand from '../icons/Expand.svg';
1214
import {VersionInfo} from './VersionInfo.react';
1315
import {CallbackGraphContainer} from '../CallbackGraph/CallbackGraphContainer.react';
1416
import {FrontEndErrorContainer} from '../FrontEnd/FrontEndErrorContainer.react';
1517

1618
const classes = (base, variant, variant2) =>
1719
`${base} ${base}--${variant}` + (variant2 ? ` ${base}--${variant2}` : '');
1820

21+
const isCollapsed = () => {
22+
try {
23+
return localStorage.getItem('dash_debug_menu_collapsed') === 'true';
24+
} catch (e) {
25+
// If localStorage is not available, default to false
26+
return false;
27+
}
28+
}
29+
1930
const MenuContent = ({
2031
hotReload,
2132
connected,
@@ -81,71 +92,73 @@ const MenuContent = ({
8192
);
8293
};
8394

84-
class DebugMenu extends Component {
85-
constructor(props) {
86-
super(props);
95+
const DebugMenu = ({error, hotReload, config, children}) => {
96+
const [popup, setPopup] = useState('errors');
97+
const [collapsed, setCollapsed] = useState(isCollapsed);
98+
99+
const errCount = error.frontEnd.length + error.backEnd.length;
100+
const connected = error.backEndConnected;
101+
102+
const toggleErrors = () => {
103+
setPopup(popup == 'errors' ? null : 'errors');
104+
};
105+
106+
const toggleCallbackGraph = () => {
107+
setPopup(popup == 'callbackGraph' ? null : 'callbackGraph')
108+
};
109+
110+
const errors = concat(error.frontEnd, error.backEnd);
111+
112+
const popupContent = (
113+
<div className='dash-debug-menu__popup'>
114+
{popup == 'callbackGraph' ? (
115+
<CallbackGraphContainer />
116+
) : undefined}
117+
{popup == 'errors' && errCount > 0 ? (
118+
<FrontEndErrorContainer
119+
clickHandler={toggleErrors}
120+
errors={errors}
121+
connected={error.backEndConnected}
122+
/>
123+
) : undefined}
124+
</div>
125+
);
87126

88-
this.state = {
89-
opened: false,
90-
popup: 'errors'
91-
};
92-
}
127+
const menuContent = (
128+
collapsed ?
129+
undefined :
130+
<MenuContent
131+
popup={popup}
132+
errCount={errCount}
133+
toggleErrors={toggleErrors}
134+
toggleCallbackGraph={toggleCallbackGraph}
135+
config={config}
136+
hotReload={hotReload}
137+
connected={connected}
138+
/>
139+
);
93140

94-
render() {
95-
const {popup} = this.state;
96-
const {error, hotReload, config} = this.props;
97-
const errCount = error.frontEnd.length + error.backEnd.length;
98-
const connected = error.backEndConnected;
99-
100-
const toggleErrors = () => {
101-
this.setState({popup: popup == 'errors' ? null : 'errors'});
102-
};
103-
104-
const toggleCallbackGraph = () => {
105-
this.setState({
106-
popup: popup == 'callbackGraph' ? null : 'callbackGraph'
107-
});
108-
};
109-
110-
const errors = concat(error.frontEnd, error.backEnd);
111-
112-
const popupContent = (
113-
<div className='dash-debug-menu__popup'>
114-
{popup == 'callbackGraph' ? (
115-
<CallbackGraphContainer />
116-
) : undefined}
117-
{popup == 'errors' && errCount > 0 ? (
118-
<FrontEndErrorContainer
119-
clickHandler={toggleErrors}
120-
errors={errors}
121-
connected={error.backEndConnected}
122-
/>
123-
) : undefined}
124-
</div>
125-
);
126-
127-
const menuContent = (
128-
<MenuContent
129-
popup={popup}
130-
errCount={errCount}
131-
toggleErrors={toggleErrors}
132-
toggleCallbackGraph={toggleCallbackGraph}
133-
config={config}
134-
hotReload={hotReload}
135-
connected={connected}
136-
/>
137-
);
138-
139-
return (
140-
<div>
141-
<div className={classes('dash-debug-menu__outer')}>
142-
{popupContent}
143-
{menuContent}
144-
</div>
145-
{this.props.children}
141+
return (
142+
<div>
143+
<div className={classes('dash-debug-menu__outer')}>
144+
{popupContent}
145+
{menuContent}
146+
<button onClick={
147+
() => {
148+
setCollapsed(!collapsed);
149+
try {
150+
localStorage.setItem('dash_debug_menu_collapsed', !collapsed);
151+
} catch (e) {
152+
// If localStorage is not available, do nothing
153+
}
154+
}
155+
}>
156+
{collapsed ? <Expand/> : <Collapse/>}
157+
</button>
146158
</div>
147-
);
148-
}
159+
{children}
160+
</div>
161+
);
149162
}
150163

151164
DebugMenu.propTypes = {

0 commit comments

Comments
 (0)