@@ -33,6 +33,7 @@ import {
33
33
} from "utils/schedule" ;
34
34
import { TemplateUpload , type TemplateUploadProps } from "./TemplateUpload" ;
35
35
import { VariableInput } from "./VariableInput" ;
36
+ import { useSearchParams } from "react-router-dom" ;
36
37
37
38
const MAX_DESCRIPTION_CHAR_LIMIT = 128 ;
38
39
@@ -91,16 +92,23 @@ type GetInitialValuesParams = {
91
92
fromCopy ?:Template ;
92
93
variables ?:TemplateVersionVariable [ ] ;
93
94
allowAdvancedScheduling :boolean ;
95
+ searchParams :URLSearchParams ;
94
96
} ;
95
97
96
98
const getInitialValues = ( {
97
99
fromExample,
98
100
fromCopy,
99
101
allowAdvancedScheduling,
100
102
variables,
103
+ searchParams,
101
104
} :GetInitialValuesParams ) => {
102
105
let initialValues = defaultInitialValues ;
103
106
107
+ // Will assume the query param has a valid ProvisionerType, as this query param is only used
108
+ // in testing.
109
+ defaultInitialValues . provisioner_type =
110
+ ( searchParams . get ( "provisioner_type" ) as ProvisionerType ) || "terraform" ;
111
+
104
112
if ( ! allowAdvancedScheduling ) {
105
113
initialValues = {
106
114
...initialValues ,
@@ -167,6 +175,7 @@ export type CreateTemplateFormProps = (
167
175
} ;
168
176
169
177
export const CreateTemplateForm :FC < CreateTemplateFormProps > = ( props ) => {
178
+ const [ searchParams , _ ] = useSearchParams ( ) ;
170
179
const {
171
180
onCancel,
172
181
onSubmit,
@@ -179,13 +188,15 @@ export const CreateTemplateForm: FC<CreateTemplateFormProps> = (props) => {
179
188
allowAdvancedScheduling,
180
189
variablesSectionRef,
181
190
} = props ;
191
+
182
192
const form = useFormik < CreateTemplateData > ( {
183
193
initialValues :getInitialValues ( {
184
194
allowAdvancedScheduling,
185
195
fromExample :
186
196
"starterTemplate" in props ?props . starterTemplate :undefined ,
187
197
fromCopy :"copiedTemplate" in props ?props . copiedTemplate :undefined ,
188
198
variables,
199
+ searchParams,
189
200
} ) ,
190
201
validationSchema,
191
202
onSubmit,
@@ -217,25 +228,6 @@ export const CreateTemplateForm: FC<CreateTemplateFormProps> = (props) => {
217
228
/>
218
229
) }
219
230
220
- { /*
221
- This value is always "terraform" in production.
222
- For testing purposes, we expose this as a hidden form element
223
- that can be changed. For example, to "echo"
224
- */ }
225
- < Field
226
- type = "hidden"
227
- { ...getFieldHelpers ( "provisioner_type" ) }
228
- data-testid = "provisioner-type-input"
229
- label = "Provisioner type"
230
- // This is a bit jank, but when you call 'setAttribute('value', 'echo') from playwright, the formik form
231
- // is not updated. So calling 'click' will also update formik. This is super weird, but I cannot find another
232
- // way
233
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Not sure what the actual type is here.
234
- onClick = { async ( e :any ) => {
235
- await form . setFieldValue ( "provisioner_type" , e . target . value ) ;
236
- } }
237
- />
238
-
239
231
< TextField
240
232
{ ...getFieldHelpers ( "name" ) }
241
233
disabled = { isSubmitting }