From b79d3286e47cb60647d6ff8a240370e268ab8872 Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Fri, 3 Jul 2026 13:14:35 +0200 Subject: [PATCH] Fixed dashboardId being corrupted and dirty-check bypassed in alarm rule form --- .../alarm-rules/cf-alarm-rule.component.ts | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts index ca1e58f774..f1e7367002 100644 --- a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts +++ b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts @@ -76,12 +76,11 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid testScript: (expression: string) => Observable; private modelValue: AlarmRule; - private propagatedValue: AlarmRule; alarmRuleFormGroup = this.fb.group({ condition: this.fb.control(null, Validators.required), - alarmDetails: [null], - dashboardId: [null] + alarmDetails: this.fb.control(null), + dashboardId: this.fb.control(null) }); private propagateChange = (v: any) => { }; @@ -106,8 +105,8 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid ngOnInit() { this.alarmRuleFormGroup.valueChanges.pipe( takeUntilDestroyed(this.destroyRef) - ).subscribe(() => { - this.updateModel(); + ).subscribe((value) => { + this.updateModel(value); }); this.alarmRuleFormGroup.statusChanges.pipe( takeUntilDestroyed(this.destroyRef) @@ -126,13 +125,12 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid } writeValue(value: AlarmRule): void { - this.modelValue = value; - const model = this.modelValue ? { - ...this.modelValue, - dashboardId: this.modelValue.dashboardId?.id + const model = value ? { + ...value, + dashboardId: value.dashboardId?.id } : null; this.alarmRuleFormGroup.patchValue(model, {emitEvent: false}); - this.propagatedValue = this.toModel(this.alarmRuleFormGroup.value); + this.modelValue = model ? this.toModel(model) : null; } public openEditDetailsDialog($event: Event) { @@ -162,17 +160,16 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid }; } - private updateModel() { - const modelValue = this.toModel(this.alarmRuleFormGroup.value); - if (isEqual(modelValue, this.propagatedValue)) { + private updateModel(value: typeof this.alarmRuleFormGroup.value): void { + const modelValue = this.toModel(value); + if (isEqual(modelValue, this.modelValue)) { return; } this.modelValue = modelValue; - this.propagatedValue = modelValue; this.propagateChange(modelValue); } - private toModel(value: any): AlarmRule { + private toModel(value: typeof this.alarmRuleFormGroup.value): AlarmRule { return {...value, dashboardId: value.dashboardId ? new DashboardId(value.dashboardId) : null} as AlarmRule; } }