Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit c07af02

Browse files
committed
Disable create button when deploying
1 parent 85df4a7 commit c07af02

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

frontend/src/panels/session.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const useStyles = makeStyles((theme: Theme) =>
3737

3838
const 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

Comments
 (0)