From 3710071ee2fc11c340ab59aad91803df52386dba Mon Sep 17 00:00:00 2001 From: dshvaika Date: Wed, 30 Sep 2026 10:30:07 +0300 Subject: [PATCH] fix(iot-hub): keep an explicit sort choice on the widget picker's Installed list From the #16148 re-review: - onIotHubSortChange compared the picked option with the effective sort, so picking "Most installed" while it was already shown as the Installed list's fallback for relevance stored nothing, and the IoT Hub list reopened on "Most relevant". The choice is now always stored; the list reloads only when the effective sort changes. - INSTALLED_SORT_OPTIONS moves below the imports. - The search page's load pipeline carries a failure as null and applies the result in applyResult() instead of an inline block with a { result } wrapper. - filterByLabel trims the search itself, so the facet list and the type pages treat a trailing space alike. - isCompactItemType() now also backs TbIotHubBrowseComponent.isCompactType and the detail dialog's isCompactLayout; the home component's pass-through becomes a readonly alias. --- .../dashboard-widget-select.component.ts | 12 ++++--- .../iot-hub/iot-hub-browse.component.ts | 5 ++- .../iot-hub/iot-hub-facet-list.component.ts | 2 +- .../iot-hub-item-detail-dialog.component.ts | 6 ++-- .../iot-hub/iot-hub-search.component.ts | 32 ++++++++++--------- .../home/components/iot-hub/iot-hub-utils.ts | 2 +- .../pages/iot-hub/iot-hub-home.component.ts | 6 +--- 7 files changed, 32 insertions(+), 33 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts index 7132063ed2..34c36113d0 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts @@ -30,8 +30,6 @@ import { WidgetCategory } from '@shared/models/iot-hub/iot-hub-item.models'; -/** The Installed list is sorted locally, and only the Hub can rank by relevance. */ -const INSTALLED_SORT_OPTIONS = IOT_HUB_SORT_OPTIONS.filter(o => o.value !== RELEVANCE_SORT_PROPERTY); import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; @@ -44,6 +42,9 @@ import { } from '@home/components/iot-hub/iot-hub-utils'; import { IotHubBuiltInService } from '@home/components/iot-hub/iot-hub-built-in.service'; +/** The Installed list is sorted locally, and only the Hub can rank by relevance. */ +const INSTALLED_SORT_OPTIONS = IOT_HUB_SORT_OPTIONS.filter(o => o.value !== RELEVANCE_SORT_PROPERTY); + type selectWidgetMode = 'installed' | 'iotHub'; type installedSubMode = 'default' | 'allWidgets'; type iotHubSubMode = 'default' | 'allWidgets' | 'installed' | 'category'; @@ -580,8 +581,11 @@ export class DashboardWidgetSelectComponent { } onIotHubSortChange(option: SortOption): void { - if (this.iotHubSelectedSort.value !== option.value) { - this.iotHubSelectedSortValue = option.value; + // Store the choice even when it is already the effective sort (the Installed list's fallback + // for relevance), so it survives a switch back to the IoT Hub list; reload only on a change. + const effective = this.iotHubSelectedSort.value; + this.iotHubSelectedSortValue = option.value; + if (effective !== option.value) { this.installedWidgetVersions = null; this.reloadIotHubWidgets(); } diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts index 40276cd769..dc856783cd 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts @@ -11,6 +11,7 @@ import { CREATOR_VISIBLE_ITEM_TYPES, FilterParamInfo, IOT_HUB_SORT_OPTIONS, + isCompactItemType, ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; import { widgetTypeTranslations, cfTypeTranslations, ruleChainTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models'; @@ -80,9 +81,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy } get isCompactType(): boolean { - return this._activeType === ItemType.CALCULATED_FIELD - || this._activeType === ItemType.ALARM_RULE - || this._activeType === ItemType.RULE_CHAIN; + return isCompactItemType(this._activeType); } get searchPlaceholderKey(): string { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts index 439ffc548f..fb62675145 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts @@ -54,7 +54,7 @@ export class TbIotHubFacetListComponent implements OnChanges { } private applySearch(): void { - this.visibleOptions = filterByLabel(this.options, this.search.trim(), this.labelFor); + this.visibleOptions = filterByLabel(this.options, this.search, this.labelFor); this.scrollable = this.visibleOptions.length > IOT_HUB_FILTER_SCROLL_THRESHOLD; } } diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts index d1c6f4f194..982bba0d3b 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts @@ -7,7 +7,7 @@ import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { DialogComponent } from '@shared/components/dialog.component'; import { MpItemVersionView, cfTypeTranslations, cfTypeIcons, ruleChainTypeTranslations, widgetTypeTranslations, NodeInfo } from '@shared/models/iot-hub/iot-hub-version.models'; -import { getItemTypeIcon, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; +import { getItemTypeIcon, isCompactItemType, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; import { getInstalledItemUrl, IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { TranslateService } from '@ngx-translate/core'; @@ -87,9 +87,7 @@ export class TbIotHubItemDetailDialogComponent extends DialogComponent this.fetchResults(this.searchText || '').pipe( - map(result => ({ result })), - catchError(() => of({ result: null as PageData | null })) + catchError(() => of(null)) )) - ).subscribe(({ result }) => { - this.isLoading = false; - if (result) { - this.totalElements = result.totalElements; - this.results = result.data; - this.hasError = false; - } else { - this.hasError = true; - this.results = []; - this.totalElements = 0; - } - }); + ).subscribe(result => this.applyResult(result)); this.searchSubscription = this.searchSubject.pipe( debounceTime(300), distinctUntilChanged() @@ -405,6 +393,20 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { this.loadSubject.next(); } + /** A null result is a failed request. */ + private applyResult(result: PageData | null): void { + this.isLoading = false; + if (result) { + this.totalElements = result.totalElements; + this.results = result.data; + this.hasError = false; + } else { + this.hasError = true; + this.results = []; + this.totalElements = 0; + } + } + private fetchResults(text: string) { const sort = this.sortOptions[this.selectedSortIndex]; const sortOrder: SortOrder = { property: sort.value, direction: sort.direction }; diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts index 8c6d330427..27cef3aecd 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts @@ -65,7 +65,7 @@ export interface IotHubFilterGroup { } export function filterByLabel(items: T[], search: string, labelOf: (item: T) => string): T[] { - const normalized = (search || '').toLowerCase(); + const normalized = (search || '').trim().toLowerCase(); if (!normalized) { return items; } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index 8f44ec2c30..1aeac4b66d 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -55,6 +55,7 @@ const SEARCH_POPUP_PAGE_SIZE = 10; export class TbIotHubHomeComponent implements OnInit, OnDestroy { readonly ItemType = ItemType; + readonly isCompactType = isCompactItemType; searchText = ''; searchResults: MpItemVersionView[] = []; @@ -267,11 +268,6 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { void this.router.navigate(['/iot-hub/search'], { queryParams: { search } }); } - isCompactType(type: ItemType): boolean { - return isCompactItemType(type); - } - - getCompactIcon(item: MpItemVersionView): string { return item.icon || getItemTypeIcon(item.type); }