@@ -6,18 +6,30 @@ import {
6
6
HorizontalForm ,
7
7
} from "components/Form/Form" ;
8
8
import { useFormik } from "formik" ;
9
- import { type FC } from "react" ;
9
+ import { useState , type FC } from "react" ;
10
10
import * as Yup from "yup" ;
11
11
import {
12
12
nameValidator ,
13
13
getFormHelpers ,
14
14
onChangeTrimmed ,
15
15
} from "utils/formUtils" ;
16
- import { Workspace } from "api/typesGenerated" ;
16
+ import {
17
+ AutomaticUpdates ,
18
+ AutomaticUpdateses ,
19
+ Workspace ,
20
+ } from "api/typesGenerated" ;
17
21
import { Alert } from "components/Alert/Alert" ;
22
+ import {
23
+ FormControl ,
24
+ InputLabel ,
25
+ MenuItem ,
26
+ Select ,
27
+ SelectChangeEvent ,
28
+ } from "@mui/material" ;
18
29
19
30
export type WorkspaceSettingsFormValues = {
20
31
name : string ;
32
+ automatic_updates : AutomaticUpdates ;
21
33
} ;
22
34
23
35
export const WorkspaceSettingsForm : FC < {
@@ -31,6 +43,7 @@ export const WorkspaceSettingsForm: FC<{
31
43
onSubmit,
32
44
initialValues : {
33
45
name : workspace . name ,
46
+ automatic_updates : workspace . automatic_updates ,
34
47
} ,
35
48
validationSchema : Yup . object ( {
36
49
name : nameValidator ( "Name" ) ,
@@ -41,9 +54,25 @@ export const WorkspaceSettingsForm: FC<{
41
54
error ,
42
55
) ;
43
56
57
+ const capitalizeFirstLetter = ( inputString : string ) : string => {
58
+ return inputString . charAt ( 0 ) . toUpperCase ( ) + inputString . slice ( 1 ) ;
59
+ } ;
60
+
61
+ const [ automaticUpdates , setAutomaticUpdates ] = useState < AutomaticUpdates > (
62
+ workspace . automatic_updates ,
63
+ ) ;
64
+
65
+ const handleChange = ( event : SelectChangeEvent ) => {
66
+ setAutomaticUpdates ( event . target . value as AutomaticUpdates ) ;
67
+ form . setFieldValue ( "automatic_updates" , automaticUpdates ) ;
68
+ } ;
69
+
44
70
return (
45
71
< HorizontalForm onSubmit = { form . handleSubmit } data-testid = "form" >
46
- < FormSection title = "General" description = "The name of your workspace." >
72
+ < FormSection
73
+ title = "Workspace Name"
74
+ description = "Update the name of your workspace."
75
+ >
47
76
< FormFields >
48
77
< TextField
49
78
{ ...getFieldHelpers ( "name" ) }
@@ -61,6 +90,30 @@ export const WorkspaceSettingsForm: FC<{
61
90
) }
62
91
</ FormFields >
63
92
</ FormSection >
93
+ < FormSection
94
+ title = "Automatic Updates"
95
+ description = "Configure your workspace to automatically update to the active template version when started."
96
+ >
97
+ < FormControl fullWidth >
98
+ < FormFields >
99
+ < InputLabel htmlFor = "automatic_updates" > Update Policy</ InputLabel >
100
+ < Select
101
+ labelId = "automatic_updates"
102
+ id = "automatic_updates"
103
+ label = "Update Policy"
104
+ value = { automaticUpdates }
105
+ onChange = { handleChange }
106
+ disabled = { form . isSubmitting }
107
+ >
108
+ { AutomaticUpdateses . map ( ( value ) => (
109
+ < MenuItem value = { value } >
110
+ { capitalizeFirstLetter ( value ) }
111
+ </ MenuItem >
112
+ ) ) }
113
+ </ Select >
114
+ </ FormFields >
115
+ </ FormControl >
116
+ </ FormSection >
64
117
< FormFooter onCancel = { onCancel } isLoading = { isSubmitting } />
65
118
</ HorizontalForm >
66
119
) ;
0 commit comments