@cqa-lib/cqa-ui 1.1.395 → 1.1.396

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31329,20 +31329,23 @@ class TemplateVariablesFormComponent {
31329
31329
  this.cdr.markForCheck();
31330
31330
  }
31331
31331
  }
31332
- // If parameter options changed and we have default values, try to initialize them.
31333
- // IMPORTANT: only do this on the FIRST time parameterOptions arrive, otherwise every
31334
- // search (which also updates parameterOptions) would re-run initializeTestDataVariables()
31335
- // and reset the test-data type dropdown back to 'plain-text'.
31332
+ // Re-run initializeTestDataVariables whenever parameterOptions changes and there are still
31333
+ // variables that need initialization (have profileId but missing profile name or dataSet).
31334
+ // We do NOT use firstChange here because the saved profile may arrive in a second API call
31335
+ // (id@<profileId>) after the initial paginated list, so firstChange would miss it.
31336
+ // The inner some() guard ensures we only re-run when variables are still incomplete,
31337
+ // preventing unnecessary re-runs on user search updates.
31336
31338
  if (changes['parameterOptions'] &&
31337
- changes['parameterOptions'].firstChange &&
31338
31339
  this.parameterOptions.length > 0 &&
31339
- ((this.defaultTestDataProfileId && this.defaultTestDataStartIndex != null) ||
31340
- // Check if any variable has selectedTestDataProfileId but is missing selectedTestDataProfile or selectedDataSet
31341
- // This happens when loading a saved step - setTemplateVariables sets the ID, but we need parameterOptions to set the name and data set
31342
- this.templateVariables?.some(v => this.needsDataTypeDropdown(v) &&
31343
- v.dataType === 'parameter' &&
31344
- v.selectedTestDataProfileId != null &&
31345
- (!v.selectedTestDataProfile || !v.selectedDataSet)) ||
31340
+ (
31341
+ // Check if any variable has selectedTestDataProfileId but is missing selectedTestDataProfile or selectedDataSet
31342
+ // This happens when loading a saved step - setTemplateVariables sets the ID, but we need parameterOptions to set the name and data set
31343
+ this.templateVariables?.some(v => this.needsDataTypeDropdown(v) &&
31344
+ v.dataType === 'parameter' &&
31345
+ v.selectedTestDataProfileId != null &&
31346
+ (!v.selectedTestDataProfile || !v.selectedDataSet)) ||
31347
+ (this.defaultTestDataProfileId && this.defaultTestDataStartIndex != null &&
31348
+ this.templateVariables?.some(v => this.needsDataTypeDropdown(v) && v.dataType === 'parameter' && !v.selectedTestDataProfile)) ||
31346
31349
  // The extra uninitialized-variable check below is debug-only: only run it in debug mode
31347
31350
  // to avoid double-initialising variables in non-debug step-builder flows.
31348
31351
  (this.isDebug && this.templateVariables?.some(v => this.needsDataTypeDropdown(v) && v.dataType === 'parameter' && !v.selectedTestDataProfile)))) {
@@ -31555,14 +31558,22 @@ class TemplateVariablesFormComponent {
31555
31558
  // For environment type, parse the value to extract environment and parameter
31556
31559
  if (dataType === 'environment') {
31557
31560
  // Environment values are in format *|parameterName|
31558
- // We need to find which environment this parameter belongs to
31559
31561
  const paramName = rawValue;
31560
31562
  if (paramName) {
31561
- // Find the environment that contains this parameter
31562
- const envOption = this.environmentOptions.find(env => env.name === paramName);
31563
+ // If we have a saved environmentId, use it for an exact match (env-{id}-{param})
31564
+ // to avoid selecting the wrong environment when multiple environments share param names.
31565
+ let envOption;
31566
+ if (variable.selectedEnvironmentId != null) {
31567
+ const exactId = `env-${variable.selectedEnvironmentId}-${paramName}`;
31568
+ envOption = this.environmentOptions.find(env => env.id === exactId);
31569
+ }
31570
+ // Fallback: match by param name only (legacy / first-time save)
31571
+ if (!envOption) {
31572
+ envOption = this.environmentOptions.find(env => env.name === paramName);
31573
+ }
31563
31574
  if (envOption) {
31564
31575
  variable.selectedEnvironment = envOption.environment;
31565
- // Extract and store environment ID
31576
+ // Extract and store environment ID from the option id
31566
31577
  const idMatch = envOption.id.match(/env-(\d+)-/);
31567
31578
  if (idMatch && idMatch[1]) {
31568
31579
  variable.selectedEnvironmentId = parseInt(idMatch[1], 10);