@@ -2,18 +2,22 @@ import React, { Component } from 'react';
22
33import { withStyles } from '@material-ui/core/styles' ;
44import Button from '@material-ui/core/Button' ;
5- import IconButton from '@material-ui/core/IconButton' ;
6- import { Tooltip } from 'netpyne/components' ;
75import Icon from '../general/NetPyNEIcons' ;
86import { TOPBAR_CONSTANTS , MODEL_STATE } from '../../constants' ;
7+ import SplitButton from '../general/SplitButton' ;
98
109const styles = ( {
1110 palette,
12- shape,
1311 spacing,
14- typography,
1512} ) => ( {
16- container : { } ,
13+ container : {
14+ display : 'flex' ,
15+ height : '100%' ,
16+ '& .MuiButton-root' : {
17+ borderRadius : 0 ,
18+ marginBottom : 0 ,
19+ } ,
20+ } ,
1721 button : {
1822 textTransform : 'uppercase' ,
1923 letterSpacing : 2 ,
@@ -24,20 +28,34 @@ const styles = ({
2428 icon : { color : palette . common . white } ,
2529} ) ;
2630
31+ const CREATE_NETWORK = 'CREATE NETWORK' ;
32+ const CREATE_AND_SIMULATE = 'CREATE AND SIMULATE' ;
33+ const SIMULATE = 'SIMULATE' ;
34+ const BACK_TO_EDIT = 'BACK TO EDIT' ;
35+
36+ const editOptions = [ CREATE_NETWORK , CREATE_AND_SIMULATE , SIMULATE ] ;
37+ const exploreOptions = [ SIMULATE , CREATE_AND_SIMULATE ] ;
38+
2739class SwitchPageButton extends Component {
2840 constructor ( props ) {
2941 super ( props ) ;
3042 this . handleClick = this . handleClick . bind ( this ) ;
3143 }
3244
33- handleClick = ( event ) => {
34- const instantiate = this . props . automaticInstantiation || this . props . modelState === MODEL_STATE . NOT_INSTANTIATED ;
35- if ( ! this . props . editModelPage ) {
36- this . props . switchToEditModelPage ( ) ;
37- } else if ( instantiate && this . props . automaticSimulation ) {
45+ handleClick = ( selectedOption ) => {
46+ const instantiate = this . props . modelState === MODEL_STATE . NOT_INSTANTIATED ;
47+ if ( selectedOption === CREATE_NETWORK ) {
48+ if ( instantiate ) {
49+ this . props . createNetwork ( ) ;
50+ } else {
51+ this . props . showNetwork ( ) ;
52+ }
53+ } else if ( selectedOption === SIMULATE ) {
54+ this . props . simulateNetwork ( ) ;
55+ } else if ( selectedOption === CREATE_AND_SIMULATE ) {
3856 this . props . createAndSimulateNetwork ( ) ;
39- } else if ( instantiate ) {
40- this . props . createNetwork ( ) ;
57+ } else if ( selectedOption === BACK_TO_EDIT ) {
58+ this . props . switchToEditModelPage ( ) ;
4159 } else {
4260 this . props . showNetwork ( ) ;
4361 }
@@ -64,48 +82,43 @@ class SwitchPageButton extends Component {
6482 render ( ) {
6583 const {
6684 classes,
67- modelState,
6885 editModelPage,
69- simulateNetwork,
7086 } = this . props ;
71- const disableSimulate = modelState === MODEL_STATE . SIMULATED ;
7287 return (
7388 < div className = { classes . container } >
74- {
75- editModelPage ? null
76-
77- : (
78- < Tooltip
79- title = { disableSimulate ? 'You have already simulated the network' : 'Simulate the network' }
80- placement = "left"
89+ { editModelPage
90+ ? (
91+ < SplitButton
92+ options = { editOptions }
93+ handleClick = { ( selectedOption ) => this . handleClick ( selectedOption ) }
94+ icon = { (
95+ < span style = { { marginRight : '5px' } } >
96+ < Icon name = "rocket" />
97+ </ span >
98+ ) }
99+ skipIconFor = { CREATE_NETWORK }
100+ />
101+ )
102+ : (
103+ < >
104+ < Button
105+ variant = "contained"
106+ onClick = { ( ) => this . handleClick ( BACK_TO_EDIT ) }
107+ startIcon = { < Icon name = "pencil" selected = { false } /> }
81108 >
82- < span >
83- < IconButton
84- color = "default"
85- id = "launchSimulationButton"
86- className = { classes . rocket }
87- size = "small"
88- onClick = { ( ) => simulateNetwork ( ) }
89- disabled = { disableSimulate }
90- style = { { opacity : disableSimulate ? 0.5 : 1 } }
91- >
109+ { TOPBAR_CONSTANTS . BACK_TO_EDITION }
110+ </ Button >
111+ < SplitButton
112+ options = { exploreOptions }
113+ handleClick = { ( selectedOption ) => this . handleClick ( selectedOption ) }
114+ icon = { (
115+ < span style = { { marginRight : '5px' } } >
92116 < Icon name = "rocket" />
93-
94- </ IconButton >
95- </ span >
96- </ Tooltip >
97- )
98- }
99- < Button
100- variant = "contained"
101- size = "small"
102- className = { classes . button }
103- onClick = { this . handleClick }
104- endIcon = { < Icon name = { editModelPage ? 'rocket' : 'pencil' } selected = { false } /> }
105- >
106- { editModelPage ? this . getExploreLabel ( ) : TOPBAR_CONSTANTS . BACK_TO_EDITION }
107- </ Button >
108-
117+ </ span >
118+ ) }
119+ />
120+ </ >
121+ ) }
109122 </ div >
110123 ) ;
111124 }
0 commit comments