diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/components/test-arguments/calculated-field-test-arguments.component.ts b/ui-ngx/src/app/modules/home/components/calculated-fields/components/test-arguments/calculated-field-test-arguments.component.ts index 11246e004f..e3ab3b560c 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/components/test-arguments/calculated-field-test-arguments.component.ts +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/components/test-arguments/calculated-field-test-arguments.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { Component, forwardRef } from '@angular/core'; +import { AfterViewInit, Component, forwardRef } from '@angular/core'; import { ControlValueAccessor, NG_VALIDATORS, @@ -60,7 +60,7 @@ import { MatDialog } from '@angular/material/dialog'; } ] }) -export class CalculatedFieldTestArgumentsComponent extends PageComponent implements ControlValueAccessor, Validator { +export class CalculatedFieldTestArgumentsComponent extends PageComponent implements ControlValueAccessor, Validator, AfterViewInit { argumentsFormArray = this.fb.array([]); @@ -78,6 +78,10 @@ export class CalculatedFieldTestArgumentsComponent extends PageComponent impleme .subscribe(() => this.propagateChange(this.getValue())); } + ngAfterViewInit(): void { + this.argumentsFormArray.updateValueAndValidity(); + } + registerOnChange(propagateChange: (value: CalculatedFieldEventArguments) => void): void { this.propagateChange = propagateChange; } @@ -91,8 +95,8 @@ export class CalculatedFieldTestArgumentsComponent extends PageComponent impleme const value = { ...argumentsObj[key], argumentName: key } as CalculatedFieldArgumentEventValue; this.argumentsFormArray.push((value).type === ArgumentType.Rolling ? this.getRollingArgumentFormGroup(value as CalculatedFieldRollingTelemetryArgumentValue) - : this.getSimpleArgumentFormGroup(value as CalculatedFieldSingleArgumentValue), - {emitEvent: false}); + : this.getSimpleArgumentFormGroup(value as CalculatedFieldSingleArgumentValue) + ); }); } @@ -100,24 +104,6 @@ export class CalculatedFieldTestArgumentsComponent extends PageComponent impleme return this.argumentsFormArray.valid ? null : { arguments: { valid: false } }; } - private getSimpleArgumentFormGroup({ argumentName, type, ts, value }: CalculatedFieldSingleArgumentValue): FormGroup { - return this.fb.group({ - argumentName: [{ value: argumentName, disabled: true}], - type: [{ value: type , disabled: true }], - ts: [ts], - value: [value] - }) as FormGroup; - } - - private getRollingArgumentFormGroup({ argumentName, type, timewindow, values }: CalculatedFieldRollingTelemetryArgumentValue): FormGroup { - return this.fb.group({ - ...timewindow ?? {}, - argumentName: [{ value: argumentName, disabled: true }], - type: [{ value: type , disabled: true }], - values: [values] - }) as FormGroup; - } - openEditJSONDialog(group: FormGroup): void { this.dialog.open(JsonObjectEditDialogComponent, { disableClose: true, @@ -136,10 +122,28 @@ export class CalculatedFieldTestArgumentsComponent extends PageComponent impleme : group.patchValue({ ts: (result as CalculatedFieldSingleArgumentValue).ts, value: (result as CalculatedFieldSingleArgumentValue).value }) ); } + private getSimpleArgumentFormGroup({ argumentName, type, ts, value }: CalculatedFieldSingleArgumentValue): FormGroup { + return this.fb.group({ + argumentName: [{ value: argumentName, disabled: true}], + type: [{ value: type , disabled: true }], + ts: [ts], + value: [value] + }) as FormGroup; + } + + private getRollingArgumentFormGroup({ argumentName, type, timewindow, values }: CalculatedFieldRollingTelemetryArgumentValue): FormGroup { + return this.fb.group({ + ...timewindow ?? {}, + argumentName: [{ value: argumentName, disabled: true }], + type: [{ value: type , disabled: true }], + values: [values] + }) as FormGroup; + } + private getValue(): CalculatedFieldEventArguments { return this.argumentsFormArray.getRawValue().reduce((acc, rowItem) => { const { argumentName, type, ...value } = rowItem; - acc[argumentName] = { ...value }; + acc[argumentName] = value; return acc; }, {}); } diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/components/test-dialog/calculated-field-script-test-dialog.component.ts b/ui-ngx/src/app/modules/home/components/calculated-fields/components/test-dialog/calculated-field-script-test-dialog.component.ts index 83e3625219..ea0164f9b8 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/components/test-dialog/calculated-field-script-test-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/components/test-dialog/calculated-field-script-test-dialog.component.ts @@ -81,7 +81,7 @@ export class CalculatedFieldScriptTestDialogComponent extends DialogComponent this.calculatedFieldScriptTestFormGroup.get('expression').patchValue(res, {emitEvent: false}) ); - this.calculatedFieldScriptTestFormGroup.get('arguments').patchValue(this.data.arguments, {emitEvent: false}); + this.calculatedFieldScriptTestFormGroup.get('arguments').patchValue(this.data.arguments); } ngAfterViewInit(): void { diff --git a/ui-ngx/src/app/shared/models/calculated-field.models.ts b/ui-ngx/src/app/shared/models/calculated-field.models.ts index 5bcc0a4a2a..6c816cbb9b 100644 --- a/ui-ngx/src/app/shared/models/calculated-field.models.ts +++ b/ui-ngx/src/app/shared/models/calculated-field.models.ts @@ -149,7 +149,7 @@ export interface CalculatedFieldDebugDialogData { } export interface CalculatedFieldTestScriptInputParams { - arguments: Record, + arguments: CalculatedFieldEventArguments, expression: string; }