Skip to content

Commit 49b4ad6

Browse files
committed
refactor: clean up TemplateParameters components
1 parent e290ece commit 49b4ad6

File tree

1 file changed

+45
-53
lines changed

1 file changed

+45
-53
lines changed

site/src/components/TemplateParameters/TemplateParameters.tsx

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,68 +17,60 @@ export type TemplateParametersSectionProps = {
1717
export const MutableTemplateParametersSection: FC<
1818
TemplateParametersSectionProps
1919
> = ({ templateParameters, getInputProps, ...formSectionProps }) => {
20-
const hasMutableParameters =
21-
templateParameters.filter((p) => p.mutable).length > 0;
20+
const mutableParameters = templateParameters.filter((p) => p.mutable);
21+
22+
if (mutableParameters.length === 0) {
23+
return null;
24+
}
2225

2326
return (
24-
<>
25-
{hasMutableParameters && (
26-
<FormSection
27-
{...formSectionProps}
28-
title="Parameters"
29-
description="Settings used by your template"
30-
>
31-
<FormFields>
32-
{templateParameters.map(
33-
(parameter, index) =>
34-
parameter.mutable && (
35-
<RichParameterInput
36-
{...getInputProps(parameter, index)}
37-
key={parameter.name}
38-
parameter={parameter}
39-
/>
40-
),
41-
)}
42-
</FormFields>
43-
</FormSection>
44-
)}
45-
</>
27+
<FormSection
28+
{...formSectionProps}
29+
title="Parameters"
30+
description="Settings used by your template"
31+
>
32+
<FormFields>
33+
{mutableParameters.map((parameter, index) => (
34+
<RichParameterInput
35+
{...getInputProps(parameter, index)}
36+
key={parameter.name}
37+
parameter={parameter}
38+
/>
39+
))}
40+
</FormFields>
41+
</FormSection>
4642
);
4743
};
4844

4945
export const ImmutableTemplateParametersSection: FC<
5046
TemplateParametersSectionProps
5147
> = ({ templateParameters, getInputProps, ...formSectionProps }) => {
52-
const hasImmutableParameters =
53-
templateParameters.filter((p) => !p.mutable).length > 0;
48+
const immutableParams = templateParameters.filter((p) => !p.mutable);
49+
50+
if (immutableParams.length === 0) {
51+
return null;
52+
}
5453

5554
return (
56-
<>
57-
{hasImmutableParameters && (
58-
<FormSection
59-
{...formSectionProps}
60-
title="Immutable parameters"
61-
description={
62-
<>
63-
These settings <strong>cannot be changed</strong> after creating
64-
the workspace.
65-
</>
66-
}
67-
>
68-
<FormFields>
69-
{templateParameters.map(
70-
(parameter, index) =>
71-
!parameter.mutable && (
72-
<RichParameterInput
73-
{...getInputProps(parameter, index)}
74-
key={parameter.name}
75-
parameter={parameter}
76-
/>
77-
),
78-
)}
79-
</FormFields>
80-
</FormSection>
81-
)}
82-
</>
55+
<FormSection
56+
{...formSectionProps}
57+
title="Immutable parameters"
58+
description={
59+
<>
60+
These settings <strong>cannot be changed</strong> after creating the
61+
workspace.
62+
</>
63+
}
64+
>
65+
<FormFields>
66+
{immutableParams.map((parameter, index) => (
67+
<RichParameterInput
68+
{...getInputProps(parameter, index)}
69+
key={parameter.name}
70+
parameter={parameter}
71+
/>
72+
))}
73+
</FormFields>
74+
</FormSection>
8375
);
8476
};

0 commit comments

Comments
 (0)