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

Commit4f98fd4

Browse files
SasSwartjaaydenhssncferreira
authored
fix: fix validation error during workspace creation without preset (#18494)
closes#18430.Selecting a preset, and then selecting the "None" preset used to result in a validation error because an invalid preset id ("") was sent to the backend.---------Co-authored-by: Jaayden Halko <jaayden@coder.com>Co-authored-by: Susana Ferreira <susana@coder.com>
1 parent796dc7a commit4f98fd4

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.stories.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,46 @@ export const PresetReselected: Story = {
201201
},
202202
};
203203

204+
exportconstPresetNoneSelected:Story={
205+
args:{
206+
...PresetsButNoneSelected.args,
207+
onSubmit:(request,owner)=>{
208+
// Assert that template_version_preset_id is not present in the request
209+
console.assert(
210+
!("template_version_preset_id"inrequest),
211+
'template_version_preset_id should not be present when "None" is selected',
212+
);
213+
action("onSubmit")(request,owner);
214+
},
215+
},
216+
play:async({ canvasElement})=>{
217+
constcanvas=within(canvasElement);
218+
219+
// First select a preset to set the field value
220+
awaituserEvent.click(canvas.getByLabelText("Preset"));
221+
awaituserEvent.click(canvas.getByText("Preset 1"));
222+
223+
// Then select "None" to unset the field value
224+
awaituserEvent.click(canvas.getByLabelText("Preset"));
225+
awaituserEvent.click(canvas.getByText("None"));
226+
227+
// Fill in required fields and submit to test the API call
228+
awaituserEvent.type(
229+
canvas.getByLabelText("Workspace Name"),
230+
"test-workspace",
231+
);
232+
awaituserEvent.click(canvas.getByText("Create workspace"));
233+
},
234+
parameters:{
235+
docs:{
236+
description:{
237+
story:
238+
"This story tests that when 'None' preset is selected, the template_version_preset_id field is not included in the form submission. The story first selects a preset to set the field value, then selects 'None' to unset it, and finally submits the form to verify the API call behavior.",
239+
},
240+
},
241+
},
242+
};
243+
204244
exportconstExternalAuth:Story={
205245
args:{
206246
externalAuth:[

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
369369
setSelectedPresetIndex(index);
370370
form.setFieldValue(
371371
"template_version_preset_id",
372-
option?.value,
372+
// Empty string is equivalent to using None
373+
option?.value==="" ?undefined :option?.value,
373374
);
374375
}}
375376
placeholder="Select a preset"

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,10 @@ export const CreateWorkspacePageViewExperimental: FC<
563563
return;
564564
}
565565
setSelectedPresetIndex(index);
566+
form.setFieldValue(
567+
"template_version_preset_id",
568+
index===0 ?undefined :option,
569+
);
566570
}}
567571
>
568572
<SelectTrigger>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp