@@ -37,7 +37,7 @@ const useStyles = makeStyles((theme: Theme) =>
3737
3838const options = [ { id : 'create' , label : 'Create' } , { id : 'custom' , label : 'Customize and Create' } ] ;
3939
40- export default function SplitButton ( { template, onCreate, onCreateCustom } : { template : string , onCreate : ( conf : SessionConfiguration ) => void , onCreateCustom : ( ) => void } ) {
40+ export default function SplitButton ( { template, disabled , onCreate, onCreateCustom } : { template : string , disabled : boolean , onCreate : ( conf : SessionConfiguration ) => void , onCreateCustom : ( ) => void } ) {
4141 const [ open , setOpen ] = React . useState ( false ) ;
4242 const anchorRef = React . useRef < HTMLDivElement > ( null ) ;
4343 const [ selectedIndex , setSelectedIndex ] = React . useState ( 0 ) ;
@@ -74,7 +74,7 @@ export default function SplitButton({ template, onCreate, onCreateCustom }: { te
7474 return (
7575 < >
7676 < ButtonGroup variant = "contained" color = "primary" ref = { anchorRef } aria-label = "split button" >
77- < Button onClick = { handleClick } > { options [ selectedIndex ] . label } </ Button >
77+ < Button onClick = { handleClick } disabled = { disabled } > { options [ selectedIndex ] . label } </ Button >
7878 < Button
7979 color = "primary"
8080 size = "small"
@@ -121,18 +121,29 @@ function TemplateSelector({client, conf, user, templates, onDeployed, onRetry}:
121121 const publicTemplates = Object . entries ( templates ) . filter ( ( [ k , v ] ) => v . tags ?. public == "true" ) ;
122122 const templatesAvailable = publicTemplates . length > 0 ;
123123 const [ selection , select ] = useState ( templatesAvailable ? publicTemplates [ 0 ] : null ) ;
124+ const [ deploying , setDeploying ] = useState ( false ) ;
124125 const [ errorMessage , setErrorMessage ] = useState < string | null > ( null ) ;
125126 const [ openCustom , setOpenCustom ] = React . useState ( false ) ;
126127 const classes = useStyles ( ) ;
127128
128129 async function onCreateClick ( conf : SessionConfiguration ) : Promise < void > {
129130 try {
131+ setDeploying ( true ) ;
130132 await onDeployed ( conf ) ;
133+ setDeploying ( false ) ;
131134 } catch ( e ) {
132135 setErrorMessage ( `Failed to create a new session: ${ e } ` ) ;
133136 }
134137 }
135138
139+ function createEnabled ( ) : boolean {
140+ if ( ! templatesAvailable ) {
141+ return false ;
142+ } else {
143+ return ! deploying ;
144+ }
145+ }
146+
136147 if ( selection ) {
137148 return (
138149 < >
@@ -162,8 +173,8 @@ function TemplateSelector({client, conf, user, templates, onDeployed, onRetry}:
162173 < Divider orientation = "horizontal" />
163174 < Container style = { { display : "flex" , flexDirection : "column" , alignItems : "flex-end" , paddingTop : 10 , paddingBottom : 10 } } >
164175 { canCustomize ( user )
165- ? < SplitButton template = { selection [ 0 ] } onCreate = { ( ) => onCreateClick ( { template : selection [ 0 ] } ) } onCreateCustom = { ( ) => setOpenCustom ( true ) } />
166- : < Button onClick = { ( ) => onCreateClick ( { template : selection [ 0 ] } ) } color = "primary" variant = "contained" disableElevation disabled = { ! templatesAvailable } >
176+ ? < SplitButton template = { selection [ 0 ] } onCreate = { ( ) => onCreateClick ( { template : selection [ 0 ] } ) } onCreateCustom = { ( ) => setOpenCustom ( true ) } disabled = { ! createEnabled ( ) } />
177+ : < Button onClick = { ( ) => onCreateClick ( { template : selection [ 0 ] } ) } color = "primary" variant = "contained" disableElevation disabled = { ! createEnabled ( ) } >
167178 Create
168179 </ Button > }
169180 </ Container >
0 commit comments