From 05722968a2649e9dd7091e0228e485d732b80c22 Mon Sep 17 00:00:00 2001 From: Dmitriymush Date: Thu, 28 Dec 2023 17:50:33 +0200 Subject: [PATCH 1/4] UI: ota-package-autocomplete fixed override of formValue on new deviceProfile input value --- .../ota-package-autocomplete.component.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts b/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts index 6a19db3911..f8d89ba75f 100644 --- a/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts @@ -17,7 +17,7 @@ import { Component, ElementRef, forwardRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { merge, Observable, of, Subject } from 'rxjs'; -import { catchError, debounceTime, map, share, switchMap, tap } from 'rxjs/operators'; +import { catchError, debounceTime, map, share, switchMap, takeUntil, tap } from 'rxjs/operators'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { TranslateService } from '@ngx-translate/core'; @@ -61,7 +61,7 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On @Input() set type(value ) { this.otaUpdateType = value ? value : OtaUpdateType.FIRMWARE; - this.reset(); + this.cleanFilteredPackages.next([]); } private deviceProfile: string; @@ -73,7 +73,7 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On @Input() set deviceProfileId(value: string) { this.deviceProfile = value; - this.reset(); + this.cleanFilteredPackages.next([]); } @Input() @@ -116,6 +116,8 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On private dirty = false; private cleanFilteredPackages: Subject> = new Subject(); + private destroy$ = new Subject(); + private propagateChange = (v: any) => { }; constructor(private store: Store, @@ -158,7 +160,8 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On }), map(value => value ? (typeof value === 'string' ? value : value.title) : ''), switchMap(name => this.fetchPackages(name)), - share() + share(), + takeUntil(this.destroy$) ); this.filteredPackages = merge(this.cleanFilteredPackages, getPackages); @@ -167,6 +170,8 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On ngOnDestroy() { this.cleanFilteredPackages.complete(); this.cleanFilteredPackages = null; + this.destroy$.next(); + this.destroy$.complete(); } getCurrentEntity(): OtaPackageInfo | null { From 788d0befa01213b91f8237a18b73a62791da136d Mon Sep 17 00:00:00 2001 From: Dmitriymush Date: Tue, 2 Jan 2024 22:27:46 +0200 Subject: [PATCH 2/4] UI: override bug fix refactoring for ota-package-autocomplete --- .../ota-package/ota-package-autocomplete.component.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts b/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts index 6a19db3911..c472f1f96c 100644 --- a/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts @@ -31,7 +31,7 @@ import { OtaPackageService } from '@core/http/ota-package.service'; import { PageLink } from '@shared/models/page/page-link'; import { Direction } from '@shared/models/page/sort-order'; import { emptyPageData } from '@shared/models/page/page-data'; -import { getEntityDetailsPageURL } from '@core/utils'; +import { getEntityDetailsPageURL, isNotEmptyStr } from '@core/utils'; import { AuthUser } from '@shared/models/user.model'; import { getCurrentAuthUser } from '@core/auth/auth.selectors'; import { Authority } from '@shared/models/authority.enum'; @@ -73,7 +73,10 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On @Input() set deviceProfileId(value: string) { this.deviceProfile = value; - this.reset(); + const packageId = this.otaPackageFormGroup.get('packageId').value; + if (packageId && isNotEmptyStr(packageId)) { + this.reset(); + } } @Input() From a359d4a4b1b3fe7a3967341a72c4019e5e305f25 Mon Sep 17 00:00:00 2001 From: Dmitriymush Date: Thu, 4 Jan 2024 12:36:23 +0200 Subject: [PATCH 3/4] refactoring for ota package input --- .../ota-package/ota-package-autocomplete.component.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts b/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts index 1de427901c..20610cd6d0 100644 --- a/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts @@ -72,12 +72,11 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On @Input() set deviceProfileId(value: string) { - this.deviceProfile = value; - const packageId = this.otaPackageFormGroup.get('packageId').value; - if (packageId && isNotEmptyStr(packageId)) { - this.reset(); - } else { - this.cleanFilteredPackages.next([]); + if (this.deviceProfile !== value) { + if (this.deviceProfile) { + this.reset(); + } + this.deviceProfile = value; } } From 5cf473ec395b38b9f1af6aa666263d7289b047a9 Mon Sep 17 00:00:00 2001 From: Dmitriymush Date: Thu, 4 Jan 2024 12:50:32 +0200 Subject: [PATCH 4/4] minor edition --- .../ota-package/ota-package-autocomplete.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts b/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts index 20610cd6d0..1f74c21c34 100644 --- a/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/ota-package/ota-package-autocomplete.component.ts @@ -31,7 +31,7 @@ import { OtaPackageService } from '@core/http/ota-package.service'; import { PageLink } from '@shared/models/page/page-link'; import { Direction } from '@shared/models/page/sort-order'; import { emptyPageData } from '@shared/models/page/page-data'; -import { getEntityDetailsPageURL, isNotEmptyStr } from '@core/utils'; +import { getEntityDetailsPageURL } from '@core/utils'; import { AuthUser } from '@shared/models/user.model'; import { getCurrentAuthUser } from '@core/auth/auth.selectors'; import { Authority } from '@shared/models/authority.enum';