Commit 82f44971c87229f1fc3234d9651651a02858daeb

Authored by Vladyslav_Prykhodko
1 parent 75817a16

UI: Added protection for invalid device profile alarm condition data

... ... @@ -26,9 +26,8 @@ import {
26 26 Validators
27 27 } from '@angular/forms';
28 28 import { MatDialog } from '@angular/material/dialog';
29   -import { deepClone, isUndefined } from '@core/utils';
  29 +import { deepClone, isDefinedAndNotNull } from '@core/utils';
30 30 import { TranslateService } from '@ngx-translate/core';
31   -import { DatePipe } from '@angular/common';
32 31 import { AlarmCondition, AlarmConditionType } from '@shared/models/device.models';
33 32 import {
34 33 AlarmRuleConditionDialogComponent,
... ... @@ -73,8 +72,7 @@ export class AlarmRuleConditionComponent implements ControlValueAccessor, OnInit
73 72
74 73 constructor(private dialog: MatDialog,
75 74 private fb: FormBuilder,
76   - private translate: TranslateService,
77   - private datePipe: DatePipe) {
  75 + private translate: TranslateService) {
78 76 }
79 77
80 78 registerOnChange(fn: any): void {
... ... @@ -102,7 +100,7 @@ export class AlarmRuleConditionComponent implements ControlValueAccessor, OnInit
102 100
103 101 writeValue(value: AlarmCondition): void {
104 102 this.modelValue = value;
105   - if (this.modelValue !== null && isUndefined(this.modelValue?.spec)) {
  103 + if (this.modelValue !== null && !isDefinedAndNotNull(this.modelValue?.spec?.predicate)) {
106 104 this.modelValue = Object.assign(this.modelValue, {spec: {type: AlarmConditionType.SIMPLE}});
107 105 }
108 106 this.updateConditionInfo();
... ...