From d67da9487c7d0ff1a0b483432f23c9c2cb836ded Mon Sep 17 00:00:00 2001 From: dpinkevych Date: Tue, 17 Nov 2026 11:13:00 +0200 Subject: [PATCH] IoT Hub installed items: a failed count shows in the header with Try again, only-updates empty state, no double error toast, cleanup (PROD-9326 review) --- .../src/app/core/http/iot-hub-api.service.ts | 23 +++----- ...t-hub-installed-items-table.component.html | 2 +- ...iot-hub-installed-items-table.component.ts | 52 ++++++++----------- .../iot-hub-installed-items.component.html | 18 +++---- .../assets/locale/locale.constant-en_US.json | 3 +- 5 files changed, 42 insertions(+), 56 deletions(-) diff --git a/ui-ngx/src/app/core/http/iot-hub-api.service.ts b/ui-ngx/src/app/core/http/iot-hub-api.service.ts index b9674e232c..fe8c2800e6 100644 --- a/ui-ngx/src/app/core/http/iot-hub-api.service.ts +++ b/ui-ngx/src/app/core/http/iot-hub-api.service.ts @@ -243,11 +243,7 @@ export class IotHubApiService { public getInstalledItems(pageLink: PageLink, itemTypes?: string | string[], itemId?: string, config?: IotHubRequestConfig): Observable> { - let query = pageLink.toQuery(); - if (itemTypes) { - const types = Array.isArray(itemTypes) ? itemTypes : [itemTypes]; - types.forEach(t => query += `&itemTypes=${t}`); - } + let query = this.installedItemsQuery(pageLink, itemTypes); if (itemId) { query += `&itemId=${itemId}`; } @@ -257,18 +253,11 @@ export class IotHubApiService { ); } - /** - * The installed items with an update: publishedVersionIds is IoT Hub's published version id by item id, as Check for - * updates got it. The server keeps the items installed in another version, with the page's sort, search and types. - */ + /** publishedVersionIds: IoT Hub's published version id by item id; the items installed in another version come back. */ public getInstalledItemsWithUpdates(pageLink: PageLink, itemTypes: string[] | null, publishedVersionIds: Record, config?: IotHubRequestConfig): Observable> { - let query = pageLink.toQuery(); - if (itemTypes?.length) { - query += itemTypes.map(t => `&itemTypes=${t}`).join(''); - } return this.http.post>( - `/api/iot-hub/installedItems/withUpdates${query}`, + `/api/iot-hub/installedItems/withUpdates${this.installedItemsQuery(pageLink, itemTypes)}`, publishedVersionIds, { params: this.buildParams(config) } ); @@ -313,7 +302,6 @@ export class IotHubApiService { ); } - /** Asked in requests of 100 item ids at most, so a tenant with many items doesn't send IoT Hub one huge request. */ public getItemsPublishedVersions(itemIds: string[], config?: IotHubRequestConfig): Observable { if (!itemIds.length) { return of([]); @@ -336,6 +324,11 @@ export class IotHubApiService { ); } + private installedItemsQuery(pageLink: PageLink, itemTypes?: string | string[] | null): string { + const types = !itemTypes ? [] : Array.isArray(itemTypes) ? itemTypes : [itemTypes]; + return pageLink.toQuery() + types.map(t => `&itemTypes=${t}`).join(''); + } + private buildParams(config?: IotHubRequestConfig): HttpParams { return new InterceptorHttpParams( new InterceptorConfig(config?.ignoreLoading ?? false, config?.ignoreErrors ?? false) diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.html index 282e4a0f23..a5a013b68d 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.html @@ -133,7 +133,7 @@

{{ 'iot-hub.unable-to-load-text' | translate }}

} @else { -

{{ 'iot-hub.no-installed-items' | translate }}

+

{{ (onlyUpdates ? 'iot-hub.no-items-with-updates' : 'iot-hub.no-installed-items') | translate }}

{{ 'iot-hub.no-installed-items-text' | translate }}

@if (hasActiveFilters()) { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts index 330fd635ef..8204a42584 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts @@ -84,7 +84,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, isCheckingUpdates = false; updatesCheckFailed = false; onlyUpdates = false; - // Of all types and with no search; null while not known + // Of all types and with no search updatesCount: number | null = null; installedCount = 0; loadFailed = false; @@ -135,10 +135,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, ngOnChanges(changes: SimpleChanges): void { if (changes.textSearch || changes.typeFilters) { if (!changes.textSearch?.firstChange || !changes.typeFilters?.firstChange) { - this.pageIndex = 0; - if (this.paginator) { - this.paginator.pageIndex = 0; - } + this.setPageIndex(0); this.loadData(); } } @@ -146,8 +143,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, ngAfterViewInit(): void { this.sort.sortChange.subscribe(() => { - this.pageIndex = 0; - this.paginator.pageIndex = 0; + this.setPageIndex(0); this.loadData(); }); } @@ -257,16 +253,12 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, next: (infos) => { this.publishedVersionMap.clear(); infos.forEach(info => this.publishedVersionMap.set(info.itemId, info)); - // Checked once the counts are in: the header shows them this.loadUpdatesCount(() => { this.updatesChecked = true; this.isCheckingUpdates = false; - // No newer versions: the full list, where a new default converter still shows + // The full list shows a new default converter, the only-updates list doesn't this.showOnlyUpdates(this.updatesCount > 0); - }, () => { - this.isCheckingUpdates = false; - this.updatesCheckFailed = true; - }); + }, () => this.isCheckingUpdates = false); }, error: () => { this.isCheckingUpdates = false; @@ -277,11 +269,15 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, showOnlyUpdates(onlyUpdates: boolean): void { this.onlyUpdates = onlyUpdates; - this.pageIndex = 0; + this.setPageIndex(0); + this.loadData(); + } + + private setPageIndex(pageIndex: number): void { + this.pageIndex = pageIndex; if (this.paginator) { - this.paginator.pageIndex = 0; + this.paginator.pageIndex = pageIndex; } - this.loadData(); } private publishedVersionIds(): Record { @@ -294,7 +290,6 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, return ids; } - /** Retries a failed load, and the header counts if they failed with it. */ retryLoad(): void { this.loadData(); if (this.updatesChecked && !this.itemVersion && this.updatesCount === null) { @@ -307,18 +302,19 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, this.loadData(); return; } - // The last update done: the full list, as after Check for updates + // Without counts the only-updates list can't be trusted, so the full list this.loadUpdatesCount( () => this.onlyUpdates && this.updatesCount === 0 ? this.showOnlyUpdates(false) : this.loadData(), - () => this.loadData()); + () => this.onlyUpdates ? this.showOnlyUpdates(false) : this.loadData()); } - /** The header counts; the previous ones stay until the new ones arrive, and a later call wins. */ + /** The previous counts stay until the new ones arrive, and a later call wins. A failure shows in the header with Try again. */ private loadUpdatesCount(onCounts?: () => void, onError?: () => void): void { const run = ++this.countRun; + const config = { ignoreLoading: true, ignoreErrors: true }; forkJoin({ - withUpdates: this.iotHubApiService.getInstalledItemsWithUpdates(new PageLink(1), null, this.publishedVersionIds(), { ignoreLoading: true }), - installed: this.iotHubApiService.getInstalledItemsCount(undefined, { ignoreLoading: true }) + withUpdates: this.iotHubApiService.getInstalledItemsWithUpdates(new PageLink(1), null, this.publishedVersionIds(), config), + installed: this.iotHubApiService.getInstalledItemsCount(undefined, config) }).subscribe({ next: ({ withUpdates, installed }) => { if (run !== this.countRun) { @@ -326,6 +322,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, } this.updatesCount = withUpdates.totalElements; this.installedCount = installed; + this.updatesCheckFailed = false; this.cd.markForCheck(); onCounts?.(); }, @@ -334,6 +331,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, return; } this.updatesCount = null; + this.updatesCheckFailed = true; this.cd.markForCheck(); onError?.(); } @@ -424,9 +422,9 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, }; const pageLink = new PageLink(this.pageSize, this.pageIndex, this.textSearch || null, sortOrder); const typeFilters = this.typeFilters?.length ? this.typeFilters : null; - // One item's versions page lists them all + // The empty state shows a failure of the only-updates list; one item's versions page lists them all const items$ = this.onlyUpdates && !this.itemVersion - ? this.iotHubApiService.getInstalledItemsWithUpdates(pageLink, typeFilters, this.publishedVersionIds(), {ignoreLoading: true}) + ? this.iotHubApiService.getInstalledItemsWithUpdates(pageLink, typeFilters, this.publishedVersionIds(), {ignoreLoading: true, ignoreErrors: true}) : this.iotHubApiService.getInstalledItems(pageLink, typeFilters, this.itemVersion?.itemId, {ignoreLoading: true}); const run = ++this.loadRun; items$.subscribe({ @@ -436,10 +434,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, } // The last page emptied after an update or a removal if (!data.data.length && this.pageIndex > 0 && data.totalElements > 0) { - this.pageIndex = Math.ceil(data.totalElements / this.pageSize) - 1; - if (this.paginator) { - this.paginator.pageIndex = this.pageIndex; - } + this.setPageIndex(Math.ceil(data.totalElements / this.pageSize) - 1); this.loadData(); return; } @@ -447,7 +442,6 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges, this.totalElements = data.totalElements; this.loadFailed = false; this.isLoading = false; - // In the only-updates list the version update shows, not the converter's if (this.updatesChecked && !this.itemVersion && !this.onlyUpdates) { void this.checkConverterUpdates(); } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.html index 7d4bbe52d0..7a46195fa5 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.html @@ -18,21 +18,18 @@
- @if (!updatesChecked) { - @if (updatesCheckFailed) { - warning - {{ 'iot-hub.check-for-updates-failed' | translate }} - } - } @else if (updatesCount > 0) { + @if (updatesCheckFailed) { + warning + {{ 'iot-hub.check-for-updates-failed' | translate }} + } @else if (updatesChecked && updatesCount > 0) { arrow_circle_up {{ 'iot-hub.items-with-update' | translate:{ count: updatesCount, total: installedCount } }} - } @else if (updatesCount === 0) { - + } @else if (updatesChecked && updatesCount === 0) { check_circle {{ 'iot-hub.no-newer-versions' | translate }} } - @if (!updatesChecked) { + @if (!updatesChecked || updatesCheckFailed) { - } @else { + } + @if (updatesChecked) { @if (onlyUpdates) { } @else if ((updatesCount ?? 0) > 0) { diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 217b2e7919..05b9d80811 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -6495,7 +6495,7 @@ "install-rollback-partial": "Some of the items installed before the failure could not be removed automatically and may need to be deleted manually.", "check-for-updates": "Check for updates", "check-for-updates-failed": "Couldn't check for updates", - "items-with-update": "{ count, plural, =1 {1 of {total} items has an update} other {# of {total} items have an update} }", + "items-with-update": "Updates available for {{count}} of {{total}}", "no-newer-versions": "No newer versions in IoT Hub", "show-all-items": "Show all items", "show-only-updates": "Show only updates", @@ -6530,6 +6530,7 @@ "installed-date": "Installed", "no-installed-items": "No installed items found", "no-installed-items-text": "Try adjusting your search or filters.", + "no-items-with-updates": "No items with updates match your filters", "remove-installed-item-title": "Remove Installed Item", "remove-installed-item-text": "Are you sure you want to remove '{{name}}'? The installed entity will also be removed.", "installed-item-removed": "'{{name}}' has been removed",