Skip to content

Commit 74a46b0

Browse files
committed
#311 confirm user action for tutorials
1 parent 8a30d03 commit 74a46b0

5 files changed

Lines changed: 42 additions & 11 deletions

File tree

webapp/components/general/ConfirmationDialog.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import DialogActions from '@material-ui/core/DialogActions';
55
import DialogContent from '@material-ui/core/DialogContent';
66
import DialogTitle from '@material-ui/core/DialogTitle';
77
import { withStyles } from '@material-ui/core/styles';
8-
import { PYTHON_CALL } from '../../redux/actions/general';
8+
import { PYTHON_CALL, LOAD_TUTORIAL } from '../../redux/actions/general';
99

1010
const styles = () => ({
1111
cancel: { marginRight: 10 },
@@ -18,14 +18,21 @@ class ConfirmationDialog extends React.Component {
1818
}
1919

2020
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-
});
21+
if (this.props.confirmationDialogOnConfirm) {
22+
if (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 if (this.props.confirmationDialogOnConfirm.type === LOAD_TUTORIAL) {
28+
if (this.props.confirmationDialogOnConfirm.payload !== undefined) {
29+
this.props.dispatchAction(this.props.confirmationDialogOnConfirm.action(this.props.confirmationDialogOnConfirm.payload));
30+
} else {
31+
this.props.dispatchAction(this.props.confirmationDialogOnConfirm.action);
32+
}
33+
}
2734
} else {
28-
console.log('confirmationAction not passed or it is not a python call');
35+
console.log('Command/desired behaviour not passed to confirmation dialog');
2936
}
3037
}
3138

webapp/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ export const Topbar = connect(
314314
dispatchAction: (action) => dispatch(action),
315315
closeDialog: () => dispatch(closeTopbarDialog),
316316
resetModel: () => dispatch(resetModel),
317+
openConfirmationDialog: (payload) => dispatch(openConfirmationDialog(payload)),
317318
}),
318319
)(_Topbar);
319320

@@ -357,6 +358,7 @@ export const ConfirmationDialog = connect(
357358
confirmationDialogOnConfirm: state.general.confirmationDialogOnConfirm,
358359
}),
359360
(dispatch) => ({
361+
dispatchAction: (action) => dispatch(action),
360362
closeConfirmationDialog: () => dispatch(closeConfirmationDialog),
361363
pythonCall: (cmd, args) => dispatch(pythonCall(cmd, args)),
362364
}),

webapp/components/topbar/Topbar.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import ImportExportHLSDialog from './dialogs/ImportExportHLS';
2020
import ImportCellParamsDialog from './dialogs/ImportCellParams';
2121
import UploadDownloadFilesDialog from './dialogs/UploadDownloadFiles';
2222

23-
import { TOPBAR_CONSTANTS } from '../../constants';
23+
import { TOPBAR_CONSTANTS, MODEL_STATE } from '../../constants';
24+
import { LOAD_TUTORIAL } from '../../redux/actions/general';
2425

2526
const styles = () => ({
2627
topbar: {
@@ -85,6 +86,27 @@ class Topbar extends Component {
8586
}
8687
break;
8788
}
89+
case 'handleTutorial': {
90+
const [action, payload] = click.parameters;
91+
if (this.props.modelState === MODEL_STATE.INSTANTIATED || this.props.modelState === MODEL_STATE.SIMULATED) {
92+
this.props.openConfirmationDialog({
93+
title: 'Warning',
94+
message: 'A NetPyNE model has already been instantiated or simulated.'
95+
+ 'Continuing with this action will use the old value of netParams and simConfig for the new model. Do you want to continue?',
96+
onConfirm: {
97+
type: LOAD_TUTORIAL,
98+
action,
99+
payload,
100+
},
101+
});
102+
} else if (payload !== undefined) {
103+
this.props.dispatchAction(action(payload));
104+
} else {
105+
this.props.dispatchAction(action);
106+
}
107+
108+
break;
109+
}
88110

89111
default:
90112
console.log(`Menu action not mapped, it is ${click}`);

webapp/components/topbar/menuConfiguration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const getTutorials = () => {
8383
label: tutLabel,
8484
icon: '',
8585
action: {
86-
handlerAction: 'redux',
86+
handlerAction: 'handleTutorial',
8787
parameters: [loadTutorial, tutFile],
8888
},
8989
};

webapp/redux/reducers/general.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default function reduceGeneral (state = GENERAL_DEFAULT_STATE, action) {
5555
};
5656
case Actions.CLOSE_CONFIRMATION_DIALOG:
5757
return {
58-
...state, confirmationDialogOpen: false, dialogTitle: '', dialogMessage: '',
58+
...state, confirmationDialogOpen: false, dialogTitle: '', dialogMessage: '', confirmationDialogOnConfirm: {},
5959
};
6060
case Actions.AUTOMATIC_INSTANTIATION: {
6161
return { ...state, automaticInstantiation: action.payload, automaticSimulation: state.automaticSimulation && action.payload };

0 commit comments

Comments
 (0)