@@ -11,7 +11,6 @@ import {
11
11
import * as Yup from "yup"
12
12
import i18next from "i18next"
13
13
import { useTranslation } from "react-i18next"
14
- import { Maybe } from "components/Conditionals/Maybe"
15
14
import { LazyIconField } from "components/IconField/LazyIconField"
16
15
import {
17
16
FormFields ,
@@ -23,28 +22,8 @@ import { Stack } from "components/Stack/Stack"
23
22
import Checkbox from "@material-ui/core/Checkbox"
24
23
import { HelpTooltip , HelpTooltipText } from "components/Tooltips/HelpTooltip"
25
24
import { makeStyles } from "@material-ui/core/styles"
26
- import Link from "@material-ui/core/Link"
27
-
28
- const TTLHelperText = ( {
29
- ttl,
30
- translationName,
31
- } : {
32
- ttl ?: number
33
- translationName : string
34
- } ) => {
35
- const { t } = useTranslation ( "templateSettingsPage" )
36
- const count = typeof ttl !== "number" ? 0 : ttl
37
- return (
38
- // no helper text if ttl is negative - error will show once field is considered touched
39
- < Maybe condition = { count >= 0 } >
40
- < span > { t ( translationName , { count } ) } </ span >
41
- </ Maybe >
42
- )
43
- }
44
25
45
26
const MAX_DESCRIPTION_CHAR_LIMIT = 128
46
- const MAX_TTL_DAYS = 7
47
- const MS_HOUR_CONVERSION = 3600000
48
27
49
28
export const getValidationSchema = ( ) : Yup . AnyObjectSchema =>
50
29
Yup . object ( {
@@ -58,20 +37,7 @@ export const getValidationSchema = (): Yup.AnyObjectSchema =>
58
37
MAX_DESCRIPTION_CHAR_LIMIT ,
59
38
i18next . t ( "descriptionMaxError" , { ns : "templateSettingsPage" } ) ,
60
39
) ,
61
- default_ttl_ms : Yup . number ( )
62
- . integer ( )
63
- . min ( 0 , i18next . t ( "defaultTTLMinError" , { ns : "templateSettingsPage" } ) )
64
- . max (
65
- 24 * MAX_TTL_DAYS /* 7 days in hours */ ,
66
- i18next . t ( "defaultTTLMaxError" , { ns : "templateSettingsPage" } ) ,
67
- ) ,
68
- max_ttl_ms : Yup . number ( )
69
- . integer ( )
70
- . min ( 0 , i18next . t ( "maxTTLMinError" , { ns : "templateSettingsPage" } ) )
71
- . max (
72
- 24 * MAX_TTL_DAYS /* 7 days in hours */ ,
73
- i18next . t ( "maxTTLMaxError" , { ns : "templateSettingsPage" } ) ,
74
- ) ,
40
+
75
41
allow_user_cancel_workspace_jobs : Yup . boolean ( ) ,
76
42
} )
77
43
@@ -81,7 +47,6 @@ export interface TemplateSettingsForm {
81
47
onCancel : ( ) => void
82
48
isSubmitting : boolean
83
49
error ?: unknown
84
- canSetMaxTTL : boolean
85
50
// Helpful to show field errors on Storybook
86
51
initialTouched ?: FormikTouched < UpdateTemplateMeta >
87
52
}
@@ -91,40 +56,22 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
91
56
onSubmit,
92
57
onCancel,
93
58
error,
94
- canSetMaxTTL,
95
59
isSubmitting,
96
60
initialTouched,
97
61
} ) => {
98
- const { t : commonT } = useTranslation ( "common" )
99
62
const validationSchema = getValidationSchema ( )
100
63
const form : FormikContextType < UpdateTemplateMeta > =
101
64
useFormik < UpdateTemplateMeta > ( {
102
65
initialValues : {
103
66
name : template . name ,
104
67
display_name : template . display_name ,
105
68
description : template . description ,
106
- // on display, convert from ms => hours
107
- default_ttl_ms : template . default_ttl_ms / MS_HOUR_CONVERSION ,
108
- // the API ignores this value, but to avoid tripping up validation set
109
- // it to zero if the user can't set the field.
110
- max_ttl_ms : canSetMaxTTL ? template . max_ttl_ms / MS_HOUR_CONVERSION : 0 ,
111
69
icon : template . icon ,
112
70
allow_user_cancel_workspace_jobs :
113
71
template . allow_user_cancel_workspace_jobs ,
114
72
} ,
115
73
validationSchema,
116
- onSubmit : ( formData ) => {
117
- // on submit, convert from hours => ms
118
- onSubmit ( {
119
- ...formData ,
120
- default_ttl_ms : formData . default_ttl_ms
121
- ? formData . default_ttl_ms * MS_HOUR_CONVERSION
122
- : undefined ,
123
- max_ttl_ms : formData . max_ttl_ms
124
- ? formData . max_ttl_ms * MS_HOUR_CONVERSION
125
- : undefined ,
126
- } )
127
- } ,
74
+ onSubmit,
128
75
initialTouched,
129
76
} )
130
77
const getFieldHelpers = getFormHelpers < UpdateTemplateMeta > ( form , error )
@@ -188,55 +135,6 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
188
135
</ FormFields >
189
136
</ FormSection >
190
137
191
- < FormSection
192
- title = { t ( "schedule.title" ) }
193
- description = { t ( "schedule.description" ) }
194
- >
195
- < Stack direction = "row" className = { styles . ttlFields } >
196
- < TextField
197
- { ...getFieldHelpers (
198
- "default_ttl_ms" ,
199
- < TTLHelperText
200
- translationName = "defaultTTLHelperText"
201
- ttl = { form . values . default_ttl_ms }
202
- /> ,
203
- ) }
204
- disabled = { isSubmitting }
205
- fullWidth
206
- inputProps = { { min : 0 , step : 1 } }
207
- label = { t ( "defaultTtlLabel" ) }
208
- variant = "outlined"
209
- type = "number"
210
- />
211
-
212
- < TextField
213
- { ...getFieldHelpers (
214
- "max_ttl_ms" ,
215
- canSetMaxTTL ? (
216
- < TTLHelperText
217
- translationName = "maxTTLHelperText"
218
- ttl = { form . values . max_ttl_ms }
219
- />
220
- ) : (
221
- < >
222
- { commonT ( "licenseFieldTextHelper" ) } { " " }
223
- < Link href = "https://coder.com/docs/v2/latest/enterprise" >
224
- { commonT ( "learnMore" ) }
225
- </ Link >
226
- .
227
- </ >
228
- ) ,
229
- ) }
230
- disabled = { isSubmitting || ! canSetMaxTTL }
231
- fullWidth
232
- inputProps = { { min : 0 , step : 1 } }
233
- label = { t ( "maxTtlLabel" ) }
234
- variant = "outlined"
235
- type = "number"
236
- />
237
- </ Stack >
238
- </ FormSection >
239
-
240
138
< FormSection
241
139
title = { t ( "operations.title" ) }
242
140
description = { t ( "operations.description" ) }
@@ -290,8 +188,4 @@ const useStyles = makeStyles((theme) => ({
290
188
fontSize : theme . spacing ( 1.5 ) ,
291
189
color : theme . palette . text . secondary ,
292
190
} ,
293
-
294
- ttlFields : {
295
- width : "100%" ,
296
- } ,
297
191
} ) )
0 commit comments