mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(site): Only display fields with redisplay enabled during workspace creation (#6004)
* fix(site): Only display fields with redisplay_value during workspace creation * Fix test --------- Co-authored-by: Kyle Carberry <kyle@carberry.com>
This commit is contained in:
co-authored by
Kyle Carberry
parent
2384e9c565
commit
f60f06e2c6
@@ -104,6 +104,7 @@ describe("CreateWorkspacePage", () => {
|
||||
jest.spyOn(API, "getTemplateVersionSchema").mockResolvedValueOnce([
|
||||
mockParameterSchema({
|
||||
name: param,
|
||||
redisplay_value: true,
|
||||
default_source_value: "",
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -39,6 +39,7 @@ Parameters.args = {
|
||||
name: "region",
|
||||
default_source_value: "🏈 US Central",
|
||||
description: "Where would you like your workspace to live?",
|
||||
redisplay_value: true,
|
||||
validation_contains: [
|
||||
"🏈 US Central",
|
||||
"⚽ Brazil East",
|
||||
@@ -51,18 +52,63 @@ Parameters.args = {
|
||||
default_source_value: "Big",
|
||||
description: "How large should you instance be?",
|
||||
validation_contains: ["Small", "Medium", "Big"],
|
||||
redisplay_value: true,
|
||||
}),
|
||||
mockParameterSchema({
|
||||
name: "instance_size",
|
||||
default_source_value: "Big",
|
||||
description: "How large should your instance be?",
|
||||
validation_contains: ["Small", "Medium", "Big"],
|
||||
redisplay_value: true,
|
||||
}),
|
||||
mockParameterSchema({
|
||||
name: "disable_docker",
|
||||
description: "Disable Docker?",
|
||||
validation_value_type: "bool",
|
||||
default_source_value: "false",
|
||||
redisplay_value: true,
|
||||
}),
|
||||
],
|
||||
createWorkspaceErrors: {},
|
||||
}
|
||||
|
||||
export const RedisplayParameters = Template.bind({})
|
||||
RedisplayParameters.args = {
|
||||
templates: [MockTemplate],
|
||||
selectedTemplate: MockTemplate,
|
||||
templateSchema: [
|
||||
mockParameterSchema({
|
||||
name: "region",
|
||||
default_source_value: "🏈 US Central",
|
||||
description: "Where would you like your workspace to live?",
|
||||
redisplay_value: false,
|
||||
validation_contains: [
|
||||
"🏈 US Central",
|
||||
"⚽ Brazil East",
|
||||
"💶 EU West",
|
||||
"🦘 Australia South",
|
||||
],
|
||||
}),
|
||||
mockParameterSchema({
|
||||
name: "instance_size",
|
||||
default_source_value: "Big",
|
||||
description: "How large should you instance be?",
|
||||
validation_contains: ["Small", "Medium", "Big"],
|
||||
redisplay_value: false,
|
||||
}),
|
||||
mockParameterSchema({
|
||||
name: "instance_size",
|
||||
default_source_value: "Big",
|
||||
description: "How large should your instance be?",
|
||||
validation_contains: ["Small", "Medium", "Big"],
|
||||
redisplay_value: true,
|
||||
}),
|
||||
mockParameterSchema({
|
||||
name: "disable_docker",
|
||||
description: "Disable Docker?",
|
||||
validation_value_type: "bool",
|
||||
default_source_value: "false",
|
||||
redisplay_value: true,
|
||||
}),
|
||||
],
|
||||
createWorkspaceErrors: {},
|
||||
|
||||
@@ -31,7 +31,6 @@ export interface CreateWorkspacePageViewProps {
|
||||
templates?: TypesGen.Template[]
|
||||
selectedTemplate?: TypesGen.Template
|
||||
templateParameters?: TypesGen.TemplateVersionParameter[]
|
||||
|
||||
templateSchema?: TypesGen.ParameterSchema[]
|
||||
createWorkspaceErrors: Partial<Record<CreateWorkspaceErrors, Error | unknown>>
|
||||
canCreateForUser?: boolean
|
||||
@@ -239,20 +238,23 @@ export const CreateWorkspacePageView: FC<
|
||||
spacing={4} // Spacing here is diff because the fields here don't have the MUI floating label spacing
|
||||
className={styles.formSectionFields}
|
||||
>
|
||||
{props.templateSchema.map((schema) => (
|
||||
<ParameterInput
|
||||
disabled={form.isSubmitting}
|
||||
key={schema.id}
|
||||
defaultValue={parameterValues[schema.name]}
|
||||
onChange={(value) => {
|
||||
setParameterValues({
|
||||
...parameterValues,
|
||||
[schema.name]: value,
|
||||
})
|
||||
}}
|
||||
schema={schema}
|
||||
/>
|
||||
))}
|
||||
{props.templateSchema
|
||||
// We only want to show schema that have redisplay_value equals true
|
||||
.filter((schema) => schema.redisplay_value)
|
||||
.map((schema) => (
|
||||
<ParameterInput
|
||||
disabled={form.isSubmitting}
|
||||
key={schema.id}
|
||||
defaultValue={parameterValues[schema.name]}
|
||||
onChange={(value) => {
|
||||
setParameterValues({
|
||||
...parameterValues,
|
||||
[schema.name]: value,
|
||||
})
|
||||
}}
|
||||
schema={schema}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user