diff --git a/dao/src/main/java/org/thingsboard/server/dao/iot_hub/IotHubInstalledItemServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/iot_hub/IotHubInstalledItemServiceImpl.java index 89f7d636b2..90fe24e0d6 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/iot_hub/IotHubInstalledItemServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/iot_hub/IotHubInstalledItemServiceImpl.java @@ -54,14 +54,16 @@ class IotHubInstalledItemServiceImpl implements IotHubInstalledItemService { public PageData findByTenantIdWithUpdates(TenantId tenantId, List itemTypes, Map 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 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(); diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/IotHubInstalledItemServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/IotHubInstalledItemServiceTest.java index 8d7698d2ce..65fe12ae2b 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/IotHubInstalledItemServiceTest.java +++ b/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 published = new HashMap<>(published()); + for (int i = 0; i < 20_000; i++) { + published.put(UUID.randomUUID(), UUID.randomUUID()); + } + + PageData 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(); 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 c871f0492e..b24e8bb4cf 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 @@ -125,34 +125,23 @@ - @if (!isLoading && loadFailed && onlyUpdates) { - + @if (!isLoading && dataSource.length === 0) {
-

{{ 'iot-hub.installed-items-load-failed' | translate }}

- -
- } @else if (!isLoading && dataSource.length === 0 && onlyUpdates && !hasActiveFilters()) { - -
-
-

{{ 'iot-hub.all-items-up-to-date' | translate }}

-

{{ 'iot-hub.all-items-up-to-date-text' | translate }}

- -
- } @else if (!isLoading && dataSource.length === 0) { -
-
-

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

-

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

- @if (hasActiveFilters()) { - + @if (loadFailed) { +

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

+

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

+ + } @else if (onlyUpdates && !hasActiveFilters()) { +

{{ 'iot-hub.all-items-up-to-date' | translate }}

+

{{ 'iot-hub.all-items-up-to-date-text' | translate }}

+ + } @else { +

{{ '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 073bbe8171..3ada8afee5 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 @@ -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 { const ids: Record = {}; 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(); } 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 456fcdbd1f..e70619ab4b 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 @@ -15,11 +15,11 @@

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

- @if (!updatesChecked) { -
+
+ @if (!updatesChecked) { @if (updatesCheckFailed) { - - warning + + warning {{ 'iot-hub.check-for-updates-failed' | translate }} } @@ -29,20 +29,18 @@ } @else { update } - {{ (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 }} -
- } @else { - -
+ } @else { @if (updatesCount !== null) { - + @if (updatesCount > 0) { - arrow_circle_up + arrow_circle_up {{ 'iot-hub.items-with-update' | translate:{ count: updatesCount, total: installedCount } }} } @else { - check_circle - {{ 'iot-hub.all-items-up-to-date' | translate }} + + check_circle + {{ 'iot-hub.no-newer-versions' | translate }} } } @@ -51,8 +49,8 @@ } @else if ((updatesCount ?? 0) > 0) { } -
- } + } +
diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.scss index eab61c2c2a..1ade0222c5 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.scss +++ b/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; 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 44d86bf476..899486594c 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/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",