From 12e17f7c4166f58648ce4c2b8ecb8e31f14225ea Mon Sep 17 00:00:00 2001 From: dshvaika Date: Fri, 9 Oct 2026 13:50:46 +0300 Subject: [PATCH] fix(iot-hub): show a failed popup search as an error, and stop a repeated query hanging the spinner From the #16148 review round of 2026-10-09: - A failed popup request is carried as null and sets searchFailed, which shows a "Network or server unavailable" row instead of "No results found". - distinctUntilChanged() is gone from the popup pipeline. onSearchInput sets searchLoading on every keystroke, so a debounced value equal to the last one (type a letter and delete it within 300 ms) was dropped and the spinner never cleared; it also kept a failed query from being retried as-is. This matches thingsboard.io#706. - The search page's resize handler captures the first visible item before measureCols(), which already resets pageSize when the old size is not among the new options; the grid now stays on the page holding that item. --- .../components/iot-hub/iot-hub-search.component.ts | 4 ++-- .../home/pages/iot-hub/iot-hub-home.component.html | 7 +++++++ .../home/pages/iot-hub/iot-hub-home.component.ts | 13 +++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts index 1c70ed2370..2ce6a552c7 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts @@ -219,12 +219,12 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { } this.resizeSubscription = this.resizeSubject.pipe(debounceTime(150)).subscribe(() => { const before = this.pageSizeOptions[0]; + // Keep the same first item in view, not the same page number. + const firstItem = this.pageIndex * this.pageSize; this.measureCols(); if (this.pageSizeOptions[0] === before) { return; } - // Keep the same first item in view, not the same page number. - const firstItem = this.pageIndex * this.pageSize; this.pageSize = this.pageSizeOptions[0]; this.pageIndex = Math.floor(firstItem / this.pageSize); this.loadResults(); diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index d244bbe06a..b2b785ceae 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -72,6 +72,13 @@ + } @else if (searchFailed) { + +
+ cloud_off + {{ 'iot-hub.network-server-unavailable' | translate }} +
+
} @else if (searchResults.length === 0 && searchLoaded) {
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 1aeac4b66d..cd9c6b383f 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 @@ -6,7 +6,7 @@ import { MatAutocompleteTrigger } from '@angular/material/autocomplete'; import { MatOptionSelectionChange } from '@angular/material/core'; import { BreakpointObserver } from '@angular/cdk/layout'; import { forkJoin, of, Subject, Subscription } from 'rxjs'; -import { catchError, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; +import { catchError, debounceTime, switchMap } from 'rxjs/operators'; import { MediaBreakpoints } from '@shared/models/constants'; import { PageLink } from '@shared/models/page/page-link'; import { Direction, SortOrder } from '@shared/models/page/sort-order'; @@ -63,6 +63,7 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { searchTotal = 0; searchLoaded = false; searchLoading = false; + searchFailed = false; @ViewChild(MatAutocompleteTrigger) searchAutoTrigger: MatAutocompleteTrigger; @ViewChild('searchInput', {read: ElementRef}) searchInputRef: ElementRef; private searchSubject = new Subject(); @@ -159,7 +160,6 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { }); this.searchSubscription = this.searchSubject.pipe( debounceTime(300), - distinctUntilChanged(), switchMap(text => { this.searchLoading = true; const trimmed = text.trim(); @@ -168,14 +168,15 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { const sortOrder: SortOrder = { property: RELEVANCE_SORT_PROPERTY, direction: Direction.DESC }; const pageLink = new PageLink(SEARCH_POPUP_PAGE_SIZE, 0, trimmed || null, sortOrder); const query = new MpItemVersionQuery(pageLink, { types: CROSS_TYPE_ITEM_TYPES }); - // A failure must not end the subscription; the next keystroke replaces the empty answer. + // A failure must not end the subscription. return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true }).pipe( - catchError(() => of({ data: [], totalElements: 0 } as PageData)) + catchError(() => of(null as PageData)) ); }) ).subscribe(page => { - this.searchResults = page.data ?? []; - this.searchTotal = page.totalElements ?? 0; + this.searchFailed = !page; + this.searchResults = page?.data ?? []; + this.searchTotal = page?.totalElements ?? 0; this.searchLoaded = true; this.searchLoading = false; });