From 76c39b6d0b2824aa66bf2bc10df8a066a5333e25 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Fri, 6 Dec 2024 12:14:06 +0200 Subject: [PATCH 1/4] UI: Fixed error toast when editing device detais --- .../ota-package/ota-package-autocomplete.component.ts | 5 +++-- 1 file changed, 3 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 04511fad38..d3570150e8 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,10 +31,11 @@ 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, isDefinedAndNotNull } from '@core/utils'; import { AuthUser } from '@shared/models/user.model'; import { getCurrentAuthUser } from '@core/auth/auth.selectors'; import { Authority } from '@shared/models/authority.enum'; +import { NULL_UUID } from '@shared/models/id/has-uuid'; @Component({ selector: 'tb-ota-package-autocomplete', @@ -76,7 +77,7 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On if (this.deviceProfile) { this.reset(); } - this.deviceProfile = value; + this.deviceProfile = value ? value :NULL_UUID; } } From 3a97faeb17447d2ac149ba607e8dd41b7babb119 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Fri, 6 Dec 2024 12:21:29 +0200 Subject: [PATCH 2/4] UI: Refactoring --- .../ota-package/ota-package-autocomplete.component.ts | 4 ++-- 1 file changed, 2 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 d3570150e8..4a117d74b9 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, isDefinedAndNotNull } 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'; @@ -77,7 +77,7 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On if (this.deviceProfile) { this.reset(); } - this.deviceProfile = value ? value :NULL_UUID; + this.deviceProfile = value ? value : NULL_UUID; } } From b906f424424f90a3ca53debeb3b84e93c70b0035 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Mon, 9 Dec 2024 10:17:25 +0200 Subject: [PATCH 3/4] UI: Refactoring --- .../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 4a117d74b9..89b728916f 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 @@ -77,7 +77,7 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On if (this.deviceProfile) { this.reset(); } - this.deviceProfile = value ? value : NULL_UUID; + this.deviceProfile = value ?? NULL_UUID; } } From 9c659a7029925e7b46e11874279f0957c14e29ed Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Tue, 10 Dec 2024 11:51:16 +0200 Subject: [PATCH 4/4] UI: Refactoring --- .../ota-package-autocomplete.component.ts | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 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 89b728916f..79fbd36d73 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,11 +31,10 @@ 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, isDefinedAndNotNull } from '@core/utils'; import { AuthUser } from '@shared/models/user.model'; import { getCurrentAuthUser } from '@core/auth/auth.selectors'; import { Authority } from '@shared/models/authority.enum'; -import { NULL_UUID } from '@shared/models/id/has-uuid'; @Component({ selector: 'tb-ota-package-autocomplete', @@ -65,19 +64,19 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On this.reset(); } - private deviceProfile: string; + private deviceProfileIdValue: string; get deviceProfileId(): string { - return this.deviceProfile; + return this.deviceProfileIdValue; } @Input() set deviceProfileId(value: string) { - if (this.deviceProfile !== value) { - if (this.deviceProfile) { + if (this.deviceProfileIdValue !== value) { + if (this.deviceProfileIdValue) { this.reset(); } - this.deviceProfile = value ?? NULL_UUID; + this.deviceProfileIdValue = value; } } @@ -258,16 +257,20 @@ export class OtaPackageAutocompleteComponent implements ControlValueAccessor, On } fetchPackages(searchText?: string): Observable> { - this.searchText = searchText; - const pageLink = new PageLink(50, 0, searchText, { - property: 'title', - direction: Direction.ASC - }); - return this.otaPackageService.getOtaPackagesInfoByDeviceProfileId(pageLink, this.deviceProfileId, this.type, - {ignoreLoading: true}).pipe( - catchError(() => of(emptyPageData())), - map((data) => data && data.data.length ? data.data : null) - ); + if (isDefinedAndNotNull(this.deviceProfileId)) { + this.searchText = searchText; + const pageLink = new PageLink(50, 0, searchText, { + property: 'title', + direction: Direction.ASC + }); + return this.otaPackageService.getOtaPackagesInfoByDeviceProfileId(pageLink, this.deviceProfileId, this.type, + {ignoreLoading: true}).pipe( + catchError(() => of(emptyPageData())), + map((data) => data && data.data.length ? data.data : null) + ); + } else { + return of([]); + } } clear() {