Browse Source

Merge pull request #14430 from ArtemDzhereleiko/AD/bug-fix/cf-alarm-rule-validation

Fixed Alarm Rule validation
pull/14442/head
Vladyslav Prykhodko 10 months ago
committed by GitHub
parent
commit
597b0a8c71
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 16
      ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.ts
  2. 2
      ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts
  3. 10
      ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule-condition.component.ts
  4. 23
      ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts
  5. 6
      ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.ts

16
ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.ts

@ -67,7 +67,7 @@ export class AlarmRuleDialogComponent extends DialogComponent<AlarmRuleDialogCom
debugSettings: [], debugSettings: [],
entityId: this.fb.group({ entityId: this.fb.group({
entityType: this.fb.control<EntityType | AliasEntityType | null>(null, Validators.required), entityType: this.fb.control<EntityType | AliasEntityType | null>(null, Validators.required),
id: ['', Validators.required], id: [null as null | string, Validators.required],
}), }),
configuration: this.fb.group({ configuration: this.fb.group({
arguments: this.fb.control({}), arguments: this.fb.control({}),
@ -101,7 +101,6 @@ export class AlarmRuleDialogComponent extends DialogComponent<AlarmRuleDialogCom
private destroyRef: DestroyRef, private destroyRef: DestroyRef,
private fb: FormBuilder) { private fb: FormBuilder) {
super(store, router, dialogRef); super(store, router, dialogRef);
this.observeIsLoading();
this.applyDialogData(); this.applyDialogData();
} }
@ -178,19 +177,6 @@ export class AlarmRuleDialogComponent extends DialogComponent<AlarmRuleDialogCom
this.fieldFormGroup.patchValue({ configuration, type, debugSettings, entityId, ...value }, {emitEvent: false}); this.fieldFormGroup.patchValue({ configuration, type, debugSettings, entityId, ...value }, {emitEvent: false});
} }
private observeIsLoading(): void {
this.isLoading$.pipe(takeUntilDestroyed()).subscribe(loading => {
if (loading) {
this.fieldFormGroup.disable({emitEvent: false});
} else {
this.fieldFormGroup.enable({emitEvent: false});
if (this.data.isDirty) {
this.fieldFormGroup.markAsDirty();
}
}
});
}
onTestScript(expression: string): Observable<string> { onTestScript(expression: string): Observable<string> {
const calculatedFieldId = this.data.value?.id?.id; const calculatedFieldId = this.data.value?.id?.id;
if (calculatedFieldId) { if (calculatedFieldId) {

2
ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts

@ -152,7 +152,7 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
this.cellActionDescriptors.push( this.cellActionDescriptors.push(
{ {
name: this.translate.instant('notification.copy-template'), name: this.translate.instant('alarm-rule.copy'),
icon: 'content_copy', icon: 'content_copy',
isEnabled: () => true, isEnabled: () => true,
onAction: ($event, entity) => this.copyCalculatedField(entity) onAction: ($event, entity) => this.copyCalculatedField(entity)

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

@ -20,7 +20,7 @@ import {
FormBuilder, FormBuilder,
NG_VALIDATORS, NG_VALIDATORS,
NG_VALUE_ACCESSOR, NG_VALUE_ACCESSOR,
UntypedFormControl, ValidationErrors,
Validator Validator
} from '@angular/forms'; } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
@ -130,10 +130,10 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
} }
public conditionSet() { public conditionSet() {
return this.modelValue && (this.modelValue.expression?.expression || this.modelValue.expression?.filters) || !this.required; return this.modelValue && (this.modelValue.expression?.expression || this.modelValue.expression?.filters);
} }
public validate(c: UntypedFormControl) { public validate(): ValidationErrors | null {
return this.conditionSet() ? null : { return this.conditionSet() ? null : {
alarmRuleCondition: { alarmRuleCondition: {
valid: false, valid: false,
@ -166,11 +166,11 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
private updateConditionInfo() { private updateConditionInfo() {
this.alarmRuleConditionFormGroup.patchValue( this.alarmRuleConditionFormGroup.patchValue(
{ this.modelValue ? {
type: this.modelValue?.type, type: this.modelValue?.type,
expression: this.modelValue?.expression, expression: this.modelValue?.expression,
schedule: this.modelValue?.schedule, schedule: this.modelValue?.schedule,
}, {emitEvent: false} } : null, {emitEvent: false}
); );
this.updateScheduleText(); this.updateScheduleText();
this.updateSpecText(); this.updateSpecText();

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

@ -20,8 +20,9 @@ import {
FormBuilder, FormBuilder,
NG_VALIDATORS, NG_VALIDATORS,
NG_VALUE_ACCESSOR, NG_VALUE_ACCESSOR,
UntypedFormControl, ValidationErrors,
Validator Validator,
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 } from '@core/utils';
@ -76,7 +77,7 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
private modelValue: AlarmRule; private modelValue: AlarmRule;
alarmRuleFormGroup = this.fb.group({ alarmRuleFormGroup = this.fb.group({
condition: this.fb.control<AlarmRuleCondition | null>(null), condition: this.fb.control<AlarmRuleCondition | null>(null, Validators.required),
alarmDetails: [null], alarmDetails: [null],
dashboardId: [null] dashboardId: [null]
}); });
@ -113,14 +114,12 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
} }
writeValue(value: AlarmRule): void { writeValue(value: AlarmRule): void {
if (value) { this.modelValue = value;
this.modelValue = value; const model = this.modelValue ? {
const model = this.modelValue ? { ...this.modelValue,
...this.modelValue, dashboardId: this.modelValue.dashboardId?.id
dashboardId: this.modelValue.dashboardId?.id } : null;
} : null; this.alarmRuleFormGroup.patchValue(model, {emitEvent: false});
this.alarmRuleFormGroup.patchValue(model, {emitEvent: false});
}
} }
public openEditDetailsDialog($event: Event) { public openEditDetailsDialog($event: Event) {
@ -142,7 +141,7 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
}); });
} }
public validate(c: UntypedFormControl) { public validate(): ValidationErrors | null {
return (!this.required && !this.modelValue || this.alarmRuleFormGroup.valid) ? null : { return (!this.required && !this.modelValue || this.alarmRuleFormGroup.valid) ? null : {
alarmRule: { alarmRule: {
valid: false, valid: false,

6
ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.ts

@ -23,7 +23,7 @@ import {
NG_VALIDATORS, NG_VALIDATORS,
NG_VALUE_ACCESSOR, NG_VALUE_ACCESSOR,
UntypedFormArray, UntypedFormArray,
UntypedFormControl, ValidationErrors,
Validator, Validator,
Validators Validators
} from '@angular/forms'; } from '@angular/forms';
@ -159,8 +159,8 @@ export class CreateCfAlarmRulesComponent implements ControlValueAccessor, Valida
return null; return null;
} }
public validate(c: UntypedFormControl) { public validate(): ValidationErrors | null {
return this.createAlarmRulesFormArray().length ? null : { return this.createAlarmRulesFormGroup.valid && this.createAlarmRulesFormArray().length > 0 ? null : {
createAlarmRules: { createAlarmRules: {
valid: false, valid: false,
}, },

Loading…
Cancel
Save