@@ -37,7 +37,7 @@ const useStyles = makeStyles((theme: Theme) =>
37
37
38
38
const options = [ { id : 'create' , label : 'Create' } , { id : 'custom' , label : 'Customize and Create' } ] ;
39
39
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 } ) {
41
41
const [ open , setOpen ] = React . useState ( false ) ;
42
42
const anchorRef = React . useRef < HTMLDivElement > ( null ) ;
43
43
const [ selectedIndex , setSelectedIndex ] = React . useState ( 0 ) ;
@@ -74,7 +74,7 @@ export default function SplitButton({ template, onCreate, onCreateCustom }: { te
74
74
return (
75
75
< >
76
76
< 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 >
78
78
< Button
79
79
color = "primary"
80
80
size = "small"
@@ -121,18 +121,29 @@ function TemplateSelector({client, conf, user, templates, onDeployed, onRetry}:
121
121
const publicTemplates = Object . entries ( templates ) . filter ( ( [ k , v ] ) => v . tags ?. public == "true" ) ;
122
122
const templatesAvailable = publicTemplates . length > 0 ;
123
123
const [ selection , select ] = useState ( templatesAvailable ? publicTemplates [ 0 ] : null ) ;
124
+ const [ deploying , setDeploying ] = useState ( false ) ;
124
125
const [ errorMessage , setErrorMessage ] = useState < string | null > ( null ) ;
125
126
const [ openCustom , setOpenCustom ] = React . useState ( false ) ;
126
127
const classes = useStyles ( ) ;
127
128
128
129
async function onCreateClick ( conf : SessionConfiguration ) : Promise < void > {
129
130
try {
131
+ setDeploying ( true ) ;
130
132
await onDeployed ( conf ) ;
133
+ setDeploying ( false ) ;
131
134
} catch ( e ) {
132
135
setErrorMessage ( `Failed to create a new session: ${ e } ` ) ;
133
136
}
134
137
}
135
138
139
+ function createEnabled ( ) : boolean {
140
+ if ( ! templatesAvailable ) {
141
+ return false ;
142
+ } else {
143
+ return ! deploying ;
144
+ }
145
+ }
146
+
136
147
if ( selection ) {
137
148
return (
138
149
< >
@@ -162,8 +173,8 @@ function TemplateSelector({client, conf, user, templates, onDeployed, onRetry}:
162
173
< Divider orientation = "horizontal" />
163
174
< Container style = { { display : "flex" , flexDirection : "column" , alignItems : "flex-end" , paddingTop : 10 , paddingBottom : 10 } } >
164
175
{ 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 ( ) } >
167
178
Create
168
179
</ Button > }
169
180
</ Container >
0 commit comments