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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
blink-so wants to merge2 commits intomain
base:main
Choose a base branch
Loading
fromfix/dynamic-parameter-ordering-values

Conversation

blink-so[bot]
Copy link
Contributor

@blink-soblink-sobot commentedJun 6, 2025

Problem

When creating a workspace from a template with dynamic parameter ordering, parameter values are not displaying correctly when the order changes. This occurs when a parameter'sorder value depends on another parameter's value.

Example scenario:

data"coder_parameter""reorder" {name="reorder"type="bool"default=falseorder=1}data"coder_parameter""cpu" {order=data.coder_parameter.reorder.value?0:2name="cpu"type="number"default=4}

When the user togglesreorder fromfalse totrue, thecpu parameter moves from position 2 to position 0, but its value gets mixed up with thereorder parameter's value.

Root Cause

The issue was inCreateWorkspacePageViewExperimental.tsx where parameters were rendered using array indices instead of parameter names:

// Problematic codeconstparameterField=`rich_parameter_values.${index}`;constformValue=form.values?.rich_parameter_values?.[index]?.value||"";

When parameters are reordered:

  1. Theparameters array order changes based on the neworder values
  2. Theform.values.rich_parameter_values array maintains the original order
  3. Array index-based lookup causes values to be mismatched

Solution

Implemented name-based lookup to ensure parameter values stay with their correct parameters:

// Find parameter value by name instead of indexconstcurrentParameterValueIndex=form.values.rich_parameter_values?.findIndex((p)=>p.name===parameter.name)??-1;// Use the found index for form field mappingconstparameterFieldIndex=currentParameterValueIndex!==-1 ?currentParameterValueIndex :index;constparameterField=`rich_parameter_values.${parameterFieldIndex}`;// Get form value by name to ensure correct mappingconstformValue=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

Impact

This fix ensures that users can reliably use dynamic parameter ordering in their templates without losing parameter values when the order changes. This is particularly important for templates that use conditional parameter visibility and ordering based on user selections.

blink-sobotand others added2 commitsJune 6, 2025 14:59
When parameters are reordered dynamically (e.g., when a parameter's orderdepends on another parameter's value), the parameter values were notdisplaying correctly. This was because the rendering logic used arrayindices instead of parameter names to map form values.The issue occurred when:1. Parameters are initially rendered in one order2. A parameter value changes, causing dynamic reordering3. The parameter array order changes but form values array stays the same4. Values get mismatched due to index-based lookupThis fix implements name-based lookup to ensure parameter values persistcorrectly 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 parametersFixes parameter value persistence in dynamic parameter ordering scenarios.
@jaaydenhjaaydenh self-assigned thisJun 6, 2025
@jaaydenhjaaydenh requested a review fromEmyrkJune 6, 2025 15:54
Comment on lines +611 to +619
const currentParameterValueIndex =
form.values.rich_parameter_values?.findIndex(
(p) => p.name === parameter.name,
) ?? -1;
const parameterFieldIndex =
currentParameterValueIndex !== -1
? currentParameterValueIndex
: index;
const parameterField = `rich_parameter_values.${parameterFieldIndex}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@jaaydenh The overall approach looks correct to me. There might be some cleaner simplier syntax

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@EmyrkEmyrkEmyrk approved these changes

Assignees

@jaaydenhjaaydenh

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@jaaydenh

[8]ページ先頭

©2009-2025 Movatter.jp