Skip to content

Commit 71bc379

Browse files
committed
frontend: make it possible to clear the tag and filesystem_tag from a compute server config
1 parent 7433f41 commit 71bc379

File tree

1 file changed

+64
-20
lines changed

1 file changed

+64
-20
lines changed

src/packages/frontend/compute/select-version.tsx

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
Configuration,
33
Images,
44
} from "@cocalc/util/db-schema/compute-servers";
5-
import { Button, Radio, Spin } from "antd";
5+
import { Button, Radio, Spin, Tooltip } from "antd";
66
import { useEffect, useMemo, useState } from "react";
77
import { A, Icon } from "@cocalc/frontend/components";
88
import { forceRefreshImages } from "./images-hook";
@@ -18,42 +18,76 @@ interface Props {
1818
}
1919

2020
export default function SelectVersion({
21-
setConfig,
21+
setConfig: setConfig0,
2222
configuration,
2323
disabled,
2424
image,
2525
IMAGES,
2626
style,
2727
}: Props) {
28-
const [tag, setTag] = useState<string | undefined>(configuration.tag);
28+
const setConfig = (obj) => {
29+
// because we can't use null as a value for radio buttons...
30+
for (const k in obj) {
31+
if (!obj[k]) {
32+
obj[k] = null;
33+
}
34+
}
35+
setConfig0(obj);
36+
};
37+
38+
const [tag, setTag] = useState<string>(configuration.tag ?? "");
2939
const [refreshing, setRefreshing] = useState<boolean>(false);
3040
const [error, setError] = useState<string>("");
31-
const [tag_filesystem, set_tag_filesystem] = useState<string | undefined>(
32-
configuration.tag_filesystem,
41+
const [tag_filesystem, set_tag_filesystem] = useState<string>(
42+
configuration.tag_filesystem ?? "",
3343
);
34-
const [tag_cocalc, set_tag_cocalc] = useState<string | undefined>(
35-
configuration.tag_cocalc,
44+
const [tag_cocalc, set_tag_cocalc] = useState<string>(
45+
configuration.tag_cocalc ?? "",
3646
);
3747

3848
useEffect(() => {
39-
setTag(configuration.tag);
49+
setTag(configuration.tag ?? "");
4050
}, [configuration.tag]);
4151

4252
useEffect(() => {
43-
set_tag_filesystem(configuration.tag_filesystem);
53+
set_tag_filesystem(configuration.tag_filesystem ?? "");
4454
}, [configuration.tag_filesystem]);
4555

4656
useEffect(() => {
47-
set_tag_cocalc(configuration.tag_cocalc);
57+
set_tag_cocalc(configuration.tag_cocalc ?? "");
4858
}, [configuration.tag_cocalc]);
4959

5060
// [ ] TODO: MAYBE we should allow gpu/non-gpu options in all cases, but just suggest one or the other?
5161
const options = useMemo(() => {
52-
const { versions } = IMAGES[image] ?? {};
53-
if (!versions) {
54-
return [];
55-
}
56-
return versions.map(toOption);
62+
return [
63+
{
64+
label: (
65+
<Tooltip title="Use newest available tested image.">Default</Tooltip>
66+
) as any,
67+
value: "",
68+
key: "default",
69+
},
70+
].concat((IMAGES[image]?.versions ?? []).map(toOption));
71+
}, [IMAGES, image]);
72+
73+
const fsOptions = useMemo(() => {
74+
return [
75+
{
76+
label: (
77+
<Tooltip title="Use newest available tested filesystem image.">
78+
Default
79+
</Tooltip>
80+
) as any,
81+
value: "",
82+
key: "default",
83+
},
84+
].concat((IMAGES["filesystem"]?.versions ?? []).map(toOption));
85+
}, [IMAGES, image]);
86+
87+
const cocalcOptions = useMemo(() => {
88+
return (
89+
IMAGES["cocalc"]?.versions ?? [{ tag: "test" }, { tag: "latest" }]
90+
).map(toOption);
5791
}, [IMAGES, image]);
5892

5993
// TODO: it would be better to have tagUrl or something like that below...
@@ -116,7 +150,7 @@ export default function SelectVersion({
116150
}
117151
disabled={disabled}
118152
tag={tag_filesystem}
119-
options={(IMAGES["filesystem"]?.versions ?? []).map(toOption)}
153+
options={fsOptions}
120154
setTag={(tag) => {
121155
set_tag_filesystem(tag);
122156
setConfig({ tag_filesystem: tag });
@@ -137,9 +171,7 @@ export default function SelectVersion({
137171
}
138172
disabled={disabled}
139173
tag={tag_cocalc}
140-
options={(
141-
IMAGES["cocalc"]?.versions ?? [{ tag: "test" }, { tag: "latest" }]
142-
).map(toOption)}
174+
options={cocalcOptions}
143175
setTag={(tag) => {
144176
set_tag_cocalc(tag);
145177
setConfig({ tag_cocalc: tag });
@@ -152,11 +184,23 @@ export default function SelectVersion({
152184
function toOption(x: {
153185
label?: string;
154186
tag: string;
187+
description?: string;
155188
tested?: boolean;
156189
version?: string;
157190
}) {
158191
return {
159-
label: `${x.label ?? x.tag}${!x.tested ? " (untested)" : ""}`,
192+
label: (
193+
<Tooltip
194+
title={
195+
<>
196+
{x.tag ?? x.label ?? ""}{" "}{x.description ?? ""}
197+
</>
198+
}
199+
>
200+
{x.label ?? x.tag}
201+
{!x.tested ? " (untested)" : ""}
202+
</Tooltip>
203+
),
160204
value: x.tag,
161205
key: x.tag,
162206
};

0 commit comments

Comments
 (0)