11import React , { useEffect , useState } from 'react' ;
2- import { ActionDialog } from 'netpyne/components' ;
32import * as ExperimentsApi from 'root/api/experiments' ;
43import {
54 DialogContentText ,
@@ -21,11 +20,11 @@ import InfoIcon from '@material-ui/icons/Info';
2120import ExpandMoreIcon from '@material-ui/icons/ExpandMore' ;
2221import { useDispatch } from 'react-redux' ;
2322import { simulateNetwork } from 'root/redux/actions/general' ;
23+ import { closeLaunchDialog } from '../../../redux/actions/experiments' ;
2424import currentModal from '../../../static/icons/modelSelected.png' ;
2525import currentModalUnselected from '../../../static/icons/modelUnselected.png' ;
2626import experimentSelected from '../../../static/icons/experimentSelected.png' ;
2727import experimentUnselected from '../../../static/icons/experimentUnselected.png' ;
28- import Checkbox from '../../general/Checkbox' ;
2928import { LAUNCH_MODAL } from '../../../constants' ;
3029import {
3130 bgLight ,
@@ -39,6 +38,7 @@ import {
3938} from '../../../theme' ;
4039import CircularLoader from '../../general/Loader' ;
4140import { openBackendErrorDialog } from '../../../redux/actions/errors' ;
41+ import SimpleDialog from './SimpleDialog' ;
4242
4343const useStyles = ( theme ) => ( {
4444 root : {
@@ -228,6 +228,11 @@ const useStyles = (theme) => ({
228228} ) ;
229229
230230const 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
0 commit comments