Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5dd8416

Browse files
committed
fix: allow delesecting a preset without triggering a validation error
1 parent c3bc1e7 commit 5dd8416

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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

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

204+
export const PresetNoneSelected: 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' in request),
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+
const canvas = within(canvasElement);
218+
219+
// First select a preset to set the field value
220+
await userEvent.click(canvas.getByLabelText("Preset"));
221+
await userEvent.click(canvas.getByText("Preset 1"));
222+
223+
// Then select "None" to unset the field value
224+
await userEvent.click(canvas.getByLabelText("Preset"));
225+
await userEvent.click(canvas.getByText("None"));
226+
227+
// Fill in required fields and submit to test the API call
228+
await userEvent.type(canvas.getByLabelText("Workspace Name"), "test-workspace");
229+
await userEvent.click(canvas.getByText("Create workspace"));
230+
},
231+
parameters: {
232+
docs: {
233+
description: {
234+
story: "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.",
235+
},
236+
},
237+
},
238+
};
239+
204240
export const ExternalAuth: Story = {
205241
args: {
206242
externalAuth: [

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
369369
setSelectedPresetIndex(index);
370370
form.setFieldValue(
371371
"template_version_preset_id",
372-
option?.value,
372+
index === 0 ? undefined : option?.value,
373373
);
374374
}}
375375
placeholder="Select a preset"

0 commit comments

Comments
 (0)