Skip to content

Commit 845d154

Browse files
author
Lucas Rebscher
committed
#393 Open LaunchDialog on splitButton action
* Refactor LaunchDialog use * Add SimpleDialog to replace ActionDialog since impl of ActionDialog provokes errors
1 parent aa1ceea commit 845d154

11 files changed

Lines changed: 168 additions & 70 deletions

File tree

webapp/components/NetPyNE.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
LayoutManager,
99
Drawer,
1010
Dialog,
11+
LaunchDialog,
1112
} from 'netpyne/components';
1213

1314
import Utils from '../Utils';
@@ -137,6 +138,7 @@ class NetPyNE extends React.Component {
137138
</div>
138139
<Dialog />
139140
<ErrorDialog />
141+
<LaunchDialog />
140142
</div>
141143
);
142144
}

webapp/components/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import {
2121
cloneExperiment,
2222
getExperiments,
23+
openLaunchDialog,
2324
} from '../redux/actions/experiments';
2425

2526
import {
@@ -60,6 +61,7 @@ import _SelectCellTemplate from './definition/cellRules/SelectCellTemplate';
6061
import _Experiments from './experiments/Experiments';
6162
import _ExperimentEdit from './experiments/ExperimentEdit';
6263
import _ExperimentManager from './experiments/ExperimentManager';
64+
import _LaunchDialog from './topbar/dialogs/LaunchDialog';
6365

6466
const updateCardsDispatch = (dispatch) => ({ updateCards: () => dispatch(updateCards) });
6567

@@ -117,6 +119,18 @@ export const Experiments = connect(
117119
}),
118120
)(_Experiments);
119121

122+
export const LaunchDialog = connect(
123+
(state, ownProps) => {
124+
const { inDesign, openLaunchDialog } = state.experiments;
125+
return ({
126+
...ownProps,
127+
open: openLaunchDialog,
128+
experimentName: inDesign == null ? '' : inDesign.name,
129+
numberOfTrials: inDesign == null ? '' : inDesign.trials.length,
130+
});
131+
},
132+
)(_LaunchDialog);
133+
120134
export const ExperimentEdit = _ExperimentEdit;
121135
export const ExperimentManager = _ExperimentManager;
122136

@@ -286,7 +300,7 @@ export const Topbar = connect(
286300
automaticInstantiation: state.general.automaticInstantiation,
287301
automaticSimulation: state.general.automaticSimulation,
288302
theme: state.general.theme,
289-
experimentInDesign: state.experiments.inDesign,
303+
experimentInDesign: state.experiments.inDesign != null,
290304
}),
291305
(dispatch) => ({
292306
dispatchAction: (action) => dispatch(action),
@@ -301,13 +315,15 @@ export const SwitchPageButton = connect(
301315
modelState: state.general.modelState,
302316
automaticInstantiation: state.general.automaticInstantiation,
303317
automaticSimulation: state.general.automaticSimulation,
318+
experimentInDesign: state.experiments.inDesign != null,
304319
}),
305320
(dispatch) => ({
306321
switchToEditModelPage: () => dispatch(editModel),
307322
createNetwork: () => dispatch(createNetwork),
308323
createAndSimulateNetwork: () => dispatch(createAndSimulateNetwork),
309324
showNetwork: () => dispatch(showNetwork),
310325
simulateNetwork: () => dispatch(simulateNetwork()),
326+
openLaunchDialog: () => dispatch(openLaunchDialog()),
311327
}),
312328
)(_SwitchPageButton);
313329

