Skip to content

Commit 354d7e1

Browse files
committed
#311 confirm user action for file imports
1 parent 74a46b0 commit 354d7e1

4 files changed

Lines changed: 57 additions & 23 deletions

File tree

webapp/components/general/ConfirmationDialog.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class ConfirmationDialog extends React.Component {
2020
handleConfirmation = () => {
2121
if (this.props.confirmationDialogOnConfirm) {
2222
if (this.props.confirmationDialogOnConfirm.type === PYTHON_CALL) {
23-
this.props.pythonCall({
24-
cmd: this.props.confirmationDialogOnConfirm.cmd,
25-
args: this.props.confirmationDialogOnConfirm.args,
26-
});
23+
this.props.pythonCall(this.props.confirmationDialogOnConfirm.cmd, this.props.confirmationDialogOnConfirm.args);
2724
} else if (this.props.confirmationDialogOnConfirm.type === LOAD_TUTORIAL) {
2825
if (this.props.confirmationDialogOnConfirm.payload !== undefined) {
2926
this.props.dispatchAction(this.props.confirmationDialogOnConfirm.action(this.props.confirmationDialogOnConfirm.payload));
@@ -38,7 +35,6 @@ class ConfirmationDialog extends React.Component {
3835

3936
render () {
4037
const {
41-
classes,
4238
confirmationDialogOpen,
4339
confirmationDialogTitle,
4440
confirmationDialogMessage,
@@ -51,10 +47,9 @@ class ConfirmationDialog extends React.Component {
5147
maxWidth="sm"
5248
open={confirmationDialogOpen}
5349
onClose={() => closeConfirmationDialog()}
54-
className={classes.root}
5550
>
5651
<DialogTitle>{confirmationDialogTitle}</DialogTitle>
57-
<DialogContent>
52+
<DialogContent style={{ color: 'white' }}>
5853
{confirmationDialogMessage}
5954
</DialogContent>
6055
<DialogActions>

webapp/components/topbar/Topbar.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Topbar extends Component {
9292
this.props.openConfirmationDialog({
9393
title: 'Warning',
9494
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?',
95+
+ ' Continuing with this action will use the old value of netParams and simConfig for the new model. Do you want to continue?',
9696
onConfirm: {
9797
type: LOAD_TUTORIAL,
9898
action,
@@ -123,9 +123,12 @@ class Topbar extends Component {
123123
classes,
124124
modelLoaded,
125125
dialogOpen,
126+
modelState,
126127
topbarDialogName,
127128
topbarDialogMetadata,
129+
openConfirmationDialog,
128130
} = this.props;
131+
129132
let content;
130133
if (dialogOpen) {
131134
switch (topbarDialogName) {
@@ -151,6 +154,8 @@ class Topbar extends Component {
151154
open={dialogOpen}
152155
onRequestClose={() => this.handleClose()}
153156
mode="IMPORT"
157+
modelState={modelState}
158+
openConfirmationDialog={(payload) => openConfirmationDialog(payload)}
154159
/>
155160
);
156161
break;

webapp/components/topbar/dialogs/ActionDialog.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ class ActionDialog extends React.Component {
3838
performAction = () => {
3939
if (this.props.command) {
4040
if (this.props.isFormValid === undefined || this.props.isFormValid()) {
41-
GEPPETTO.trigger(GEPPETTO.Events.Show_spinner, this.props.message);
42-
this.props.pythonCall(this.props.command, this.props.args);
41+
if (typeof this.props.callback !== 'undefined' || this.props.callback !== null) {
42+
this.props.callback(this.props.command, this.props.args);
43+
} else {
44+
GEPPETTO.trigger(GEPPETTO.Events.Show_spinner, this.props.message);
45+
this.props.pythonCall(this.props.command, this.props.args);
46+
}
4347
}
4448
}
4549
this.setState({ hide: true });

webapp/components/topbar/dialogs/ImportExportHLS.js

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import Box from '@material-ui/core/Box';
77
import { withStyles } from '@material-ui/core/styles';
88

99
import { ActionDialog, Tooltip } from 'netpyne/components';
10-
import { NETPYNE_COMMANDS } from '../../../constants';
10+
import { NETPYNE_COMMANDS, MODEL_STATE } from '../../../constants';
11+
import { PYTHON_CALL } from '../../../redux/actions/general';
1112
import FileBrowser from '../../general/FileBrowser';
1213
import Checkbox from '../../general/Checkbox';
1314

@@ -179,8 +180,21 @@ class ImportExportHLS extends React.Component {
179180
}
180181
}
181182

183+
handleConfirmation (command, args) {
184+
this.props.openConfirmationDialog({
185+
title: 'Warning',
186+
message: 'A NetPyNE model has already been instantiated or simulated.'
187+
+ ' Continuing with this import action will use the old value of netParams and simConfig for the new model. Do you want to continue?',
188+
onConfirm: {
189+
type: PYTHON_CALL,
190+
cmd: command,
191+
args,
192+
},
193+
});
194+
}
195+
182196
render () {
183-
const { classes } = this.props;
197+
const { classes, modelState } = this.props;
184198
switch (this.props.mode) {
185199
case 'IMPORT':
186200
var content = (
@@ -309,18 +323,34 @@ class ImportExportHLS extends React.Component {
309323
var title = 'Export as Python script';
310324
break;
311325
}
326+
312327
return (
313-
<ActionDialog
314-
command={command}
315-
message={message}
316-
buttonLabel={buttonLabel}
317-
args={this.state}
318-
title={title}
319-
isFormValid={this.isFormValid}
320-
{...this.props}
321-
>
322-
{content}
323-
</ActionDialog>
328+
this.props.mode === 'IMPORT' ? (
329+
<ActionDialog
330+
command={command}
331+
message={message}
332+
buttonLabel={buttonLabel}
333+
args={this.state}
334+
title={title}
335+
isFormValid={this.isFormValid}
336+
callback={modelState === MODEL_STATE.INSTANTIATED || modelState === MODEL_STATE.SIMULATED ? (command, args) => { this.handleConfirmation(command, args); } : undefined}
337+
{...this.props}
338+
>
339+
{content}
340+
</ActionDialog>
341+
) : (
342+
<ActionDialog
343+
command={command}
344+
message={message}
345+
buttonLabel={buttonLabel}
346+
args={this.state}
347+
title={title}
348+
isFormValid={this.isFormValid}
349+
{...this.props}
350+
>
351+
{content}
352+
</ActionDialog>
353+
)
324354
);
325355
}
326356
}

0 commit comments

Comments
 (0)