Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3173a5e

Browse files
committed
switch to query params
1 parent3862311 commit3173a5e

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

‎site/e2e/helpers.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,15 @@ export const createTemplate = async (
183183
letpath="/templates/new";
184184
if(isStarterTemplate(responses)){
185185
path+=`?exampleId=${responses}`;
186+
}else{
187+
// The form page will read this value and use it as the default type.
188+
path+="?provisioner_type=echo";
186189
}
187190

188191
awaitpage.goto(path,{waitUntil:"domcontentloaded"});
189192
awaitexpectUrl(page).toHavePathName("/templates/new");
190193

191194
if(!isStarterTemplate(responses)){
192-
awaitpage
193-
.locator(`xpath=//input[@data-testid="provisioner-type-input"]`)
194-
.evaluate((el:HTMLElement)=>{
195-
// This is a little jank, but the "setAttribute" updates the HTML, but not the formik values.
196-
el.setAttribute("value","echo");
197-
// This '.click()' activates the onClick handler that tells the input to update it's formik value.
198-
el.click();
199-
});
200-
201195
awaitpage.getByTestId("file-upload").setInputFiles({
202196
buffer:awaitcreateTemplateVersionTar(responses),
203197
mimeType:"application/x-tar",

‎site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
}from"utils/schedule";
3434
import{TemplateUpload,typeTemplateUploadProps}from"./TemplateUpload";
3535
import{VariableInput}from"./VariableInput";
36+
import{useSearchParams}from"react-router-dom";
3637

3738
constMAX_DESCRIPTION_CHAR_LIMIT=128;
3839

@@ -91,16 +92,23 @@ type GetInitialValuesParams = {
9192
fromCopy?:Template;
9293
variables?:TemplateVersionVariable[];
9394
allowAdvancedScheduling:boolean;
95+
searchParams:URLSearchParams;
9496
};
9597

9698
constgetInitialValues=({
9799
fromExample,
98100
fromCopy,
99101
allowAdvancedScheduling,
100102
variables,
103+
searchParams,
101104
}:GetInitialValuesParams)=>{
102105
letinitialValues=defaultInitialValues;
103106

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")asProvisionerType)||"terraform";
111+
104112
if(!allowAdvancedScheduling){
105113
initialValues={
106114
...initialValues,
@@ -167,6 +175,7 @@ export type CreateTemplateFormProps = (
167175
};
168176

169177
exportconstCreateTemplateForm:FC<CreateTemplateFormProps>=(props)=>{
178+
const[searchParams,_]=useSearchParams();
170179
const{
171180
onCancel,
172181
onSubmit,
@@ -179,13 +188,15 @@ export const CreateTemplateForm: FC<CreateTemplateFormProps> = (props) => {
179188
allowAdvancedScheduling,
180189
variablesSectionRef,
181190
}=props;
191+
182192
constform=useFormik<CreateTemplateData>({
183193
initialValues:getInitialValues({
184194
allowAdvancedScheduling,
185195
fromExample:
186196
"starterTemplate"inprops ?props.starterTemplate :undefined,
187197
fromCopy:"copiedTemplate"inprops ?props.copiedTemplate :undefined,
188198
variables,
199+
searchParams,
189200
}),
190201
validationSchema,
191202
onSubmit,
@@ -217,25 +228,6 @@ export const CreateTemplateForm: FC<CreateTemplateFormProps> = (props) => {
217228
/>
218229
)}
219230

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-
awaitform.setFieldValue("provisioner_type",e.target.value);
236-
}}
237-
/>
238-
239231
<TextField
240232
{...getFieldHelpers("name")}
241233
disabled={isSubmitting}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp