From d18079f81fbea7b7dd23c3bac228be543a07e8a2 Mon Sep 17 00:00:00 2001 From: rusikv Date: Tue, 12 Mar 2024 18:30:51 +0200 Subject: [PATCH 1/2] UI: fixed key filter dialog constant key type and boolean value type selected saving null if not touched, added clear of value field on value type change --- .../filter/key-filter-dialog.component.ts | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/filter/key-filter-dialog.component.ts b/ui-ngx/src/app/modules/home/components/filter/key-filter-dialog.component.ts index a29bfac750..a1557709ab 100644 --- a/ui-ngx/src/app/modules/home/components/filter/key-filter-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/filter/key-filter-dialog.component.ts @@ -35,7 +35,7 @@ import { TranslateService } from '@ngx-translate/core'; import { entityFields } from '@shared/models/entity.models'; import { Observable, of, Subject } from 'rxjs'; import { filter, map, mergeMap, publishReplay, refCount, startWith, takeUntil } from 'rxjs/operators'; -import { isDefined } from '@core/utils'; +import { isBoolean, isDefined } from '@core/utils'; import { EntityId } from '@shared/models/id/entity-id'; import { DeviceProfileService } from '@core/http/device-profile.service'; @@ -121,22 +121,30 @@ export class KeyFilterDialogComponent extends this.keyFilterFormGroup.get('valueType').valueChanges.pipe( takeUntil(this.destroy$) ).subscribe((valueType: EntityKeyValueType) => { - const prevValue: EntityKeyValueType = this.keyFilterFormGroup.value.valueType; + const prevValueType: EntityKeyValueType = this.keyFilterFormGroup.value.valueType; const predicates: KeyFilterPredicate[] = this.keyFilterFormGroup.get('predicates').value; - if (prevValue && prevValue !== valueType && predicates && predicates.length) { - this.dialogs.confirm(this.translate.instant('filter.key-value-type-change-title'), - this.translate.instant('filter.key-value-type-change-message')).subscribe( - (result) => { - if (result) { - this.keyFilterFormGroup.get('predicates').setValue([]); - } else { - this.keyFilterFormGroup.get('valueType').setValue(prevValue, {emitEvent: false}); + const value = this.keyFilterFormGroup.get('value')?.value; + if (prevValueType && prevValueType !== valueType) { + if (this.isConstantKeyType && this.data.telemetryKeysOnly) { + this.keyFilterFormGroup.get('value').setValue(null); + } + if (predicates && predicates.length) { + this.dialogs.confirm(this.translate.instant('filter.key-value-type-change-title'), + this.translate.instant('filter.key-value-type-change-message')).subscribe( + (result) => { + if (result) { + this.keyFilterFormGroup.get('predicates').setValue([]); + } else { + this.keyFilterFormGroup.get('valueType').setValue(prevValueType, {emitEvent: false}); + this.keyFilterFormGroup.get('value')?.setValue(value, {emitEvent: false}); + } } - } - ); + ); + } } - if (valueType === EntityKeyValueType.BOOLEAN && this.isConstantKeyType) { + if (valueType === EntityKeyValueType.BOOLEAN && this.isConstantKeyType && this.data.telemetryKeysOnly) { this.keyFilterFormGroup.get('value').clearValidators(); + this.keyFilterFormGroup.get('value').setValue(isBoolean(value) ? value : false); this.keyFilterFormGroup.get('value').updateValueAndValidity(); } }); From 0dc805ab3feca444fac6f78a487603915ac41e9c Mon Sep 17 00:00:00 2001 From: rusikv Date: Fri, 15 Mar 2024 18:14:31 +0800 Subject: [PATCH 2/2] UI: optimize condition check for key filter dialog --- .../home/components/filter/key-filter-dialog.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/modules/home/components/filter/key-filter-dialog.component.ts b/ui-ngx/src/app/modules/home/components/filter/key-filter-dialog.component.ts index a1557709ab..bd0e711cab 100644 --- a/ui-ngx/src/app/modules/home/components/filter/key-filter-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/filter/key-filter-dialog.component.ts @@ -142,7 +142,7 @@ export class KeyFilterDialogComponent extends ); } } - if (valueType === EntityKeyValueType.BOOLEAN && this.isConstantKeyType && this.data.telemetryKeysOnly) { + if (this.data.telemetryKeysOnly && this.isConstantKeyType && valueType === EntityKeyValueType.BOOLEAN) { this.keyFilterFormGroup.get('value').clearValidators(); this.keyFilterFormGroup.get('value').setValue(isBoolean(value) ? value : false); this.keyFilterFormGroup.get('value').updateValueAndValidity();