Browse Source

IoT Hub installed items: the full list when no newer versions, the map bounded by installed items, retry with the counts (PROD-9326 review)

pull/16657/head
dpinkevych 3 weeks ago
parent
commit
53aeba0875
  1. 12
      dao/src/main/java/org/thingsboard/server/dao/iot_hub/IotHubInstalledItemServiceImpl.java
  2. 15
      dao/src/test/java/org/thingsboard/server/dao/service/IotHubInstalledItemServiceTest.java
  3. 41
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.html
  4. 38
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts
  5. 28
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.html
  6. 29
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.scss
  7. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

12
dao/src/main/java/org/thingsboard/server/dao/iot_hub/IotHubInstalledItemServiceImpl.java

@ -54,14 +54,16 @@ class IotHubInstalledItemServiceImpl implements IotHubInstalledItemService {
public PageData<IotHubInstalledItem> findByTenantIdWithUpdates(TenantId tenantId, List<String> itemTypes,
Map<UUID, UUID> publishedVersionIds, PageLink pageLink) {
validatePageLink(pageLink, IotHubInstalledItemEntity.ALLOWED_SORT_PROPERTIES);
// An item IoT Hub publishes no version of has nothing to update to
// Only the tenant's installed items, so the map can't outgrow the query's bind parameter limit; an item IoT Hub
// publishes no version of has nothing to update to
Map<UUID, UUID> published = new HashMap<>();
if (publishedVersionIds != null) {
publishedVersionIds.forEach((itemId, versionId) -> {
if (itemId != null && versionId != null) {
if (publishedVersionIds != null && !publishedVersionIds.isEmpty()) {
for (UUID itemId : iotHubInstalledItemDao.findInstalledItemIdsByTenantId(tenantId)) {
UUID versionId = publishedVersionIds.get(itemId);
if (versionId != null) {
published.put(itemId, versionId);
}
});
}
}
if (published.isEmpty()) {
return PageData.emptyPageData();

15
dao/src/test/java/org/thingsboard/server/dao/service/IotHubInstalledItemServiceTest.java

@ -108,6 +108,21 @@ public class IotHubInstalledItemServiceTest extends AbstractServiceTest {
assertThat(names(installedItemService.findByTenantId(tenantId, null, sensorItemId, byName))).containsExactly("a", "c", "d");
}
@Test
public void withUpdates_ignoresItemsTheTenantHasNotInstalled() {
installFive();
Map<UUID, UUID> published = new HashMap<>(published());
for (int i = 0; i < 20_000; i++) {
published.put(UUID.randomUUID(), UUID.randomUUID());
}
PageData<IotHubInstalledItem> page = installedItemService.findByTenantIdWithUpdates(tenantId, null, published,
new PageLink(10, 0, null, new SortOrder("itemName", SortOrder.Direction.ASC)));
// 40k bind parameters would be over PostgreSQL's limit of 32767
assertThat(names(page)).containsExactly("b", "d");
}
@Test
public void withUpdates_withoutPublishedVersions_isEmpty() {
installFive();

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

@ -125,34 +125,23 @@
<tr mat-row *matRowDef="let _row; columns: displayedColumns;"></tr>
</table>
@if (!isLoading && loadFailed && onlyUpdates) {
<!-- The list of items with an update didn't load: not the same as none having one -->
@if (!isLoading && dataSource.length === 0) {
<div class="tb-iot-hub-empty-state flex flex-1 flex-col items-center justify-center text-center">
<div class="tb-no-data-bg"></div>
<h3>{{ 'iot-hub.installed-items-load-failed' | translate }}</h3>
<button mat-flat-button color="primary" (click)="showOnlyUpdates(true)">
{{ 'iot-hub.check-for-updates-try-again' | translate }}
</button>
</div>
} @else if (!isLoading && dataSource.length === 0 && onlyUpdates && !hasActiveFilters()) {
<!-- Only the items with an update, and none has one -->
<div class="tb-iot-hub-empty-state flex flex-1 flex-col items-center justify-center text-center">
<div class="tb-no-data-bg"></div>
<h3>{{ 'iot-hub.all-items-up-to-date' | translate }}</h3>
<p>{{ 'iot-hub.all-items-up-to-date-text' | translate }}</p>
<button mat-flat-button color="primary" (click)="showOnlyUpdates(false)">
{{ 'iot-hub.show-all-items' | translate }}
</button>
</div>
} @else if (!isLoading && dataSource.length === 0) {
<div class="tb-iot-hub-empty-state flex flex-1 flex-col items-center justify-center text-center">
<div class="tb-no-data-bg"></div>
<h3>{{ '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>
@if (loadFailed) {
<h3>{{ 'iot-hub.unable-to-load' | translate }}</h3>
<p>{{ 'iot-hub.unable-to-load-text' | translate }}</p>
<button mat-flat-button color="primary" (click)="retryLoad()">{{ 'iot-hub.try-again' | translate }}</button>
} @else if (onlyUpdates && !hasActiveFilters()) {
<h3>{{ 'iot-hub.all-items-up-to-date' | translate }}</h3>
<p>{{ 'iot-hub.all-items-up-to-date-text' | translate }}</p>
<button mat-flat-button color="primary" (click)="showOnlyUpdates(false)">{{ 'iot-hub.show-all-items' | translate }}</button>
} @else {
<h3>{{ '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>
}
}
</div>
}

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

@ -82,16 +82,12 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
private converterCheckRun = 0;
updatesChecked = false;
isCheckingUpdates = false;
// IoT Hub didn't answer Check for updates: the page says so quietly, the list works without it
updatesCheckFailed = false;
// After Check for updates the list shows only the items with an update, until the user asks for all of them
onlyUpdates = false;
// How many installed items have an update, and how many there are, of all types and with no search; null while not known
// Of all types and with no search; null while not known
updatesCount: number | null = null;
// The last load of the list failed: the list is empty, but not because nothing has an update
loadFailed = false;
installedCount = 0;
// A later load (another page, mode, sort or search) wins over an earlier one that answers last
loadFailed = false;
private loadRun = 0;
private widgetResize$: ResizeObserver;
@ -262,8 +258,8 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
infos.forEach(info => this.publishedVersionMap.set(info.itemId, info));
this.updatesChecked = true;
this.isCheckingUpdates = false;
this.showOnlyUpdates(true);
this.loadUpdatesCount();
// No newer versions: the full list, where a new default converter still shows
this.loadUpdatesCount(() => this.showOnlyUpdates((this.updatesCount ?? 0) > 0));
},
error: () => {
this.isCheckingUpdates = false;
@ -272,7 +268,6 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
});
}
/** Only the items with an update, or all of them; from the first page, as the list changes. */
showOnlyUpdates(onlyUpdates: boolean): void {
this.onlyUpdates = onlyUpdates;
this.pageIndex = 0;
@ -282,7 +277,6 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
this.loadData();
}
/** IoT Hub's published version id by item id, of the items it publishes a version of. */
private publishedVersionIds(): Record<string, string> {
const ids: Record<string, string> = {};
this.publishedVersionMap.forEach((info, itemId) => {
@ -293,7 +287,14 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
return ids;
}
/** After an item is updated or removed: the list and, once the updates are checked, the counts in the header. */
/** Retries a failed load, and the header counts if they failed with it. */
retryLoad(): void {
this.loadData();
if (this.updatesCount === null) {
this.loadUpdatesCount();
}
}
private reloadAfterChange(): void {
this.loadData();
if (this.updatesChecked && !this.itemVersion) {
@ -301,7 +302,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
}
}
private loadUpdatesCount(): void {
private loadUpdatesCount(then?: () => void): void {
this.updatesCount = null;
forkJoin({
withUpdates: this.iotHubApiService.getInstalledItemsWithUpdates(new PageLink(1), null, this.publishedVersionIds(), { ignoreLoading: true }),
@ -311,9 +312,12 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
this.updatesCount = withUpdates.totalElements;
this.installedCount = installed;
this.cd.markForCheck();
then?.();
},
// The header then shows only the buttons
error: () => this.cd.markForCheck()
error: () => {
this.cd.markForCheck();
then?.();
}
});
}
@ -401,7 +405,7 @@ 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;
// The page of one item's versions has its own published version and lists all of them
// 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.getInstalledItems(pageLink, typeFilters, this.itemVersion?.itemId, {ignoreLoading: true});
@ -411,7 +415,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
if (run !== this.loadRun) {
return;
}
// The last page emptied (its last item updated or removed): go to the page that is last now
// 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) {
@ -424,7 +428,7 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
this.totalElements = data.totalElements;
this.loadFailed = false;
this.isLoading = false;
// In the list of items with an update their version update shows, not the converter's
// In the only-updates list the version update shows, not the converter's
if (this.updatesChecked && !this.itemVersion && !this.onlyUpdates) {
void this.checkConverterUpdates();
}

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

@ -15,11 +15,11 @@
<!-- Header -->
<div class="tb-installed-header">
<h1 class="tb-installed-title">{{ 'iot-hub.installed-items' | translate }}</h1>
@if (!updatesChecked) {
<div class="tb-installed-updates flex items-center gap-4">
<div class="flex items-center gap-4">
@if (!updatesChecked) {
@if (updatesCheckFailed) {
<span class="tb-installed-updates-note">
<mat-icon class="tb-installed-updates-failed">warning</mat-icon>
<span class="inline-flex items-center gap-2 text-sm leading-5 tracking-[0.2px] text-black/[.76]" role="status">
<mat-icon class="tb-mat-20 text-[#f66716]">warning</mat-icon>
{{ 'iot-hub.check-for-updates-failed' | translate }}
</span>
}
@ -29,20 +29,18 @@
} @else {
<mat-icon matButtonIcon>update</mat-icon>
}
{{ (updatesCheckFailed ? 'iot-hub.check-for-updates-try-again' : 'iot-hub.check-for-updates') | translate }}
{{ (updatesCheckFailed ? 'iot-hub.try-again' : 'iot-hub.check-for-updates') | translate }}
</button>
</div>
} @else {
<!-- After Check for updates: how many items have one, and the switch between them and all items -->
<div class="tb-installed-updates flex items-center gap-4">
} @else {
@if (updatesCount !== null) {
<span class="tb-installed-updates-note">
<span class="inline-flex items-center gap-2 text-sm leading-5 tracking-[0.2px] text-black/[.76]" role="status">
@if (updatesCount > 0) {
<mat-icon class="tb-installed-updates-available">arrow_circle_up</mat-icon>
<mat-icon class="tb-mat-20 text-[#f44336]">arrow_circle_up</mat-icon>
{{ 'iot-hub.items-with-update' | translate:{ count: updatesCount, total: installedCount } }}
} @else {
<mat-icon class="tb-installed-updates-none">check_circle</mat-icon>
{{ 'iot-hub.all-items-up-to-date' | translate }}
<!-- Only versions: a package may still have a new default converter, which the list shows -->
<mat-icon class="tb-mat-20 text-[#198038]">check_circle</mat-icon>
{{ 'iot-hub.no-newer-versions' | translate }}
}
</span>
}
@ -51,8 +49,8 @@
} @else if ((updatesCount ?? 0) > 0) {
<button mat-stroked-button color="primary" (click)="showOnlyUpdates(true)">{{ 'iot-hub.show-only-updates' | translate }}</button>
}
</div>
}
}
</div>
</div>
<!-- Filter + chips row -->

29
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.scss

@ -29,35 +29,6 @@
margin-bottom: 32px;
}
// After Check for updates: "N items have an update" and Show all items / Show only updates
.tb-installed-updates-note {
display: inline-flex;
align-items: center;
gap: 8px;
font-size: 14px;
line-height: 20px;
letter-spacing: 0.2px;
color: rgba(0, 0, 0, 0.76);
mat-icon {
font-size: 20px;
width: 20px;
height: 20px;
}
.tb-installed-updates-available {
color: #f44336;
}
.tb-installed-updates-none {
color: #198038;
}
.tb-installed-updates-failed {
color: #f66716;
}
}
.tb-installed-title {
font-size: 36px;
font-weight: 500;

3
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -6495,10 +6495,9 @@
"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",
"check-for-updates-try-again": "Try again",
"items-with-update": "{ count, plural, =1 {1 of {total} items has an update} other {# of {total} items have an update} }",
"installed-items-load-failed": "Couldn't load the items with an update",
"all-items-up-to-date": "All items are up to date",
"no-newer-versions": "No newer versions in IoT Hub",
"all-items-up-to-date-text": "No installed item has a newer version in IoT Hub.",
"show-all-items": "Show all items",
"show-only-updates": "Show only updates",

Loading…
Cancel
Save