8000 fix: preserve parameter values when dynamic ordering changes by blink-so[bot] · Pull Request #18270 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix: preserve parameter values when dynamic ordering changes #18270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: preserve parameter values when dynamic ordering changes
When parameters are reordered dynamically (e.g., when a parameter's order
depends on another parameter's value), the parameter values were not
displaying correctly. This was because the rendering logic used array
indices instead of parameter names to map form values.

The issue occurred when:
1. Parameters are initially rendered in one order
2. A parameter value changes, causing dynamic reordering
3. The parameter array order changes but form values array stays the same
4. Values get mismatched due to index-based lookup

This fix implements name-based lookup to ensure parameter values persist
correctly regardless of ordering changes:
- Find parameter value by name instead of array index
- Use the found index for form field mapping
- Fallback to current index for new parameters

Fixes parameter value persistence in dynamic parameter ordering scenarios.
  • Loading branch information
blink-so[bot] committed Jun 6, 2025
commit 290f11b9db698458ac1ac676061c463ba30604b3
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,15 @@ export const CreateWorkspacePageViewExperimental: FC<

<div className="flex flex-col gap-9">
{parameters.map((parameter, index) => {
const parameterField = `rich_parameter_values.${index}`;
// Find the current parameter's value by name instead of index
// to ensure values persist correctly when parameter order changes
const currentParameterValueIndex = form.values.rich_parameter_values?.findIndex(
(p) => p.name === parameter.name
) ?? -1;

// Use the found index for the parameter field, or fallback to current index
const parameterFieldIndex = currentParameterValueIndex !== -1 ? currentParameterValueIndex : index;
const parameterField = `rich_parameter_values.${parameterFieldIndex}`;
const isPresetParameter = presetParameterNames.includes(
parameter.name,
);
Expand All @@ -629,8 +637,10 @@ export const CreateWorkspacePageViewExperimental: FC<
return null;
}

const formValue =
form.values?.rich_parameter_values?.[index]?.value || "";
// Get the form value by parameter name to ensure correct value mapping
const formValue = currentParameterValueIndex !== -1
? form.values?.rich_parameter_values?.[currentParameterValueIndex]?.value || ""
: "";

return (
<DynamicParameter
Expand Down
Loading
0