@@ -2,7 +2,7 @@ import type {
2
2
Configuration ,
3
3
Images ,
4
4
} from "@cocalc/util/db-schema/compute-servers" ;
5
- import { Button , Radio , Spin } from "antd" ;
5
+ import { Button , Radio , Spin , Tooltip } from "antd" ;
6
6
import { useEffect , useMemo , useState } from "react" ;
7
7
import { A , Icon } from "@cocalc/frontend/components" ;
8
8
import { forceRefreshImages } from "./images-hook" ;
@@ -18,42 +18,76 @@ interface Props {
18
18
}
19
19
20
20
export default function SelectVersion ( {
21
- setConfig,
21
+ setConfig : setConfig0 ,
22
22
configuration,
23
23
disabled,
24
24
image,
25
25
IMAGES ,
26
26
style,
27
27
} : 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 ?? "" ) ;
29
39
const [ refreshing , setRefreshing ] = useState < boolean > ( false ) ;
30
40
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 ?? "" ,
33
43
) ;
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 ?? "" ,
36
46
) ;
37
47
38
48
useEffect ( ( ) => {
39
- setTag ( configuration . tag ) ;
49
+ setTag ( configuration . tag ?? "" ) ;
40
50
} , [ configuration . tag ] ) ;
41
51
42
52
useEffect ( ( ) => {
43
- set_tag_filesystem ( configuration . tag_filesystem ) ;
53
+ set_tag_filesystem ( configuration . tag_filesystem ?? "" ) ;
44
54
} , [ configuration . tag_filesystem ] ) ;
45
55
46
56
useEffect ( ( ) => {
47
- set_tag_cocalc ( configuration . tag_cocalc ) ;
57
+ set_tag_cocalc ( configuration . tag_cocalc ?? "" ) ;
48
58
} , [ configuration . tag_cocalc ] ) ;
49
59
50
60
// [ ] TODO: MAYBE we should allow gpu/non-gpu options in all cases, but just suggest one or the other?
51
61
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 ) ;
57
91
} , [ IMAGES , image ] ) ;
58
92
59
93
// TODO: it would be better to have tagUrl or something like that below...
@@ -116,7 +150,7 @@ export default function SelectVersion({
116
150
}
117
151
disabled = { disabled }
118
152
tag = { tag_filesystem }
119
- options = { ( IMAGES [ "filesystem" ] ?. versions ?? [ ] ) . map ( toOption ) }
153
+ options = { fsOptions }
120
154
setTag = { ( tag ) => {
121
155
set_tag_filesystem ( tag ) ;
122
156
setConfig ( { tag_filesystem : tag } ) ;
@@ -137,9 +171,7 @@ export default function SelectVersion({
137
171
}
138
172
disabled = { disabled }
139
173
tag = { tag_cocalc }
140
- options = { (
141
- IMAGES [ "cocalc" ] ?. versions ?? [ { tag : "test" } , { tag : "latest" } ]
142
- ) . map ( toOption ) }
174
+ options = { cocalcOptions }
143
175
setTag = { ( tag ) => {
144
176
set_tag_cocalc ( tag ) ;
145
177
setConfig ( { tag_cocalc : tag } ) ;
@@ -152,11 +184,23 @@ export default function SelectVersion({
152
184
function toOption ( x : {
153
185
label ?: string ;
154
186
tag : string ;
187
+ description ?: string ;
155
188
tested ?: boolean ;
156
189
version ?: string ;
157
190
} ) {
158
191
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
+ ) ,
160
204
value : x . tag ,
161
205
key : x . tag ,
162
206
} ;
0 commit comments