Browse Source

Fixed dashboardId being corrupted and dirty-check bypassed in alarm rule form

pull/15868/head
Maksym Tsymbarov 4 weeks ago
parent
commit
b79d3286e4
  1. 27
      ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts

27
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<string>;
private modelValue: AlarmRule;
private propagatedValue: AlarmRule;
alarmRuleFormGroup = this.fb.group({
condition: this.fb.control<AlarmRuleCondition | null>(null, Validators.required),
alarmDetails: [null],
dashboardId: [null]
alarmDetails: this.fb.control<string | null>(null),
dashboardId: this.fb.control<string | null>(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;
}
}

Loading…
Cancel
Save