Skip to content

Commit f5a9673

Browse files
committed
Remove schedule from general settings
1 parent 674647c commit f5a9673

File tree

1 file changed

+2
-108
lines changed

1 file changed

+2
-108
lines changed

site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx

Lines changed: 2 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import * as Yup from "yup"
1212
import i18next from "i18next"
1313
import { useTranslation } from "react-i18next"
14-
import { Maybe } from "components/Conditionals/Maybe"
1514
import { LazyIconField } from "components/IconField/LazyIconField"
1615
import {
1716
FormFields,
@@ -23,28 +22,8 @@ import { Stack } from "components/Stack/Stack"
2322
import Checkbox from "@material-ui/core/Checkbox"
2423
import { HelpTooltip, HelpTooltipText } from "components/Tooltips/HelpTooltip"
2524
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-
}
4425

4526
const MAX_DESCRIPTION_CHAR_LIMIT = 128
46-
const MAX_TTL_DAYS = 7
47-
const MS_HOUR_CONVERSION = 3600000
4827

4928
export const getValidationSchema = (): Yup.AnyObjectSchema =>
5029
Yup.object({
@@ -58,20 +37,7 @@ export const getValidationSchema = (): Yup.AnyObjectSchema =>
5837
MAX_DESCRIPTION_CHAR_LIMIT,
5938
i18next.t("descriptionMaxError", { ns: "templateSettingsPage" }),
6039
),
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+
7541
allow_user_cancel_workspace_jobs: Yup.boolean(),
7642
})
7743

@@ -81,7 +47,6 @@ export interface TemplateSettingsForm {
8147
onCancel: () => void
8248
isSubmitting: boolean
8349
error?: unknown
84-
canSetMaxTTL: boolean
8550
// Helpful to show field errors on Storybook
8651
initialTouched?: FormikTouched<UpdateTemplateMeta>
8752
}
@@ -91,40 +56,22 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
9156
onSubmit,
9257
onCancel,
9358
error,
94-
canSetMaxTTL,
9559
isSubmitting,
9660
initialTouched,
9761
}) => {
98-
const { t: commonT } = useTranslation("common")
9962
const validationSchema = getValidationSchema()
10063
const form: FormikContextType<UpdateTemplateMeta> =
10164
useFormik<UpdateTemplateMeta>({
10265
initialValues: {
10366
name: template.name,
10467
display_name: template.display_name,
10568
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,
11169
icon: template.icon,
11270
allow_user_cancel_workspace_jobs:
11371
template.allow_user_cancel_workspace_jobs,
11472
},
11573
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,
12875
initialTouched,
12976
})
13077
const getFieldHelpers = getFormHelpers<UpdateTemplateMeta>(form, error)
@@ -188,55 +135,6 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
188135
</FormFields>
189136
</FormSection>
190137

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-
240138
<FormSection
241139
title={t("operations.title")}
242140
description={t("operations.description")}
@@ -290,8 +188,4 @@ const useStyles = makeStyles((theme) => ({
290188
fontSize: theme.spacing(1.5),
291189
color: theme.palette.text.secondary,
292190
},
293-
294-
ttlFields: {
295-
width: "100%",
296-
},
297191
}))

0 commit comments

Comments
 (0)