Browse Source

Fixed false "Unsaved changes" popup on the Alarm rule details page when a clear condition is present

pull/15868/head
Maksym Tsymbarov 4 months ago
parent
commit
9038f3c9fd
  1. 18
      ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts

18
ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts

@ -25,7 +25,7 @@ import {
Validators Validators
} from '@angular/forms'; } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { isDefinedAndNotNull } from '@core/utils'; import { isDefinedAndNotNull, isEqual } from '@core/utils';
import { DashboardId } from '@shared/models/id/dashboard-id'; import { DashboardId } from '@shared/models/id/dashboard-id';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { AlarmRule, AlarmRuleCondition } from "@shared/models/alarm-rule.models"; import { AlarmRule, AlarmRuleCondition } from "@shared/models/alarm-rule.models";
@ -76,6 +76,7 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
testScript: (expression: string) => Observable<string>; testScript: (expression: string) => Observable<string>;
private modelValue: AlarmRule; private modelValue: AlarmRule;
private propagatedValue: AlarmRule;
alarmRuleFormGroup = this.fb.group({ alarmRuleFormGroup = this.fb.group({
condition: this.fb.control<AlarmRuleCondition | null>(null, Validators.required), condition: this.fb.control<AlarmRuleCondition | null>(null, Validators.required),
@ -131,6 +132,7 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
dashboardId: this.modelValue.dashboardId?.id dashboardId: this.modelValue.dashboardId?.id
} : null; } : null;
this.alarmRuleFormGroup.patchValue(model, {emitEvent: false}); this.alarmRuleFormGroup.patchValue(model, {emitEvent: false});
this.propagatedValue = this.toModel(this.alarmRuleFormGroup.value);
} }
public openEditDetailsDialog($event: Event) { public openEditDetailsDialog($event: Event) {
@ -161,8 +163,16 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
} }
private updateModel() { private updateModel() {
const value = this.alarmRuleFormGroup.value; const modelValue = this.toModel(this.alarmRuleFormGroup.value);
this.modelValue = {...value, dashboardId: value.dashboardId ? new DashboardId(value.dashboardId) : null} as AlarmRule; if (isEqual(modelValue, this.propagatedValue)) {
this.propagateChange(this.modelValue); return;
}
this.modelValue = modelValue;
this.propagatedValue = modelValue;
this.propagateChange(modelValue);
}
private toModel(value: any): AlarmRule {
return {...value, dashboardId: value.dashboardId ? new DashboardId(value.dashboardId) : null} as AlarmRule;
} }
} }

Loading…
Cancel
Save