Browse Source

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)

pull/16657/head
dpinkevych 3 weeks ago
parent
commit
d67da9487c
Failed to extract signature
  1. 23
      ui-ngx/src/app/core/http/iot-hub-api.service.ts
  2. 2
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.html
  3. 52
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts
  4. 18
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.html
  5. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

23
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<PageData<IotHubInstalledItem>> {
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<string, string>,
config?: IotHubRequestConfig): Observable<PageData<IotHubInstalledItem>> {
let query = pageLink.toQuery();
if (itemTypes?.length) {
query += itemTypes.map(t => `&itemTypes=${t}`).join('');
}
return this.http.post<PageData<IotHubInstalledItem>>(
`/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<ItemPublishedVersionInfo[]> {
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)

2
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.html

@ -133,7 +133,7 @@
<p>{{ 'iot-hub.unable-to-load-text' | translate }}</p>
<button mat-flat-button color="primary" (click)="retryLoad()">{{ 'iot-hub.try-again' | translate }}</button>
} @else {
<h3>{{ 'iot-hub.no-installed-items' | translate }}</h3>
<h3>{{ (onlyUpdates ? 'iot-hub.no-items-with-updates' : 'iot-hub.no-installed-items') | translate }}</h3>
<p>{{ 'iot-hub.no-installed-items-text' | translate }}</p>
@if (hasActiveFilters()) {
<button mat-flat-button color="primary" (click)="clearFilters.emit()">{{ 'iot-hub.clear-all-filters' | translate }}</button>

52
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<string, string> {
@ -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();
}

18
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.html

@ -18,21 +18,18 @@
<div class="flex items-center gap-4">
<!-- Always there, so a screen reader announces each change of the note -->
<span class="inline-flex items-center gap-2 text-sm leading-5 tracking-[0.2px] text-black/[.76]" role="status">
@if (!updatesChecked) {
@if (updatesCheckFailed) {
<mat-icon class="tb-mat-20 text-[#f66716]">warning</mat-icon>
{{ 'iot-hub.check-for-updates-failed' | translate }}
}
} @else if (updatesCount > 0) {
@if (updatesCheckFailed) {
<mat-icon class="tb-mat-20 text-[#f66716]">warning</mat-icon>
{{ 'iot-hub.check-for-updates-failed' | translate }}
} @else if (updatesChecked && updatesCount > 0) {
<mat-icon class="tb-mat-20 text-[#f44336]">arrow_circle_up</mat-icon>
{{ 'iot-hub.items-with-update' | translate:{ count: updatesCount, total: installedCount } }}
} @else if (updatesCount === 0) {
<!-- Only versions: a package may still have a new default converter, which the list shows -->
} @else if (updatesChecked && updatesCount === 0) {
<mat-icon class="tb-mat-20 text-[#198038]">check_circle</mat-icon>
{{ 'iot-hub.no-newer-versions' | translate }}
}
</span>
@if (!updatesChecked) {
@if (!updatesChecked || updatesCheckFailed) {
<button mat-flat-button color="primary" (click)="checkForUpdates()" [disabled]="isCheckingUpdates">
@if (isCheckingUpdates) {
<mat-spinner matButtonIcon class="mr-2" diameter="18"></mat-spinner>
@ -41,7 +38,8 @@
}
{{ (updatesCheckFailed ? 'iot-hub.try-again' : 'iot-hub.check-for-updates') | translate }}
</button>
} @else {
}
@if (updatesChecked) {
@if (onlyUpdates) {
<button mat-stroked-button color="primary" (click)="showOnlyUpdates(false)">{{ 'iot-hub.show-all-items' | translate }}</button>
} @else if ((updatesCount ?? 0) > 0) {

3
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",

Loading…
Cancel
Save