Browse Source

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.
pull/16148/head
dshvaika 1 month ago
parent
commit
12e17f7c41
  1. 4
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts
  2. 7
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html
  3. 13
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts

4
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();

7
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html

@ -72,6 +72,13 @@
<mat-option [disabled]="true" class="tb-search-popup-loading">
<mat-spinner diameter="24"></mat-spinner>
</mat-option>
} @else if (searchFailed) {
<mat-option [disabled]="true" class="tb-search-popup-no-results">
<div class="tb-search-popup-no-results-content">
<mat-icon>cloud_off</mat-icon>
<span>{{ 'iot-hub.network-server-unavailable' | translate }}</span>
</div>
</mat-option>
} @else if (searchResults.length === 0 && searchLoaded) {
<mat-option [disabled]="true" class="tb-search-popup-no-results">
<div class="tb-search-popup-no-results-content">

13
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<string>();
@ -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<MpItemVersionView>))
catchError(() => of(null as PageData<MpItemVersionView>))
);
})
).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;
});

Loading…
Cancel
Save