Skip to content

Commit 8a30d03

Browse files
committed
#311 create confirmation dialog
1 parent bc5e0eb commit 8a30d03

6 files changed

Lines changed: 896 additions & 63 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+
ConfirmationDialog,
1112
LaunchDialog,
1213
} from 'netpyne/components';
1314

@@ -140,6 +141,7 @@ class NetPyNE extends React.Component {
140141
</Box>
141142
</div>
142143
<Dialog />
144+
<ConfirmationDialog />
143145
<ErrorDialog />
144146
<LaunchDialog />
145147
</div>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React from 'react';
2+
import Dialog from '@material-ui/core/Dialog/Dialog';
3+
import Button from '@material-ui/core/Button';
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+
import { PYTHON_CALL } from '../../redux/actions/general';
9+
10+
const styles = () => ({
11+
cancel: { marginRight: 10 },
12+
});
13+
14+
class ConfirmationDialog extends React.Component {
15+
constructor (props) {
16+
super(props);
17+
this.state = { hide: !this.props.open };
18+
}
19+
20+
handleConfirmation = () => {
21+
if (this.props.confirmationDialogOnConfirm
22+
&& this.props.confirmationDialogOnConfirm.type === PYTHON_CALL) {
23+
this.props.pythonCall({
24+
cmd: this.props.confirmationDialogOnConfirm.cmd,
25+
args: this.props.confirmationDialogOnConfirm.args,
26+
});
27+
} else {
28+
console.log('confirmationAction not passed or it is not a python call');
29+
}
30+
}
31+
32+
render () {
33+
const {
34+
classes,
35+
confirmationDialogOpen,
36+
confirmationDialogTitle,
37+
confirmationDialogMessage,
38+
closeConfirmationDialog,
39+
} = this.props;
40+
41+
return (
42+
<Dialog
43+
fullWidth
44+
maxWidth="sm"
45+
open={confirmationDialogOpen}
46+
onClose={() => closeConfirmationDialog()}
47+
className={classes.root}
48+
>
49+
<DialogTitle>{confirmationDialogTitle}</DialogTitle>
50+
<DialogContent>
51+
{confirmationDialogMessage}
52+
</DialogContent>
53+
<DialogActions>
54+
<Button
55+
onClick={closeConfirmationDialog}
56+
style={styles.cancel}
57+
key="CANCEL"
58+
>
59+
CANCEL
60+
</Button>
61+
<Button
62+
color="primary"
63+
variant="contained"
64+
onClick={() => { this.handleConfirmation(); closeConfirmationDialog(); }}
65+
key="CONFIRM"
66+
>
67+
CONFIRM
68+
</Button>
69+
</DialogActions>
70+
</Dialog>
71+
);
72+
}
73+
}
74+
75+
export default withStyles(styles)(ConfirmationDialog);

webapp/components/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { openBackendErrorDialog, closeBackendErrorDialog } from '../redux/action
1414
import {
1515
updateCards, editModel, simulateNetwork, createNetwork, closeDialog,
1616
createAndSimulateNetwork, showNetwork, pythonCall, modelLoaded, deleteNetParamsObj, resetModel,
17-
setDefaultWidgets,
17+
setDefaultWidgets, openConfirmationDialog, closeConfirmationDialog,
1818
} from '../redux/actions/general';
1919

2020
import {
@@ -56,6 +56,7 @@ import _Topbar from './topbar/Topbar';
5656
import _SwitchPageButton from './topbar/SwitchPageButton';
5757
import _NetPyNEThumbnail from './general/NetPyNEThumbnail';
5858
import _Dialog from './general/Dialog';
59+
import _ConfirmationDialog from './general/ConfirmationDialog';
5960
import _SelectCellTemplate from './definition/cellRules/SelectCellTemplate';
6061
import _Experiments from './experiments/Experiments';
6162
import _ExperimentEdit from './experiments/ExperimentEdit';
@@ -348,6 +349,19 @@ export const Dialog = connect(
348349
(dispatch) => ({ handleClose: () => dispatch(closeDialog) }),
349350
)(_Dialog);
350351

352+
export const ConfirmationDialog = connect(
353+
(state) => ({
354+
confirmationDialogOpen: state.general.confirmationDialogOpen,
355+
confirmationDialogTitle: state.general.confirmationDialogTitle,
356+
confirmationDialogMessage: state.general.confirmationDialogMessage,
357+
confirmationDialogOnConfirm: state.general.confirmationDialogOnConfirm,
358+
}),
359+
(dispatch) => ({
360+
closeConfirmationDialog: () => dispatch(closeConfirmationDialog),
361+
pythonCall: (cmd, args) => dispatch(pythonCall(cmd, args)),
362+
}),
363+
)(_ConfirmationDialog);
364+
351365
export const SelectCellTemplate = connect(
352366
null,
353367
(dispatch) => ({

webapp/redux/actions/general.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const DELETE_NETPARAMS_OBJ = 'DELETE_NETPARAMS_OBJ';
1515
export const CLOSE_DIALOG = 'CLOSE_DIALOG';
1616
export const OPEN_DIALOG = 'OPEN_DIALOG';
1717
export const LOAD_TUTORIAL = 'LOAD_TUTORIAL';
18+
export const OPEN_CONFIRMATION_DIALOG = 'OPEN_CONFIRMATION_DIALOG';
19+
export const CLOSE_CONFIRMATION_DIALOG = 'CLOSE_CONFIRMATION_DIALOG';
1820
export const AUTOMATIC_INSTANTIATION = 'AUTOMATIC_INSTANTIATION';
1921
export const AUTOMATIC_SIMULATION = 'AUTOMATIC_SIMULATION';
2022
export const IMPORT_APPLICATION_STATE = 'IMPORT_APPLICATION_STATE';
@@ -55,6 +57,13 @@ export const openDialog = (payload) => ({
5557
payload,
5658
});
5759

60+
export const openConfirmationDialog = (payload) => ({
61+
type: OPEN_CONFIRMATION_DIALOG,
62+
payload,
63+
});
64+
65+
export const closeConfirmationDialog = { type: CLOSE_CONFIRMATION_DIALOG };
66+
5867
export const setTheme = (themeName) => ({
5968
type: SET_THEME,
6069
payload: themeName,

webapp/redux/reducers/general.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ export const GENERAL_DEFAULT_STATE = {
1111
dialogOpen: false,
1212
dialogTitle: '',
1313
dialogMessage: '',
14+
confirmationDialogTitle: '',
15+
confirmationDialogMessage: '',
16+
confirmationDialogOnConfirm: {},
1417
automaticSimulation: false,
1518
automaticInstantiation: false,
19+
confirmationDialogOpen: false,
1620
theme: 'gui',
1721
};
1822

@@ -41,6 +45,18 @@ export default function reduceGeneral (state = GENERAL_DEFAULT_STATE, action) {
4145
};
4246
case Actions.CLOSE_DIALOG:
4347
return { ...state, dialogOpen: false };
48+
case Actions.OPEN_CONFIRMATION_DIALOG:
49+
return {
50+
...state,
51+
confirmationDialogOpen: true,
52+
confirmationDialogTitle: action.payload.title,
53+
confirmationDialogMessage: action.payload.message,
54+
confirmationDialogOnConfirm: action.payload.onConfirm,
55+
};
56+
case Actions.CLOSE_CONFIRMATION_DIALOG:
57+
return {
58+
...state, confirmationDialogOpen: false, dialogTitle: '', dialogMessage: '',
59+
};
4460
case Actions.AUTOMATIC_INSTANTIATION: {
4561
return { ...state, automaticInstantiation: action.payload, automaticSimulation: state.automaticSimulation && action.payload };
4662
}

0 commit comments

Comments
 (0)