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

Commitddb49df

Browse files
blink-so[bot]jaaydenh
authored andcommitted
fix: preserve parameter values when dynamic ordering changes (#18270)
## ProblemWhen creating a workspace from a template with dynamic parameterordering, parameter values are not displaying correctly when the orderchanges. This occurs when a parameter's `order` value depends on anotherparameter's value.**Example scenario:**```terraformdata "coder_parameter" "reorder" { name = "reorder" type = "bool" default = false order = 1}data "coder_parameter" "cpu" { order = data.coder_parameter.reorder.value ? 0 : 2 name = "cpu" type = "number" default = 4}```When the user toggles `reorder` from `false` to `true`, the `cpu`parameter moves from position 2 to position 0, but its value gets mixedup with the `reorder` parameter's value.## Root CauseThe issue was in `CreateWorkspacePageViewExperimental.tsx` whereparameters were rendered using array indices instead of parameter names:```typescript// Problematic codeconst parameterField = `rich_parameter_values.${index}`;const formValue = form.values?.rich_parameter_values?.[index]?.value || "";```When parameters are reordered:1. The `parameters` array order changes based on the new `order` values2. The `form.values.rich_parameter_values` array maintains the originalorder3. Array index-based lookup causes values to be mismatched## SolutionImplemented name-based lookup to ensure parameter values stay with theircorrect parameters:```typescript// Find parameter value by name instead of indexconst currentParameterValueIndex = form.values.rich_parameter_values?.findIndex( (p) => p.name === parameter.name) ?? -1;// Use the found index for form field mappingconst parameterFieldIndex = currentParameterValueIndex !== -1 ? currentParameterValueIndex : index;const parameterField = `rich_parameter_values.${parameterFieldIndex}`;// Get form value by name to ensure correct mappingconst formValue = currentParameterValueIndex !== -1 ? form.values?.rich_parameter_values?.[currentParameterValueIndex]?.value || "" : "";```## Testing- ✅ Created test script that validates the fix works correctly- ✅ Tested with the provided template showing dynamic parameter ordering- ✅ Verified parameter values persist correctly during reordering- ✅ Confirmed no TypeScript compilation issues## ImpactThis fix ensures that users can reliably use dynamic parameter orderingin their templates without losing parameter values when the orderchanges. This is particularly important for templates that useconditional parameter visibility and ordering based on user selections.---------Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com>Co-authored-by: Jaayden Halko <jaayden@coder.com>
1 parenta30a18f commitddb49df

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,15 @@ export const CreateWorkspacePageViewExperimental: FC<
608608

609609
<divclassName="flex flex-col gap-9">
610610
{parameters.map((parameter,index)=>{
611-
constparameterField=`rich_parameter_values.${index}`;
611+
constcurrentParameterValueIndex=
612+
form.values.rich_parameter_values?.findIndex(
613+
(p)=>p.name===parameter.name,
614+
)??-1;
615+
constparameterFieldIndex=
616+
currentParameterValueIndex!==-1
617+
?currentParameterValueIndex
618+
:index;
619+
constparameterField=`rich_parameter_values.${parameterFieldIndex}`;
612620
constisPresetParameter=presetParameterNames.includes(
613621
parameter.name,
614622
);
@@ -629,8 +637,13 @@ export const CreateWorkspacePageViewExperimental: FC<
629637
returnnull;
630638
}
631639

640+
// Get the form value by parameter name to ensure correct value mapping
632641
constformValue=
633-
form.values?.rich_parameter_values?.[index]?.value||"";
642+
currentParameterValueIndex!==-1
643+
?form.values?.rich_parameter_values?.[
644+
currentParameterValueIndex
645+
]?.value||""
646+
:"";
634647

635648
return(
636649
<DynamicParameter

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp