Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[pull] main from coder:main #74

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

[pull] main from coder:main #74

merged 2 commits into from
Jun 9, 2025

Conversation

pull[bot]
Copy link

@pull pull bot commented Jun 9, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? πŸ’– Please sponsor : )

blink-so bot and others added 2 commits June 9, 2025 16:42
## 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's `order` value depends on another
parameter's value.

**Example scenario:**
```terraform
data "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 mixed
up with the `reorder` parameter's value.

## Root Cause

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

```typescript
// Problematic code
const 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` values
2. The `form.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:

```typescript
// Find parameter value by name instead of index
const currentParameterValueIndex = form.values.rich_parameter_values?.findIndex(
  (p) => p.name === parameter.name
) ?? -1;

// Use the found index for form field mapping
const parameterFieldIndex = currentParameterValueIndex !== -1 ? currentParameterValueIndex : index;
const parameterField = `rich_parameter_values.${parameterFieldIndex}`;

// Get form value by name to ensure correct mapping
const 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

## 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.

---------

Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com>
Co-authored-by: Jaayden Halko <[email protected]>
fixes #16987

Fix implemented through the coder tasks UI using Coder with Claude Code.

Prompt:
fix this issue, #16987
@pull pull bot merged commit 44fff54 into jango-blockchained:main Jun 9, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jun 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant