1
+ import InputAdornment from "@material-ui/core/InputAdornment"
2
+ import { makeStyles } from "@material-ui/core/styles"
1
3
import TextField from "@material-ui/core/TextField"
2
4
import { Template , UpdateTemplateMeta } from "api/typesGenerated"
3
5
import { FormFooter } from "components/FormFooter/FormFooter"
@@ -10,6 +12,7 @@ import * as Yup from "yup"
10
12
export const Language = {
11
13
nameLabel : "Name" ,
12
14
descriptionLabel : "Description" ,
15
+ iconLabel : "Icon" ,
13
16
maxTtlLabel : "Max TTL" ,
14
17
// This is the same from the CLI on https://github.com/coder/coder/blob/546157b63ef9204658acf58cb653aa9936b70c49/cli/templateedit.go#L59
15
18
maxTtlHelperText : "Edit the template maximum time before shutdown in milliseconds" ,
@@ -45,6 +48,7 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
45
48
name : template . name ,
46
49
description : template . description ,
47
50
max_ttl_ms : template . max_ttl_ms ,
51
+ icon : template . icon ,
48
52
} ,
49
53
validationSchema,
50
54
onSubmit : ( data ) => {
@@ -53,6 +57,8 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
53
57
initialTouched,
54
58
} )
55
59
const getFieldHelpers = getFormHelpersWithError < UpdateTemplateMeta > ( form , error )
60
+ const styles = useStyles ( )
61
+ const hasIcon = form . values . icon && form . values . icon !== ""
56
62
57
63
return (
58
64
< form onSubmit = { form . handleSubmit } aria-label = { Language . formAriaLabel } >
@@ -77,6 +83,29 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
77
83
rows = { 2 }
78
84
/>
79
85
86
+ < TextField
87
+ { ...getFieldHelpers ( "icon" ) }
88
+ disabled = { isSubmitting }
89
+ fullWidth
90
+ label = { Language . iconLabel }
91
+ variant = "outlined"
92
+ InputProps = { {
93
+ endAdornment : hasIcon ? (
94
+ < InputAdornment position = "end" >
95
+ < img
96
+ alt = ""
97
+ src = { form . values . icon }
98
+ className = { styles . adornment }
99
+ // This prevent browser to display the ugly error icon if the
100
+ // image path is wrong or user didn't finish typing the url
101
+ onError = { ( e ) => ( e . currentTarget . style . display = "none" ) }
102
+ onLoad = { ( e ) => ( e . currentTarget . style . display = "inline" ) }
103
+ />
104
+ </ InputAdornment >
105
+ ) : undefined ,
106
+ } }
107
+ />
108
+
80
109
< TextField
81
110
{ ...getFieldHelpers ( "max_ttl_ms" ) }
82
111
helperText = { Language . maxTtlHelperText }
@@ -92,3 +121,10 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
92
121
</ form >
93
122
)
94
123
}
124
+
125
+ const useStyles = makeStyles ( ( theme ) => ( {
126
+ adornment : {
127
+ width : theme . spacing ( 3 ) ,
128
+ height : theme . spacing ( 3 ) ,
129
+ } ,
130
+ } ) )
0 commit comments