webapp/components/topbar/SwitchPageButton.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,17 @@ class SwitchPageButton extends Component {
5151
this.props.showNetwork();
5252
}
5353
} else if (selectedOption === SIMULATE) {
54-
this.props.simulateNetwork();
54+
if (this.props.experimentInDesign) {
55+
this.props.openLaunchDialog();
56+
} else {
57+
this.props.simulateNetwork();
58+
}
5559
} else if (selectedOption === CREATE_AND_SIMULATE) {
56-
this.props.createAndSimulateNetwork();
60+
if (this.props.experimentInDesign) {
61+
this.props.openLaunchDialog();
62+
} else {
63+
this.props.createAndSimulateNetwork();
64+
}
5765
} else if (selectedOption === BACK_TO_EDIT) {
5866
this.props.switchToEditModelPage();
5967
} else {

webapp/components/topbar/Topbar.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import NewModelDialog from './dialogs/NewModel';
1919
import ImportExportHLSDialog from './dialogs/ImportExportHLS';
2020
import ImportCellParamsDialog from './dialogs/ImportCellParams';
2121
import UploadDownloadFilesDialog from './dialogs/UploadDownloadFiles';
22-
import LaunchDialog from './dialogs/LaunchDialog';
2322

2423
import { TOPBAR_CONSTANTS } from '../../constants';
2524

@@ -104,7 +103,6 @@ class Topbar extends Component {
104103
dialogOpen,
105104
topbarDialogName,
106105
topbarDialogMetadata,
107-
experimentInDesign,
108106
} = this.props;
109107
let content;
110108
if (dialogOpen) {
@@ -185,16 +183,6 @@ class Topbar extends Component {
185183
/>
186184
);
187185
break;
188-
case TOPBAR_CONSTANTS.SIMULATE:
189-
content = (
190-
<LaunchDialog
191-
open={dialogOpen}
192-
onRequestClose={() => this.handleClose()}
193-
experimentName={experimentInDesign == null ? '' : experimentInDesign.name}
194-
numberOfTrials={experimentInDesign == null ? '' : experimentInDesign.trials.length}
195-
/>
196-
);
197-
break;
198186
default:
199187
content = <div />;
200188
break;

webapp/components/topbar/dialogs/ActionDialog.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ class ActionDialog extends React.Component {
2222
this.state = { hide: !this.props.openErrorDialogBox && !this.props.openDialog };
2323
}
2424

25+
handleClickGoBack () {
26+
this.setState({ hide: true });
27+
this.clearErrorDialogBox();
28+
}
29+
30+
cancelDialog = () => {
31+
this.clearErrorDialogBox();
32+
this.setState({ hide: true });
33+
if (this.props.onRequestClose) {
34+
this.props.onRequestClose();
35+
}
36+
};
37+
2538
performAction = () => {
2639
if (this.props.command) {
2740
if (this.props.isFormValid === undefined || this.props.isFormValid()) {
@@ -41,19 +54,6 @@ class ActionDialog extends React.Component {
4154
}
4255
}
4356

44-
cancelDialog = () => {
45-
this.clearErrorDialogBox();
46-
this.setState({ hide: true });
47-
if (this.props.onRequestClose) {
48-
this.props.onRequestClose();
49-
}
50-
};
51-
52-
handleClickGoBack () {
53-
this.setState({ hide: true });
54-
this.clearErrorDialogBox();
55-
}
56-
5757
render () {
5858
const {
5959
classes,

webapp/components/topbar/dialogs/LaunchDialog.js

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useEffect, useState } from 'react';
2-
import { ActionDialog } from 'netpyne/components';
32
import * as ExperimentsApi from 'root/api/experiments';
43
import {
54
DialogContentText,
@@ -21,11 +20,11 @@ import InfoIcon from '@material-ui/icons/Info';
2120
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
2221
import { useDispatch } from 'react-redux';
2322
import { simulateNetwork } from 'root/redux/actions/general';
23+
import { closeLaunchDialog } from '../../../redux/actions/experiments';
2424
import currentModal from '../../../static/icons/modelSelected.png';
2525
import currentModalUnselected from '../../../static/icons/modelUnselected.png';
2626
import experimentSelected from '../../../static/icons/experimentSelected.png';
2727
import experimentUnselected from '../../../static/icons/experimentUnselected.png';
28-
import Checkbox from '../../general/Checkbox';
2928
import { LAUNCH_MODAL } from '../../../constants';
3029
import {
3130
bgLight,
@@ -39,6 +38,7 @@ import {
3938
} from '../../../theme';
4039
import CircularLoader from '../../general/Loader';
4140
import { openBackendErrorDialog } from '../../../redux/actions/errors';
41+
import SimpleDialog from './SimpleDialog';
4242

4343
const useStyles = (theme) => ({
4444
root: {
@@ -228,6 +228,11 @@ const useStyles = (theme) => ({
228228
});
229229

230230
const LaunchDialog = (props) => {
231+
const {
232+
classes, experimentName, numberOfTrials, open,
233+
} = props;
234+
const dispatch = useDispatch();
235+
231236
const [value, setValue] = useState(LAUNCH_MODAL.modelState);
232237
const [runConfig, setRunConfig] = useState({
233238
asynchronous: true,
@@ -237,37 +242,41 @@ const LaunchDialog = (props) => {
237242

238243
const [expandConfiguration, setExpandConfiguration] = useState(false);
239244
const [loading, setLoading] = useState(false);
240-
const dispatch = useDispatch();
241-
const { classes, experimentName, numberOfTrials } = props;
245+
246+
useEffect(() => {
247+
if (open) {
248+
ExperimentsApi.getRunConfiguration().then((runConfig) => {
249+
setRunConfig(runConfig);
250+
}).catch(() => {
251+
dispatch(openBackendErrorDialog({
252+
errorMessage: 'Failed to retrieve configuration',
253+
errorDetails: '',
254+
}));
255+
});
256+
}
257+
}, [open]);
258+
242259
const handleConfigurationUpdate = (e) => {
243260
e.stopPropagation();
244261
setLoading(true);
245-
ExperimentsApi.editRunConfiguration(runConfig).then(() => {
246-
setLoading(false);
247-
setExpandConfiguration(false);
248-
}).catch(() => {
249-
setLoading(false);
250-
dispatch(openBackendErrorDialog({
251-
errorMessage: 'Failed to update configuration',
252-
errorDetails: '',
253-
}));
254-
});
255-
};
256262

257-
useEffect(() => {
258-
ExperimentsApi.getRunConfiguration().then((runConfig) => {
259-
setRunConfig(runConfig);
260-
}).catch(() => {
261-
dispatch(openBackendErrorDialog({
262-
errorMessage: 'Failed to retrieve configuration',
263-
errorDetails: '',
264-
}));
265-
});
266-
}, []);
263+
ExperimentsApi.editRunConfiguration(runConfig)
264+
.then(() => {
265+
setLoading(false);
266+
setExpandConfiguration(false);
267+
}).catch(() => {
268+
setLoading(false);
269+
dispatch(openBackendErrorDialog({
270+
errorMessage: 'Failed to update configuration',
271+
errorDetails: '',
272+
}));
273+
});
274+
};
267275

268276
return (
269-
<ActionDialog
270-
buttonLabel={LAUNCH_MODAL.actionSimulate}
277+
<SimpleDialog
278+
actionLabel={LAUNCH_MODAL.actionSimulate}
279+
open={open}
271280
title={(
272281
<span>
273282
{LAUNCH_MODAL.actionSimulate}
@@ -276,12 +285,15 @@ const LaunchDialog = (props) => {
276285
</span>
277286
)}
278287
classes={classes}
279-
onAction={() => dispatch(simulateNetwork(value === LAUNCH_MODAL.experimentState))}
288+
onAction={() => {
289+
dispatch(closeLaunchDialog());
290+
dispatch(simulateNetwork(value === LAUNCH_MODAL.experimentState));
291+
}}
292+
onClose={() => dispatch(closeLaunchDialog())}
280293
>
281294
<DialogContentText>
282295
{LAUNCH_MODAL.title}
283296
</DialogContentText>
284-
285297
<Box className="custom-radio">
286298
<Typography component="label">
287299
<Radio
@@ -382,7 +394,7 @@ const LaunchDialog = (props) => {
382394
)}
383395
</AccordionDetails>
384396
</Accordion>
385-
</ActionDialog>
397+
</SimpleDialog>
386398
);
387399
};
388400

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React from 'react';
2+
import Button from '@material-ui/core/Button';
3+
import Dialog from '@material-ui/core/Dialog/Dialog';
4+
import DialogActions from '@material-ui/core/DialogActions';
5+
import DialogContent from '@material-ui/core/DialogContent';
6+
import DialogTitle from '@material-ui/core/DialogTitle';
7+
import { withStyles } from '@material-ui/core/styles';
8+
9+
const styles = () => ({
10+
cancel: { marginRight: 10 },
11+
});
12+
13+
/**
14+
* Customizable Dialog Component with action and cancel buttons.
15+
*/
16+
const SimpleDialog = (props) => {
17+
const {
18+
classes, title, open, onClose, onAction, actionLabel, children,
19+
} = props;
20+
21+
return (
22+
<Dialog
23+
fullWidth
24+
maxWidth="sm"
25+
open={open}
26+
onClose={onClose}
27+
className={classes.root}
28+
>
29+
<DialogTitle>
30+
{title}
31+
</DialogTitle>
32+
<DialogContent>
33+
{children}
34+
</DialogContent>
35+
<DialogActions>
36+
<Button
37+
onClick={onClose}
38+
style={styles.cancel}
39+
key="CANCEL"
40+
>
41+
CANCEL
42+
</Button>
43+
<Button
44+
id="appBarPerformActionButton"
45+
key="appBarPerformActionButton"
46+
variant="contained"
47+
color="primary"
48+
onClick={onAction}
49+
>
50+
{actionLabel}
51+
</Button>
52+
</DialogActions>
53+
</Dialog>
54+
);
55+
};
56+
57+
export default withStyles(styles)(SimpleDialog);

0 commit comments

Comments
 (0)