From 5595dde55e8b3fe76005b32c3ad21cf3474c0677 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Mon, 14 Sep 2026 19:05:49 +0300 Subject: [PATCH 01/23] feat(iot-hub): group the hero search popup, and give the search page filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two surfaces, one defect between them: a query answered by several content types could not show all of them. **The hero popup** asked /api/versions/published for one flat page of ten rows by install count and grouped that page on the client. Ten rows cannot hold four of each of six item types, so whichever types filled the page took it and the rest had no section at all — and an absent section was indistinguishable from "no matches of this type". Measured against the catalogue, `temperature` returns 71 matches across five types; a flat top-16 by install count shows no calculated field and no alarm rule, and by relevance it shows none of the 22 devices. On `gateway` neither ordering surfaces one of the 12 matching widgets. It asks for a grouped answer now. The server caps each type and puts `typeTotal` on every row, so the client renders what it was given: one section per type, the header a link to that type page carrying the current query and, when more of that type exists, a "+N more ›" chip. Count and chevron appear together or not at all — on a section already showing everything a chevron points at nothing. The footer names where it goes rather than an ordering. **The search page** keeps its flat paginated grid — the site's equivalent is a browsable catalogue with indexed page URLs, so neither product groups there — and gains what it was missing beside the type pages: * A filter panel: item type, category, use case. Type is new, this being the one page that mixes them. There is no catalogue-wide filterInfo endpoint, so the six per-type answers are merged client-side. Counts are deliberately not rendered: filterInfo takes no text query, so beside a searched result they would be the whole catalogue's numbers describing a different answer. * A page size that follows the column count, read from a hidden probe carrying the grid's own classes rather than restated from its media queries: max(12, columns × 3). Fifteen at every width ended a page mid-row at four and six columns. * One card layout. Calculated fields, alarm rules and rule chains render as a compact horizontal row that needs a wide cell; the type pages narrow the grid for them, a mixed grid cannot, and those rows truncated their own titles. **Relevance** is a sort option on all four surfaces that carry a search field, and the default on each. With text it ranks the answer; without it the backend substitutes the install count, so browsing keeps the order it had. Nothing switches on the field state — a control that relabels itself unasked was tried and rejected. Also here: the search page moves onto the type pages' frame — one even padding on the card, the component full bleed — which removes four breakpoints' worth of negative margins, each written to cancel that padding for one element. --- .../dashboard-widget-select.component.ts | 12 + .../iot-hub/iot-hub-browse.component.ts | 16 ++ .../iot-hub/iot-hub-components.module.ts | 3 + .../iot-hub/iot-hub-facet-list.component.html | 31 ++ .../iot-hub/iot-hub-facet-list.component.scss | 92 ++++++ .../iot-hub/iot-hub-facet-list.component.ts | 83 ++++++ .../iot-hub/iot-hub-item-card.component.html | 4 +- .../iot-hub/iot-hub-item-card.component.ts | 13 + .../iot-hub/iot-hub-search.component.html | 120 +++++--- .../iot-hub/iot-hub-search.component.scss | 190 +++++++++--- .../iot-hub/iot-hub-search.component.ts | 270 ++++++++++++++---- .../iot-hub-creator-profile.component.html | 5 +- .../pages/iot-hub/iot-hub-home.component.html | 67 +++-- .../pages/iot-hub/iot-hub-home.component.scss | 35 +++ .../pages/iot-hub/iot-hub-home.component.ts | 46 ++- .../iot-hub-search-page.component.scss | 101 ++----- .../models/iot-hub/iot-hub-version.models.ts | 27 ++ .../assets/locale/locale.constant-en_US.json | 4 + 18 files changed, 884 insertions(+), 235 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html create mode 100644 ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss create mode 100644 ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts index d93a1e504e..57c621eb8d 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts @@ -88,7 +88,19 @@ export class DashboardWidgetSelectComponent { includeDeprecated = false; searchFocused = false; + /** + * Relevance leads, and is therefore the default (iotHubSelectedSortIndex starts at 0). This + * panel has a search field, which is the only thing relevance ranks by; with the field empty + * the backend substitutes the install count, so the picker opens on the order it always had. + * + * scadaFirst is unaffected: the backend prepends it ahead of the caller's sort AND ahead of + * relevance, so a SCADA context still lists SCADA widgets first. + * + * Fourth copy of this list — the others are in TbIotHubSearchComponent, TbIotHubBrowseComponent + * and IOT_HUB_SORT_OPTIONS on thingsboard.io. Kept in step by hand. + */ iotHubSortOptions: WidgetSelectSortOption[] = [ + { value: 'relevance', label: 'iot-hub.sort-most-relevant', direction: Direction.DESC }, { value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC }, { value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC }, { value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC } diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts index 11352f1d04..785bd48660 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts @@ -126,7 +126,17 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy activeHardwareTypes = new Set(); activeVendors = new Set(); + /** + * Relevance leads, and is therefore the default (selectedSortIndex starts at 0). A type page + * carries a search field, which is the only thing relevance ranks by; with the field empty the + * backend substitutes the install count, so browsing keeps the order it always had. + * + * Kept in step by hand with TbIotHubSearchComponent's list and with IOT_HUB_SORT_OPTIONS on + * thingsboard.io — three copies, because the two products share no code and this component + * predates the search page's list. + */ sortOptions: SortOption[] = [ + { value: 'relevance', label: 'iot-hub.sort-most-relevant', direction: Direction.DESC }, { value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC }, { value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC }, { value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC } @@ -176,6 +186,12 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy if (params['search']) { this.textSearch = params['search']; } + // A search section header on a creator profile lands here scoped to that creator. The + // bound input wins: an embedded host (the add-item dialog) sets its own scope, and must + // not pick one up from whatever URL happens to be open behind the dialog. + if (!this.creatorId && !this.embedded && params['creatorId']) { + this.creatorId = params['creatorId']; + } if (this.fixedSubType) { const subtypes = this.getActiveSubtypes(); if (subtypes) { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts index 53e2493651..00ce18b4c0 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts @@ -14,6 +14,7 @@ import { TbIotHubUnpublishedWarningDialogComponent } from './iot-hub-unpublished import { TbDeviceInstallDialogComponent } from './device-install-dialog/device-install-dialog.component'; import { InstallFormRendererComponent } from './device-install-dialog/install-form-renderer/install-form-renderer.component'; import { TbIotHubSearchComponent } from './iot-hub-search.component'; +import { TbIotHubFacetListComponent } from './iot-hub-facet-list.component'; import { TbIotHubInstalledItemsTableComponent } from './iot-hub-installed-items-table.component'; import { TbIotHubInstalledItemsDialogComponent } from './iot-hub-installed-items-dialog.component'; import { TbPeConnectivityMethodPromptComponent } from './pe-connectivity-method-prompt.component'; @@ -36,6 +37,7 @@ import { IotHubItemLinkModule } from './iot-hub-item-link-card/iot-hub-item-link TbIotHubUnpublishedWarningDialogComponent, TbDeviceInstallDialogComponent, TbIotHubSearchComponent, + TbIotHubFacetListComponent, TbIotHubInstalledItemsTableComponent, TbIotHubInstalledItemsDialogComponent, TbPeConnectivityMethodPromptComponent, @@ -64,6 +66,7 @@ import { IotHubItemLinkModule } from './iot-hub-item-link-card/iot-hub-item-link TbIotHubUnpublishedWarningDialogComponent, TbDeviceInstallDialogComponent, TbIotHubSearchComponent, + TbIotHubFacetListComponent, TbIotHubInstalledItemsTableComponent, TbIotHubInstalledItemsDialogComponent, TbPeConnectivityMethodPromptComponent, diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html new file mode 100644 index 0000000000..dfde943c22 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html @@ -0,0 +1,31 @@ + + + + {{ label | translate }} + + + @if (searchable) { + + } + +
+ @for (option of visibleOptions; track trackByKey($index, option)) { + + {{ labelFor(option.key) }} + + } +
+
diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss new file mode 100644 index 0000000000..e5fc43f803 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss @@ -0,0 +1,92 @@ +// SPDX-FileCopyrightText: Copyright The Thingsboard Authors +// SPDX-License-Identifier: Apache-2.0 +@import "./iot-hub-common"; + +// Values follow the type pages' filter panel so the two read as one control, minus its deep +// left indent: that indent exists because the panel there sits in a wider rail. +.tb-iot-hub-facet-panel.mat-expansion-panel { + box-shadow: none; + border-radius: 0; + background: transparent; + + // Indented from the column's edges, because the rules between facets are not: they span the + // whole column, as they do on the type pages. The host sets --tb-facet-indent to whatever + // puts this text on the page's own left margin. + .mat-expansion-panel-header { + padding: 8px 16px 8px var(--tb-facet-indent, 16px); + height: 48px; + min-height: 48px; + } + + ::ng-deep .mat-expansion-panel-header-title { + font-size: 14px; + font-weight: 500; + color: rgba(0, 0, 0, 0.87); + } + + ::ng-deep .mat-expansion-panel-body { + padding: 0 8px 8px var(--tb-facet-indent, 16px); + } + + mat-checkbox { + display: block; + overflow: hidden; + + &:hover { + background: rgba(0, 0, 0, 0.04); + } + } + + .tb-iot-hub-facet-items { + // Uncapped until the list is long enough to need it, so a three-option facet does not + // reserve a scroll area it never uses. + &.scrollable { + max-height: 280px; + overflow-y: auto; + } + + &::-webkit-scrollbar { + width: 6px; + } + + &::-webkit-scrollbar-track { + background-color: transparent; + } + + &::-webkit-scrollbar-thumb { + background-color: transparent; + border-radius: 3px; + } + + &:hover { + &::-webkit-scrollbar-track { + background-color: rgba(0, 0, 0, 0.04); + } + + &::-webkit-scrollbar-thumb { + background-color: rgba(0, 0, 0, 0.2); + + &:hover { + background-color: rgba(0, 0, 0, 0.35); + } + } + } + } + + .tb-iot-hub-facet-search { + @include tb-iot-hub-search-container; + margin: 4px 8px 8px 0; + + mat-icon { + @include tb-iot-hub-search-icon(rgba(0, 0, 0, 0.54)); + } + + input { + @include tb-iot-hub-search-input-text(0.2px); + } + + .tb-iot-hub-facet-search-clear.mat-mdc-icon-button { + @include tb-iot-hub-search-clear; + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts new file mode 100644 index 0000000000..b9b5625fce --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts @@ -0,0 +1,83 @@ +// SPDX-FileCopyrightText: Copyright The Thingsboard Authors +// SPDX-License-Identifier: Apache-2.0 +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { FilterParamInfo } from '@shared/models/iot-hub/iot-hub-item.models'; + +/** + * One checkbox facet of a filter panel: a title, the options with their item counts, and the + * set of keys currently selected. Presentational only - it owns no filter state and issues no + * request; the host decides what a toggle means. + * + * Written for the cross-type search page, which needs three plain facets (item type, category, + * use case). The type pages keep their own panel in TbIotHubBrowseComponent: theirs carries + * facets this one has no notion of - grouped connectivity, vendor lists, per-type subtypes - + * so folding the two together would mean parameterising that panel for a shape it never uses. + */ +@Component({ + selector: 'tb-iot-hub-facet-list', + standalone: false, + templateUrl: './iot-hub-facet-list.component.html', + styleUrls: ['./iot-hub-facet-list.component.scss'] +}) +export class TbIotHubFacetListComponent { + + /** Translation key for the facet's heading. */ + @Input() label: string; + + @Input() options: FilterParamInfo[] = []; + + /** Keys the host currently has selected. Read, never written. */ + @Input() selected = new Set(); + + /** + * Turns an option key into what the user reads. Defaults to the key, which is already the + * display value for categories and use cases; item types come through as enum names and need + * their translated plural. + */ + @Input() labelFor: (key: string) => string = (key) => key; + + /** + * Open on first render. The host decides: a short, always-relevant facet earns the space it + * takes, a long one costs the reader the facets below it — on the search page all three + * headings fit above the fold only because two of them start closed. + */ + @Input() expanded = true; + + @Output() toggled = new EventEmitter(); + + /** + * Above this many options the facet gets its own search box and a scroll cap. Matches the + * threshold the type pages' panel uses, so the two feel the same at the same list lengths. + */ + private static readonly SEARCH_THRESHOLD = 8; + + search = ''; + + get searchable(): boolean { + return this.options.length > TbIotHubFacetListComponent.SEARCH_THRESHOLD; + } + + get visibleOptions(): FilterParamInfo[] { + const needle = this.search.trim().toLowerCase(); + if (!needle) { + return this.options; + } + return this.options.filter(o => this.labelFor(o.key).toLowerCase().includes(needle)); + } + + get scrollable(): boolean { + return this.visibleOptions.length > TbIotHubFacetListComponent.SEARCH_THRESHOLD; + } + + isSelected(key: string): boolean { + return this.selected.has(key); + } + + onToggle(key: string): void { + this.toggled.emit(key); + } + + trackByKey(_index: number, option: FilterParamInfo): string { + return option.key; + } +} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html index cbde4bbf83..16bca59bf7 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html @@ -78,7 +78,9 @@ } @else {
- {{ getPlaceholderIcon() }} + + {{ getPlaceholderIcon() }}
} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts index 22a4eaf323..f57582fb29 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts @@ -23,6 +23,16 @@ export class TbIotHubItemCardComponent { @Input() showTypeChip = true; @Input() showSubtype = false; @Input() mode: 'default' | 'add' = 'default'; + /** + * `auto` lets the item's type choose, which is what a single-type grid wants: calculated + * fields, alarm rules and rule chains have nothing to preview, so they get a compact row and + * the grid gives them wider cells. + * + * `preview` forces the tall card on every type. A grid that mixes types cannot widen its + * cells for some rows only, and a horizontal row squeezed into a cell sized for a preview + * truncates its own title and leaves the rest of the cell empty. + */ + @Input() layout: 'auto' | 'preview' = 'auto'; @Output() cardClick = new EventEmitter(); @Output() creatorClick = new EventEmitter(); @Output() installClick = new EventEmitter(); @@ -47,6 +57,9 @@ export class TbIotHubItemCardComponent { } isCompactLayout(): boolean { + if (this.layout === 'preview') { + return false; + } return this.item.type === ItemType.CALCULATED_FIELD || this.item.type === ItemType.ALARM_RULE || this.item.type === ItemType.RULE_CHAIN; diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html index c737e1e96c..5963b7c003 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html @@ -4,14 +4,26 @@ SPDX-License-Identifier: Apache-2.0 --> -
+
{{ 'iot-hub.results-count' | translate:{ count: totalElements } }}
- -
+ + + + +
+ @if (showFilters) { + + }
-
+
{{ 'iot-hub.results-count' | translate:{ count: totalElements } }} @@ -76,7 +88,59 @@
-
+ + +
+ @if (activeFilterCount > 0) { + + } + + + @if (categoryOptions.length > 0) { + + + + } + @if (useCaseOptions.length > 0) { + + + } +
+
+ +
+ + +
+ @if (showFilters) { + + }
@@ -100,39 +164,27 @@
} - - @if (resultGroups.length > 0) { -
- @for (group of resultGroups; track group.type) { -
- - - -
- @for (item of group.items; track item.id) { - - - } -
-
+ + @if (results.length > 0) { +
+ @for (item of results; track item.id) { + + }
}
+
@if (isLoading) { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss index 4b43ad5b3c..2556d03f3d 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss @@ -8,6 +8,14 @@ flex-direction: column; } +// The page hands this component the card's full width and its own side padding as a variable. +// Rows that are ordinary content pad themselves back in; the divider and the filter rail are +// the two things that are supposed to reach the edge, so they do not. +.tb-search-pad { + padding-left: var(--tb-search-side-pad, 0px); + padding-right: var(--tb-search-side-pad, 0px); +} + .tb-search-results-count-mobile { display: none; margin-left: auto; @@ -143,49 +151,135 @@ overflow: auto; } -// Categories / sections -.tb-search-categories { +// Card grid +.tb-search-card-grid { + display: grid; + grid-template-columns: repeat(5, 1fr); + gap: 20px; + + // Probe: zero-height element used only to read the computed column count. + // Keeps display: grid and non-zero width so grid-template-columns resolves. + &.tb-search-card-grid-probe { + width: 100%; + height: 0; + gap: 0; + overflow: hidden; + visibility: hidden; + pointer-events: none; + } +} + +// Filter button — the drawer's trigger, and where the active count is shown +.tb-search-filter-btn { + flex-shrink: 0; +} + +.tb-search-filter-count { + margin-left: 6px; + min-width: 18px; + height: 18px; + padding: 0 5px; + border-radius: 9px; + background: rgba(0, 0, 0, 0.08); + font-size: 12px; + line-height: 18px; + font-variant-numeric: tabular-nums; +} + +// Content: facet sidebar beside the grid +// The page gives this component the viewport's remaining height and expects its body to scroll +// inside, not to grow past the white card. So the row takes that height and BOTH columns scroll +// themselves — the grid as it always did, the facets likewise. A facet list can then be any +// length at all without reaching the page behind it. +.tb-search-layout { display: flex; - flex-direction: column; - gap: 48px; + gap: 24px; + height: 100%; + min-height: 0; + + .tb-results-container { + flex: 1; + min-width: 0; + // Only on the right: the gap to the rail already separates it on the left. + padding-right: var(--tb-search-side-pad, 0px); + } } -// Section header -.tb-search-section-header { - font-size: 18px; - font-weight: 500; - line-height: 24px; - color: rgba(0, 0, 0, 0.87); - padding: 0; - margin-bottom: 12px; +.tb-search-facets-desktop { + width: 232px; + flex-shrink: 0; + border-right: 1px solid rgba(0, 0, 0, 0.12); + + // The component is already full-bleed, so this column starts at the card's edge with no + // margin of its own and every rule drawn across it reaches that edge. The indent goes INSIDE + // each facet — padding here would inset the rules too — and matches the page's own margin, so + // the words line up with the heading above them. + --tb-facet-indent: var(--tb-search-side-pad, 16px); + + align-self: stretch; + height: 100%; + overflow-y: auto; + padding-top: 20px; + + &::-webkit-scrollbar { + width: 6px; + } + + &::-webkit-scrollbar-track { + background-color: transparent; + } + + &::-webkit-scrollbar-thumb { + background-color: transparent; + border-radius: 3px; + } + + &:hover { + &::-webkit-scrollbar-track { + background-color: rgba(0, 0, 0, 0.04); + } - mat-icon { - font-size: 24px; - width: 24px; - height: 24px; + &::-webkit-scrollbar-thumb { + background-color: rgba(0, 0, 0, 0.2); + + &:hover { + background-color: rgba(0, 0, 0, 0.35); + } + } } } -// Card grid -.tb-search-card-grid { - display: grid; - grid-template-columns: repeat(5, 1fr); - gap: 20px; +// The close button and heading belong to the narrow layout only. +.tb-search-facets-header { + display: none; + height: 48px; + font-size: 16px; + font-weight: 500; +} - &.tb-search-card-grid-compact { - grid-template-columns: repeat(3, 1fr); +.tb-search-facets { + display: flex; + flex-direction: column; + padding-bottom: 24px; + + // The type pages put a rule between filter sections. No gap and no padding around it: the + // rule sits flush between two sections, edge to edge, rather than floating inside a gap. + tb-iot-hub-facet-list + tb-iot-hub-facet-list { + border-top: 1px solid rgba(0, 0, 0, 0.12); } } +.tb-search-facets-clear { + align-self: flex-start; + margin-left: calc(var(--tb-facet-indent, 16px) - 16px); +} + // Responsive @media #{$mat-gt-xxl} { .tb-search-card-grid { grid-template-columns: repeat(6, 1fr); - &.tb-search-card-grid-compact { - grid-template-columns: repeat(4, 1fr); - } } } @@ -193,9 +287,6 @@ .tb-search-card-grid { grid-template-columns: repeat(4, 1fr); - &.tb-search-card-grid-compact { - grid-template-columns: repeat(3, 1fr); - } } } @@ -203,9 +294,6 @@ .tb-search-card-grid { grid-template-columns: repeat(3, 1fr); - &.tb-search-card-grid-compact { - grid-template-columns: repeat(2, 1fr); - } } } @@ -229,9 +317,6 @@ .tb-search-card-grid { grid-template-columns: repeat(2, 1fr); - &.tb-search-card-grid-compact { - grid-template-columns: repeat(1, 1fr); - } } } @@ -268,3 +353,38 @@ margin-left: 0; } } + +// The sidebar costs a whole card column, so below this width it stops being a column: the +// panel collapses, and the Filter button opens it as a block above the results. +@media #{$mat-lt-lg} { + .tb-search-layout { + flex-direction: column; + } + + .tb-search-facets-desktop { + display: none; + // As a block above the results it is ordinary content, not a rail, so it lines up with + // the rows above it rather than with the card's edge. + width: 100%; + height: auto; + max-height: 60vh; + border-right: none; + border-bottom: 1px solid rgba(0, 0, 0, 0.12); + padding-right: 0; + + &.opened { + display: block; + } + } + + .tb-search-facets-header { + display: flex; + } +} + +// Wide enough for the sidebar, so the button that opens the block has nothing to open. +@media #{$mat-gt-md} { + .tb-search-filter-btn { + display: none; + } +} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts index f915be77e1..6326a52010 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts @@ -1,6 +1,6 @@ // SPDX-FileCopyrightText: Copyright The Thingsboard Authors // SPDX-License-Identifier: Apache-2.0 -import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core'; +import { Component, OnInit, OnDestroy, Input, Output, EventEmitter, ViewChild, ElementRef } from '@angular/core'; import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { forkJoin, Subject, Subscription } from 'rxjs'; @@ -8,27 +8,38 @@ import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; import { PageLink } from '@shared/models/page/page-link'; import { Direction, SortOrder } from '@shared/models/page/sort-order'; import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; -import { ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; +import { FilterParamInfo, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubActionsService } from './iot-hub-actions.service'; -interface SearchResultGroup { - type: ItemType; - items: MpItemVersionView[]; -} - interface SortOption { value: string; label: string; direction: Direction; } -const TYPE_ORDER: ItemType[] = [ +/** Sort property served by relevance ranking. With no text the backend substitutes the + * install count, so it is a safe default in both states. */ +const RELEVANCE = 'relevance'; + +/** + * Item types the Type facet offers, in the order every other cross-type surface uses (the hero + * popup's sections, the site's). Fixed rather than sorted by count: the counts move with the + * catalogue and a facet whose options reshuffle under the pointer is hard to use. + */ +const FACET_ITEM_TYPES: ItemType[] = [ ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, ItemType.WIDGET, ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN ]; +/** + * Rows a page holds, as a multiple of the column count, so a page always ends on a complete row. + * The floor keeps a one- or two-column phone layout from falling to three cards a page. + */ +const ROWS_PER_PAGE = 3; +const MIN_PAGE_SIZE = 12; + @Component({ selector: 'tb-iot-hub-search', standalone: false, @@ -37,32 +48,64 @@ const TYPE_ORDER: ItemType[] = [ }) export class TbIotHubSearchComponent implements OnInit, OnDestroy { - readonly ItemType = ItemType; - @Input() searchText = ''; @Input() creatorId: string; @Input() showCreator = true; + /** + * Render the filter panel. The search page does; the creator profile does not - it is already + * scoped to one creator, and the site's profile has no panel either. + */ + @Input() showFilters = true; @Output() searchTextChange = new EventEmitter(); get searchPlaceholderKey(): string { return this.creatorId ? 'iot-hub.search-published-items' : 'iot-hub.search'; } - resultGroups: SearchResultGroup[] = []; + results: MpItemVersionView[] = []; totalElements = 0; isLoading = false; hasError = false; private retryTimer: any = null; - pageSize = 15; pageIndex = 0; - pageSizeOptions = [15, 30, 60]; + + /** + * Read from a hidden probe that carries the real grid's classes, not guessed from breakpoints: + * the grid's column count is a CSS fact, and duplicating its media queries in TypeScript is a + * second source of truth that drifts the first time someone edits the stylesheet. + */ + @ViewChild('cardGridProbe', { static: true }) cardGridProbe!: ElementRef; + cols = 5; + pageSize = MIN_PAGE_SIZE; + + get pageSizeOptions(): number[] { + const base = Math.max(MIN_PAGE_SIZE, this.cols * ROWS_PER_PAGE); + return [base, base * 2, base * 4]; + } + + /** Filter panel state. Empty sets mean "no filter", which is what the query object expects. */ + /** Narrow widths only: the facet panel is a block above the results, not a sidebar. */ + filtersOpen = false; + typeOptions: FilterParamInfo[] = []; + categoryOptions: FilterParamInfo[] = []; + useCaseOptions: FilterParamInfo[] = []; + activeTypes = new Set(); + activeCategories = new Set(); + activeUseCases = new Set(); sortOptions: SortOption[] = [ + { value: RELEVANCE, label: 'iot-hub.sort-most-relevant', direction: Direction.DESC }, { value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC }, { value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC }, { value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC } ]; + /** + * Relevance is the default in BOTH states, which is why nothing here switches on whether the + * search field has text. With text it ranks the answer; without it the backend substitutes the + * install count, so a user who never opens this menu sees the order they always saw while + * browsing and the best matches once they type. + */ selectedSortIndex = 0; installedWidgets: IotHubInstalledItem[] = []; @@ -83,6 +126,11 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { ) {} ngOnInit(): void { + this.measureCols(); + this.observeGridWidth(); + if (this.showFilters) { + this.loadFilterInfo(); + } this.loadInstalledItems(); this.searchSubscription = this.searchSubject.pipe( debounceTime(300), @@ -96,6 +144,148 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { ngOnDestroy(): void { this.searchSubscription?.unsubscribe(); + this.resizeSubscription?.unsubscribe(); + this.resizeObserver?.disconnect(); + } + + // Filters + + getTypeLabel = (key: string): string => { + const translationKey = itemTypeTranslations.get(key as ItemType); + return translationKey ? this.translate.instant(translationKey + '-plural') : key; + }; + + onTypeToggle(key: string): void { + this.toggle(this.activeTypes, key); + } + + onCategoryToggle(key: string): void { + this.toggle(this.activeCategories, key); + } + + onUseCaseToggle(key: string): void { + this.toggle(this.activeUseCases, key); + } + + get activeFilterCount(): number { + return this.activeTypes.size + this.activeCategories.size + this.activeUseCases.size; + } + + clearFilters(): void { + if (this.activeFilterCount === 0) { + return; + } + this.activeTypes.clear(); + this.activeCategories.clear(); + this.activeUseCases.clear(); + this.pageIndex = 0; + this.loadResults(); + } + + private toggle(set: Set, key: string): void { + if (set.has(key)) { + set.delete(key); + } else { + set.add(key); + } + this.pageIndex = 0; + this.loadResults(); + } + + /** + * There is no catalogue-wide filterInfo endpoint - it answers per item type - so the six + * answers are merged here, the way the site merges the same six at build time. Counts are + * deliberately not rendered: filterInfo takes no text query, so beside a searched result they + * would be the whole catalogue's numbers pretending to describe this answer. + */ + private loadFilterInfo(): void { + const config = { ignoreLoading: true, ignoreErrors: true }; + forkJoin( + FACET_ITEM_TYPES.map(type => this.iotHubApiService.getFilterInfo(type, config)) + ).subscribe({ + next: infos => { + // Every item type is offered, not only the ones filterInfo reports facets for: the + // endpoint describes a type's categories and vendors, never how many items it has, and + // a type whose items carry no categories would vanish from its own facet. + this.typeOptions = FACET_ITEM_TYPES.map(type => ({ + key: type as string, + totalItems: 0, + totalInstallCount: 0 + })); + this.categoryOptions = this.mergeFacet(infos.map(i => i?.categories)); + this.useCaseOptions = this.mergeFacet(infos.map(i => i?.useCases)); + }, + // A facet panel that failed to load is an empty panel, never a broken page: the grid + // beside it answers the query perfectly well without it. + error: () => {} + }); + } + + private mergeFacet(lists: (FilterParamInfo[] | undefined)[]): FilterParamInfo[] { + const byKey = new Map(); + for (const list of lists) { + for (const option of list || []) { + const seen = byKey.get(option.key); + if (seen) { + seen.totalItems += option.totalItems; + seen.totalInstallCount += option.totalInstallCount; + } else { + byKey.set(option.key, { ...option }); + } + } + } + return [...byKey.values()] + .filter(o => o.totalItems > 0) + .sort((a, b) => a.key.localeCompare(b.key)); + } + + // Column count -> page size + + private resizeObserver?: ResizeObserver; + private resizeSubject = new Subject(); + private resizeSubscription?: Subscription; + + private observeGridWidth(): void { + const el = this.cardGridProbe?.nativeElement; + if (!el || typeof ResizeObserver === 'undefined') { + return; + } + this.resizeSubscription = this.resizeSubject.pipe(debounceTime(150)).subscribe(() => { + const before = this.pageSizeOptions[0]; + this.measureCols(); + if (this.pageSizeOptions[0] === before) { + return; + } + // Keep the user roughly where they were in the list rather than on the same page number: + // page 4 of 12-card pages is a different place from page 4 of 18-card pages. + const firstItem = this.pageIndex * this.pageSize; + this.pageSize = this.pageSizeOptions[0]; + this.pageIndex = Math.floor(firstItem / this.pageSize); + this.loadResults(); + }); + this.resizeObserver = new ResizeObserver(() => this.resizeSubject.next()); + this.resizeObserver.observe(el); + } + + private measureCols(): void { + const el = this.cardGridProbe?.nativeElement; + if (!el) { + return; + } + // Force layout so grid-template-columns resolves to pixel tracks rather than `repeat(...)`. + void el.offsetWidth; + const tracks = getComputedStyle(el).gridTemplateColumns; + if (!tracks || tracks === 'none') { + this.cols = 1; + } else if (tracks.startsWith('repeat(')) { + const match = tracks.match(/^repeat\(\s*(\d+)\s*,/); + this.cols = match ? parseInt(match[1], 10) : 1; + } else { + this.cols = Math.max(1, tracks.trim().split(/\s+/).filter(t => t.length > 0).length); + } + if (!this.pageSizeOptions.includes(this.pageSize)) { + this.pageSize = this.pageSizeOptions[0]; + } } onSearchInput(): void { @@ -159,33 +349,9 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { } // Type helpers - isCompactType(type: ItemType): boolean { - return type === ItemType.CALCULATED_FIELD - || type === ItemType.ALARM_RULE - || type === ItemType.RULE_CHAIN; - } - - getTypeLabel(type: ItemType): string { - const key = itemTypeTranslations.get(type); - return key ? this.translate.instant(key + '-plural') : type; - } - - getTypeRoute(type: ItemType): string { - switch (type) { - case ItemType.WIDGET: return 'widgets'; - case ItemType.SOLUTION_TEMPLATE: return 'solution-templates'; - case ItemType.CALCULATED_FIELD: return 'calculated-fields'; - case ItemType.ALARM_RULE: return 'alarm-rules'; - case ItemType.RULE_CHAIN: return 'rule-chains'; - case ItemType.DEVICE: return 'devices'; - default: return 'widgets'; - } - } - navigateToType(type: ItemType): void { - const search = this.searchText?.trim() || undefined; - void this.router.navigate(['/iot-hub', this.getTypeRoute(type)], { queryParams: { search } }); - } + + // Installed items getInstalledItem(item: MpItemVersionView): IotHubInstalledItem | undefined { @@ -281,7 +447,7 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { error: () => { this.isLoading = false; this.hasError = true; - this.resultGroups = []; + this.results = []; this.totalElements = 0; } }); @@ -291,30 +457,22 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { const sort = this.sortOptions[this.selectedSortIndex]; const sortOrder: SortOrder = { property: sort.value, direction: sort.direction }; const pageLink = new PageLink(this.pageSize, this.pageIndex, text.trim() || null, sortOrder); - const query = new MpItemVersionQuery(pageLink, { creatorId: this.creatorId || undefined }); + const query = new MpItemVersionQuery(pageLink, { + creatorId: this.creatorId || undefined, + // Empty sets are left off the query entirely - an empty array would narrow to nothing. + types: this.activeTypes.size ? [...this.activeTypes] : undefined, + categories: this.activeCategories.size ? [...this.activeCategories] : undefined, + useCases: this.activeUseCases.size ? [...this.activeUseCases] : undefined + }); return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true, ignoreErrors: true }); } private applyResults(data: MpItemVersionView[], totalElements: number): void { this.totalElements = totalElements; - this.resultGroups = this.groupResults(data); + this.results = data; this.isLoading = false; } - private groupResults(items: MpItemVersionView[]): SearchResultGroup[] { - const groupMap = new Map(); - for (const item of items) { - let list = groupMap.get(item.type); - if (!list) { - list = []; - groupMap.set(item.type, list); - } - list.push(item); - } - return TYPE_ORDER - .filter(type => groupMap.has(type)) - .map(type => ({ type, items: groupMap.get(type) })); - } private loadInstalledItems(): void { const config = { ignoreLoading: true }; diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html index d91164a6c3..51d834e8ed 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html @@ -96,7 +96,10 @@
- + +

{{ 'iot-hub.published-items' | translate }} ({{ creator.publishedCount }})

diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index cf4007b511..995ee4395d 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -85,37 +85,54 @@ } @else { @for (group of searchResultGroups; track group.type) { - - @for (item of group.items; track item.id) { - - @if (isCompactType(item.type)) { -
- {{ getCompactIcon(item) }} + + + {{ getSearchGroupLabel(group.type) }} + @if (group.remaining > 0) { + + {{ 'iot-hub.section-more' | translate:{ count: group.remaining } }} + chevron_right + + } + + + @for (item of group.items; track item.id) { + + @if (isCompactType(item.type)) { +
+ {{ getCompactIcon(item) }} +
+ } @else { +
+ @if (getItemImage(item); as imgUrl) { + + } @else { + {{ getItemTypeIcon(item.type) }} + } +
+ } +
+ {{ item.name }} + + person + {{ item.creatorDisplayName }} +
- } @else { -
- @if (getItemImage(item); as imgUrl) { - - } @else { - {{ getItemTypeIcon(item.type) }} - } -
- } -
- {{ item.name }} - - person - {{ item.creatorDisplayName }} - -
-
- } + + } +
} }
diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss index de032d8f1a..d8934e82ff 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss @@ -242,6 +242,41 @@ line-height: 20px; letter-spacing: 0.25px; color: rgba(0, 0, 0, 0.54); + // The header spans the panel so the count can sit against the right edge. Material's own + // label span is only as wide as its text. + width: 100%; + } + } + + // Section header — the label IS the link into the type page: title left, how much is not shown + // plus a chevron right. There is deliberately no per-section "see all" row under the items; + // six of those on one panel is what this variant was chosen to avoid. + .tb-search-popup-group-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16px; + width: 100%; + cursor: pointer; + outline: none; + } + + .tb-search-popup-group-more { + display: flex; + align-items: center; + gap: 2px; + flex-shrink: 0; + font-size: 12px; + font-weight: 500; + line-height: 16px; + letter-spacing: 0.25px; + color: $tb-primary-color; + + .mat-icon { + width: 18px; + height: 18px; + font-size: 18px; + line-height: 18px; } } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index fffd19c021..b4ecd8ca98 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -35,6 +35,10 @@ interface HeroTypeConfig { interface SearchResultGroup { type: ItemType; items: MpItemVersionView[]; + /** Rows of this type behind the answer, from the response's typeTotal. */ + total: number; + /** total - items.length, floored at 0. Zero means the header shows no "+N more". */ + remaining: number; } const SEARCH_GROUP_ORDER: ItemType[] = [ @@ -42,6 +46,11 @@ const SEARCH_GROUP_ORDER: ItemType[] = [ ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN ]; +/** Relevance ranking. Sent only while the field has text: with an empty field the backend + * substitutes the install count anyway, and this component knows the field state, so it sends + * the honest value rather than leaning on that safety net. */ +const RELEVANCE = 'relevance'; + @Component({ selector: 'tb-iot-hub-home', standalone: false, @@ -156,9 +165,16 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { distinctUntilChanged(), switchMap(text => { this.searchLoading = true; - const sortOrder: SortOrder = { property: 'totalInstallCount', direction: Direction.DESC }; - const pageLink = new PageLink(10, 0, text.trim() || null, sortOrder); - const query = new MpItemVersionQuery(pageLink); + const trimmed = text.trim(); + // Two states, one panel: popularity answers "what is worth looking at" with an empty + // field, relevance answers "what did I ask for" once there is one. + const sortOrder: SortOrder = trimmed + ? { property: RELEVANCE, direction: Direction.DESC } + : { property: 'totalInstallCount', direction: Direction.DESC }; + // The server sizes a grouped answer itself - the top rows of every type, one screen - so + // this page size is ignored, and page must stay 0 (a non-zero page is a 400). + const pageLink = new PageLink(10, 0, trimmed || null, sortOrder); + const query = new MpItemVersionQuery(pageLink, { grouped: true }); return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true }); }) ).subscribe(result => { @@ -237,6 +253,17 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { void this.router.navigate(['/iot-hub/search'], { queryParams: { search } }); } + /** + * The section header is the way into the rest of a type - the panel carries no per-section + * "see all" row, which would put six identical calls to action on one panel. The query goes + * with it, so the type page opens on the same search rather than on the whole type. + */ + navigateToSection(type: ItemType): void { + this.searchAutoTrigger?.closePanel(); + const search = this.searchText?.trim() || undefined; + void this.router.navigate(['/iot-hub', this.getTypeRoute(type)], { queryParams: { search } }); + } + isCompactType(type: ItemType): boolean { return type === ItemType.CALCULATED_FIELD || type === ItemType.ALARM_RULE @@ -523,6 +550,11 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { }); } + /** + * Reads the sections the server built. It no longer decides membership - a grouped response + * arrives already capped at four per type - so all this does is put the types in the panel's + * fixed order and carry each one's typeTotal onto the header. + */ private groupSearchResults(items: MpItemVersionView[]): SearchResultGroup[] { const groupMap = new Map(); for (const item of items) { @@ -538,6 +570,12 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { } return SEARCH_GROUP_ORDER .filter(type => groupMap.has(type)) - .map(type => ({ type, items: groupMap.get(type) })); + .map(type => { + const groupItems = groupMap.get(type); + // Every row of a type carries the same typeTotal. The fallback keeps a non-grouped + // response rendering correctly - which is what a stale backend would send. + const total = groupItems[0].typeTotal ?? groupItems.length; + return { type, items: groupItems, total, remaining: Math.max(0, total - groupItems.length) }; + }); } } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss index 1e617fb1f3..b824aade8c 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss @@ -8,12 +8,18 @@ height: 100%; } +// Same frame as the type pages (iot-hub-items-page): one even padding on the card, the hero +// inside it, and the component below pulled out to the card's edges. It replaces four +// breakpoints' worth of hand-written negative margins — one per element that needed to reach +// an edge — and is why the filter rail, the heading and the grid now line up by construction. +.tb-search-page { + padding: 40px 40px 48px; +} // Back button .tb-search-back-btn { align-self: flex-start; - margin-top: 40px; - margin-left: 123px; + margin-left: -8px; } // Title @@ -30,100 +36,37 @@ color: rgba(0, 0, 0, 0.54); } +// Full bleed, and it pads its own rows back in through --tb-search-side-pad. The rail and the +// dividers are the parts that must reach the edge; everything else lines up with the hero. tb-iot-hub-search { flex: 1; min-height: 0; - padding-left: 123px; - padding-right: 123px; - - ::ng-deep { - .tb-search-divider { - margin-left: -123px; - margin-right: -123px; - } - - .tb-results-container { - padding-right: 123px; - padding-bottom: 40px; - margin-right: -123px; - } - } -} - -// Responsive -@media #{$mat-lt-xxl} { - .tb-search-back-btn { - margin-left: 40px; - } - - tb-iot-hub-search { - padding-left: 40px; - padding-right: 40px; - - ::ng-deep { - .tb-search-divider { - margin-left: -40px; - margin-right: -40px; - } - - .tb-results-container { - padding-right: 40px; - margin-right: -40px; - } - } - } + --tb-search-side-pad: 40px; + margin-left: -40px; + margin-right: -40px; } @media #{$mat-lt-lg} { - .tb-search-back-btn { - margin-top: 24px; - margin-left: 24px; + .tb-search-page { + padding: 24px 24px 32px; } tb-iot-hub-search { - padding-left: 24px; - padding-right: 24px; - - ::ng-deep { - .tb-search-divider { - margin-left: -24px; - margin-right: -24px; - } - - .tb-results-container { - padding-right: 24px; - padding-bottom: 24px; - margin-right: -24px; - } - } + --tb-search-side-pad: 24px; + margin-left: -24px; + margin-right: -24px; } } @media #{$mat-lt-sm} { .tb-search-page { + padding: 16px 16px 24px; gap: 16px; } - .tb-search-back-btn { - margin-top: 16px; - margin-left: 16px; - } - tb-iot-hub-search { - padding-left: 16px; - padding-right: 16px; - - ::ng-deep { - .tb-search-divider { - margin-left: -16px; - margin-right: -16px; - } - - .tb-results-container { - padding-right: 16px; - padding-bottom: 16px; - margin-right: -16px; - } - } + --tb-search-side-pad: 16px; + margin-left: -16px; + margin-right: -16px; } } diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts index 349a4f62e8..b98fc30952 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts @@ -106,6 +106,12 @@ export interface MpItemVersionView { resources: MpItemVersionResource[]; relatedItems?: string[]; checksum?: string; + /** + * Rows of this item's type behind a grouped response. A flat read does not omit it — the + * column is projected as NULL and serialised, so the field arrives as `null` there. Read it + * with `??`, never with a truthiness test. + */ + typeTotal?: number | null; } // 404 body shapes returned by the public listing item-version endpoint @@ -118,7 +124,15 @@ export interface ListingItemVersionNotFound { } export interface MpItemVersionQueryOptions { + /** Single item type, for a surface pinned to one (the type pages, the add-item dialog). */ type?: string; + /** + * Several item types at once, for a cross-type surface whose Type facet is multi-select. + * Emitted as a repeated `type` parameter, which is the shape the backend reads + * (`@RequestParam List type`). Kept separate from `type` rather than widening it, + * so a caller that means "exactly this type" cannot be handed an array by accident. + */ + types?: string[]; peOnly?: boolean; creatorId?: string; categories?: string[]; @@ -131,6 +145,13 @@ export interface MpItemVersionQueryOptions { connectivity?: string[]; vendors?: string[]; scadaFirst?: boolean; + /** + * Ask for the top four of each item type in one response instead of a flat page. + * Every row then carries `typeTotal`, the number of rows of its type behind the answer, + * which is what the section header's "+N more" counts. Grouped responses are one screen: + * the backend rejects a non-zero `page`. + */ + grouped?: boolean; } export class MpItemVersionQuery { @@ -142,6 +163,9 @@ export class MpItemVersionQuery { if (o.type) { query += `&type=${o.type}`; } + if (o.types?.length) { + query += o.types.map(t => `&type=${encodeURIComponent(t)}`).join(''); + } if (o.peOnly != null) { query += `&peOnly=${o.peOnly}`; } @@ -178,6 +202,9 @@ export class MpItemVersionQuery { if (o.scadaFirst != null) { query += `&scadaFirst=${o.scadaFirst}`; } + if (o.grouped != null) { + query += `&grouped=${o.grouped}`; + } return query; } } 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 98f59ec8a9..e19cb64cff 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3708,6 +3708,7 @@ "search": "Search...", "search-published-items": "Search published items...", "see-all-results": "See all results", + "see-results-for": "See results for \"{{ search }}\"", "no-search-results": "No results found for '{{ search }}'", "no-items-available": "No items available", "search-results": "Search results", @@ -3730,6 +3731,7 @@ "type": "Type", "items-per-page": "Items per page", "filter": "Filter", + "clear-filters": "Clear filters", "available": "Available", "items-page-desc-widgets": "Jumpstart your IoT journey with pre-configured widgets designed for your industry. Deploy proven architectures instantly and focus your energy on what matters: your unique business logic.", "items-page-desc-dashboards": "Explore dashboards to find pre-built visualization templates and interactive UI layouts you can deploy in minutes to bring your IoT data to life.", @@ -3774,9 +3776,11 @@ "search-alarm-rules": "Search alarm rules...", "search-rule-chains": "Search rule chains...", "search-devices": "Search devices...", + "sort-most-relevant": "Most relevant", "sort-most-installed": "Most installed", "sort-newest": "Newest", "sort-name": "Name (A-Z)", + "section-more": "{ count, plural, =1 {+1 more} other {+# more} }", "type-filter-label": "Type", "category": "Category", "use-case": "Use case", From bb43fffa04ab6f3d62101e260b02ad2e359910f3 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 15 Sep 2026 12:45:34 +0300 Subject: [PATCH 02/23] fix(iot-hub): call the grouped versions endpoint The Hub answers a sectioned search at /api/versions/published/grouped rather than through a flag on the flat read. That endpoint takes the filters and a sort key only - it sizes its own answer - so the popup asks through its own API method and its own query string, and sends no page, page size or sort order. MpItemVersionGroupedView mirrors what comes back: the view plus typeTotal, always set, rather than the flat view with a nullable field and a comment about when it is null. MpItemVersionQueryOptions loses grouped with it. --- .../src/app/core/http/iot-hub-api.service.ts | 21 +++++++- .../pages/iot-hub/iot-hub-home.component.ts | 22 ++++----- .../models/iot-hub/iot-hub-version.models.ts | 49 +++++++++++++------ 3 files changed, 65 insertions(+), 27 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 33f19d285f..f4d87a5ce5 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 @@ -6,7 +6,7 @@ import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { PageData } from '@shared/models/page/page-data'; import { PageLink } from '@shared/models/page/page-link'; -import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; +import { MpItemVersionGroupedView, MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import { CreatorView } from '@shared/models/iot-hub/iot-hub-creator.models'; import { IotHubInstalledItem, InstallItemVersionResult, InstallPlan, InstallPlanResult, UpdateItemVersionResult, ItemPublishedVersionInfo } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { ItemType, ItemTypeFilterInfo, WidgetCategory } from '@shared/models/iot-hub/iot-hub-item.models'; @@ -81,6 +81,25 @@ export class IotHubApiService { ); } + /** + * The sectioned answer: at most four rows of each item type, every row carrying the size of its + * section. Its own endpoint, which is why this is its own method - it takes no page, page size + * or sort direction, and sending them would be sending what the server does not read. + */ + public getPublishedVersionsGrouped(query: MpItemVersionQuery, + config?: IotHubRequestConfig): Observable> { + if (query.options.tbVersion == null) { + query.options.tbVersion = tbVersionToInt(env.tbVersion); + } + if (query.options.peOnly == null) { + query.options.peOnly = false; + } + return this.http.get>( + `${this.baseUrl}/api/versions/published/grouped${query.toGroupedQuery()}`, + { params: this.buildParams(config) } + ); + } + public getFilterInfo(itemType: ItemType, config?: IotHubRequestConfig): Observable { const url = `${this.baseUrl}/api/item-listing/filterInfo/${itemType}` + `?peOnly=false&tbVersion=${tbVersionToInt(env.tbVersion)}`; diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index b4ecd8ca98..cf26d52bbe 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -9,7 +9,7 @@ import { debounceTime, distinctUntilChanged, 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'; -import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; +import { MpItemVersionGroupedView, MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import { getItemTypeIcon, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; @@ -34,7 +34,7 @@ interface HeroTypeConfig { interface SearchResultGroup { type: ItemType; - items: MpItemVersionView[]; + items: MpItemVersionGroupedView[]; /** Rows of this type behind the answer, from the response's typeTotal. */ total: number; /** total - items.length, floored at 0. Zero means the header shows no "+N more". */ @@ -62,7 +62,7 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { readonly ItemType = ItemType; searchText = ''; - searchResults: MpItemVersionView[] = []; + searchResults: MpItemVersionGroupedView[] = []; searchResultGroups: SearchResultGroup[] = []; searchLoaded = false; searchLoading = false; @@ -171,11 +171,10 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { const sortOrder: SortOrder = trimmed ? { property: RELEVANCE, direction: Direction.DESC } : { property: 'totalInstallCount', direction: Direction.DESC }; - // The server sizes a grouped answer itself - the top rows of every type, one screen - so - // this page size is ignored, and page must stay 0 (a non-zero page is a 400). + // The grouped endpoint sizes its own answer, so the page size here is never sent. const pageLink = new PageLink(10, 0, trimmed || null, sortOrder); - const query = new MpItemVersionQuery(pageLink, { grouped: true }); - return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true }); + const query = new MpItemVersionQuery(pageLink); + return this.iotHubApiService.getPublishedVersionsGrouped(query, { ignoreLoading: true }); }) ).subscribe(result => { this.searchResults = result.data; @@ -555,8 +554,8 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { * arrives already capped at four per type - so all this does is put the types in the panel's * fixed order and carry each one's typeTotal onto the header. */ - private groupSearchResults(items: MpItemVersionView[]): SearchResultGroup[] { - const groupMap = new Map(); + private groupSearchResults(items: MpItemVersionGroupedView[]): SearchResultGroup[] { + const groupMap = new Map(); for (const item of items) { if (!SEARCH_GROUP_ORDER.includes(item.type)) { continue; @@ -572,8 +571,9 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { .filter(type => groupMap.has(type)) .map(type => { const groupItems = groupMap.get(type); - // Every row of a type carries the same typeTotal. The fallback keeps a non-grouped - // response rendering correctly - which is what a stale backend would send. + // Every row of a type carries the same typeTotal, so the first one answers for the + // section. The fallback covers a backend too old to have the grouped endpoint, whose + // rows arrive without it. const total = groupItems[0].typeTotal ?? groupItems.length; return { type, items: groupItems, total, remaining: Math.max(0, total - groupItems.length) }; }); diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts index b98fc30952..4aaaeeaa62 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts @@ -106,12 +106,18 @@ export interface MpItemVersionView { resources: MpItemVersionResource[]; relatedItems?: string[]; checksum?: string; +} + +/** + * A row of a grouped search: the view plus the size of the section it belongs to. Its own type + * rather than a nullable field on the view, matching what the endpoint returns. + */ +export interface MpItemVersionGroupedView extends MpItemVersionView { /** - * Rows of this item's type behind a grouped response. A flat read does not omit it — the - * column is projected as NULL and serialised, so the field arrives as `null` there. Read it - * with `??`, never with a truthiness test. + * Rows of this row's item type behind the answer — what a "+N more" header subtracts the + * shown rows from. Always set: the grouped endpoint projects it for every row it returns. */ - typeTotal?: number | null; + typeTotal: number; } // 404 body shapes returned by the public listing item-version endpoint @@ -145,20 +151,36 @@ export interface MpItemVersionQueryOptions { connectivity?: string[]; vendors?: string[]; scadaFirst?: boolean; - /** - * Ask for the top four of each item type in one response instead of a flat page. - * Every row then carries `typeTotal`, the number of rows of its type behind the answer, - * which is what the section header's "+N more" counts. Grouped responses are one screen: - * the backend rejects a non-zero `page`. - */ - grouped?: boolean; } export class MpItemVersionQuery { constructor(public pageLink: PageLink, public options: MpItemVersionQueryOptions = {}) {} + /** + * The grouped endpoint's query string: the filters, plus a sort key. It sizes its own answer, + * so it declares no page or page size, and each key's direction is fixed by its chain, so it + * declares no sort order either - sending any of the three would be sending something the + * server does not read. + */ + public toGroupedQuery(): string { + const text = this.pageLink.textSearch?.trim(); + let query = '?'; + if (text?.length) { + query += `textSearch=${encodeURIComponent(text)}&`; + } + if (this.pageLink.sortOrder) { + query += `sortProperty=${this.pageLink.sortOrder.property}&`; + } + return query + this.filtersToQuery(); + } + public toQuery(): string { - let query = this.pageLink.toQuery(); + return this.pageLink.toQuery() + this.filtersToQuery(); + } + + /** Every filter, as `&name=value` pairs - shared by both query strings above. */ + private filtersToQuery(): string { + let query = ''; const o = this.options; if (o.type) { query += `&type=${o.type}`; @@ -202,9 +224,6 @@ export class MpItemVersionQuery { if (o.scadaFirst != null) { query += `&scadaFirst=${o.scadaFirst}`; } - if (o.grouped != null) { - query += `&grouped=${o.grouped}`; - } return query; } } From 6eaf10dfd4572a6ec9e4fc3e9a6998b08e7c7b55 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 15 Sep 2026 13:01:05 +0300 Subject: [PATCH 03/23] fix(iot-hub): keep the hero search alive when a request fails --- .../home/pages/iot-hub/iot-hub-home.component.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index cf26d52bbe..6108a9bd4e 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -4,9 +4,10 @@ import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/co import { Router } from '@angular/router'; import { MatAutocompleteTrigger } from '@angular/material/autocomplete'; import { BreakpointObserver } from '@angular/cdk/layout'; -import { forkJoin, Subject, Subscription } from 'rxjs'; -import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; +import { forkJoin, of, Subject, Subscription } from 'rxjs'; +import { catchError, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; import { MediaBreakpoints } from '@shared/models/constants'; +import { emptyPageData } from '@shared/models/page/page-data'; import { PageLink } from '@shared/models/page/page-link'; import { Direction, SortOrder } from '@shared/models/page/sort-order'; import { MpItemVersionGroupedView, MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; @@ -174,7 +175,11 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { // The grouped endpoint sizes its own answer, so the page size here is never sent. const pageLink = new PageLink(10, 0, trimmed || null, sortOrder); const query = new MpItemVersionQuery(pageLink); - return this.iotHubApiService.getPublishedVersionsGrouped(query, { ignoreLoading: true }); + // A failed request must not end the subscription: the interceptor reports it, and the + // panel goes back to an empty answer the next keystroke can replace. + return this.iotHubApiService.getPublishedVersionsGrouped(query, { ignoreLoading: true }).pipe( + catchError(() => of(emptyPageData())) + ); }) ).subscribe(result => { this.searchResults = result.data; @@ -572,9 +577,8 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { .map(type => { const groupItems = groupMap.get(type); // Every row of a type carries the same typeTotal, so the first one answers for the - // section. The fallback covers a backend too old to have the grouped endpoint, whose - // rows arrive without it. - const total = groupItems[0].typeTotal ?? groupItems.length; + // section. + const total = groupItems[0].typeTotal; return { type, items: groupItems, total, remaining: Math.max(0, total - groupItems.length) }; }); } From 09dbf7b0c06e40c5d16e1e3f7568b6cb1cd3d4a3 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 15 Sep 2026 13:20:56 +0300 Subject: [PATCH 04/23] refactor(iot-hub): read the hero popup's sections as sections --- .../src/app/core/http/iot-hub-api.service.ts | 13 ++--- .../pages/iot-hub/iot-hub-home.component.html | 2 +- .../pages/iot-hub/iot-hub-home.component.ts | 51 +++++++------------ .../models/iot-hub/iot-hub-version.models.ts | 15 +++--- 4 files changed, 34 insertions(+), 47 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 f4d87a5ce5..987f9f214b 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 @@ -6,7 +6,7 @@ import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { PageData } from '@shared/models/page/page-data'; import { PageLink } from '@shared/models/page/page-link'; -import { MpItemVersionGroupedView, MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; +import { MpItemVersionQuery, MpItemVersionSection, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import { CreatorView } from '@shared/models/iot-hub/iot-hub-creator.models'; import { IotHubInstalledItem, InstallItemVersionResult, InstallPlan, InstallPlanResult, UpdateItemVersionResult, ItemPublishedVersionInfo } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { ItemType, ItemTypeFilterInfo, WidgetCategory } from '@shared/models/iot-hub/iot-hub-item.models'; @@ -82,19 +82,20 @@ export class IotHubApiService { } /** - * The sectioned answer: at most four rows of each item type, every row carrying the size of its - * section. Its own endpoint, which is why this is its own method - it takes no page, page size - * or sort direction, and sending them would be sending what the server does not read. + * The sectioned answer: one section per item type, in the server's order, each holding at most + * four rows and the total behind them. Its own endpoint, which is why this is its own method - + * it takes no page, page size or sort direction, and sending them would be sending what the + * server does not read. */ public getPublishedVersionsGrouped(query: MpItemVersionQuery, - config?: IotHubRequestConfig): Observable> { + config?: IotHubRequestConfig): Observable { if (query.options.tbVersion == null) { query.options.tbVersion = tbVersionToInt(env.tbVersion); } if (query.options.peOnly == null) { query.options.peOnly = false; } - return this.http.get>( + return this.http.get( `${this.baseUrl}/api/versions/published/grouped${query.toGroupedQuery()}`, { params: this.buildParams(config) } ); diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index 995ee4395d..07905a8d21 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -72,7 +72,7 @@ - } @else if (searchResults.length === 0 && searchLoaded) { + } @else if (searchResultGroups.length === 0 && searchLoaded) {
search_off diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index 6108a9bd4e..47c1ca06e1 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -7,10 +7,9 @@ import { BreakpointObserver } from '@angular/cdk/layout'; import { forkJoin, of, Subject, Subscription } from 'rxjs'; import { catchError, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; import { MediaBreakpoints } from '@shared/models/constants'; -import { emptyPageData } from '@shared/models/page/page-data'; import { PageLink } from '@shared/models/page/page-link'; import { Direction, SortOrder } from '@shared/models/page/sort-order'; -import { MpItemVersionGroupedView, MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; +import { MpItemVersionQuery, MpItemVersionSection, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import { getItemTypeIcon, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; @@ -35,14 +34,16 @@ interface HeroTypeConfig { interface SearchResultGroup { type: ItemType; - items: MpItemVersionGroupedView[]; - /** Rows of this type behind the answer, from the response's typeTotal. */ + items: MpItemVersionView[]; + /** Rows of this type behind the answer, from the section's total. */ total: number; /** total - items.length, floored at 0. Zero means the header shows no "+N more". */ remaining: number; } -const SEARCH_GROUP_ORDER: ItemType[] = [ +/** The types this popup lays out. A section of anything else is dropped rather than rendered + * without a label - the platform publishes no dashboards. Order comes from the server. */ +const SEARCH_GROUP_TYPES: ItemType[] = [ ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, ItemType.WIDGET, ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN ]; @@ -63,7 +64,6 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { readonly ItemType = ItemType; searchText = ''; - searchResults: MpItemVersionGroupedView[] = []; searchResultGroups: SearchResultGroup[] = []; searchLoaded = false; searchLoading = false; @@ -178,12 +178,11 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { // A failed request must not end the subscription: the interceptor reports it, and the // panel goes back to an empty answer the next keystroke can replace. return this.iotHubApiService.getPublishedVersionsGrouped(query, { ignoreLoading: true }).pipe( - catchError(() => of(emptyPageData())) + catchError(() => of([] as MpItemVersionSection[])) ); }) - ).subscribe(result => { - this.searchResults = result.data; - this.searchResultGroups = this.groupSearchResults(result.data); + ).subscribe(sections => { + this.searchResultGroups = this.toResultGroups(sections); this.searchLoaded = true; this.searchLoading = false; }); @@ -559,27 +558,15 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { * arrives already capped at four per type - so all this does is put the types in the panel's * fixed order and carry each one's typeTotal onto the header. */ - private groupSearchResults(items: MpItemVersionGroupedView[]): SearchResultGroup[] { - const groupMap = new Map(); - for (const item of items) { - if (!SEARCH_GROUP_ORDER.includes(item.type)) { - continue; - } - let list = groupMap.get(item.type); - if (!list) { - list = []; - groupMap.set(item.type, list); - } - list.push(item); - } - return SEARCH_GROUP_ORDER - .filter(type => groupMap.has(type)) - .map(type => { - const groupItems = groupMap.get(type); - // Every row of a type carries the same typeTotal, so the first one answers for the - // section. - const total = groupItems[0].typeTotal; - return { type, items: groupItems, total, remaining: Math.max(0, total - groupItems.length) }; - }); + private toResultGroups(sections: MpItemVersionSection[]): SearchResultGroup[] { + return sections + .filter(section => SEARCH_GROUP_TYPES.includes(section.itemType)) + .map(section => ({ + type: section.itemType, + items: section.items, + total: section.total, + remaining: Math.max(0, section.total - section.items.length) + })); } + } diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts index 4aaaeeaa62..4c1f79718b 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts @@ -109,15 +109,14 @@ export interface MpItemVersionView { } /** - * A row of a grouped search: the view plus the size of the section it belongs to. Its own type - * rather than a nullable field on the view, matching what the endpoint returns. + * One item type's share of a grouped search: the rows to show and how many exist behind them. + * A grouped answer is a list of these, in the server's section order, and a type nothing matched + * has no section — so a "+N more" header is `total - items.length`. */ -export interface MpItemVersionGroupedView extends MpItemVersionView { - /** - * Rows of this row's item type behind the answer — what a "+N more" header subtracts the - * shown rows from. Always set: the grouped endpoint projects it for every row it returns. - */ - typeTotal: number; +export interface MpItemVersionSection { + itemType: ItemType; + total: number; + items: MpItemVersionView[]; } // 404 body shapes returned by the public listing item-version endpoint From 19cbfc403a7da9076a7250ce8ffcdae728914da9 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 15 Sep 2026 13:44:36 +0300 Subject: [PATCH 05/23] fix(iot-hub): keep the grouped query string well-formed without text --- .../shared/models/iot-hub/iot-hub-version.models.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts index 4c1f79718b..c48a232098 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts @@ -163,14 +163,16 @@ export class MpItemVersionQuery { */ public toGroupedQuery(): string { const text = this.pageLink.textSearch?.trim(); - let query = '?'; + const parts: string[] = []; if (text?.length) { - query += `textSearch=${encodeURIComponent(text)}&`; + parts.push(`textSearch=${encodeURIComponent(text)}`); } if (this.pageLink.sortOrder) { - query += `sortProperty=${this.pageLink.sortOrder.property}&`; + parts.push(`sortProperty=${this.pageLink.sortOrder.property}`); } - return query + this.filtersToQuery(); + // filtersToQuery() emits leading ampersands, which is what toQuery() needs after a page link; + // here they may be the whole query string, so the first one is dropped. + return `?${`${parts.join('&')}${this.filtersToQuery()}`.replace(/^&/, '')}`; } public toQuery(): string { From 3af7b71740c6a3541a584b568247ee09c3b1c6ac Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 15 Sep 2026 14:00:41 +0300 Subject: [PATCH 06/23] refactor(iot-hub): give the grouped read its own query, without a page link --- .../src/app/core/http/iot-hub-api.service.ts | 39 +++-- .../pages/iot-hub/iot-hub-home.component.ts | 15 +- .../models/iot-hub/iot-hub-version.models.ts | 137 +++++++++--------- 3 files changed, 104 insertions(+), 87 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 987f9f214b..25c6253bae 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 @@ -6,7 +6,13 @@ import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { PageData } from '@shared/models/page/page-data'; import { PageLink } from '@shared/models/page/page-link'; -import { MpItemVersionQuery, MpItemVersionSection, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; +import { + MpItemVersionGroupedQuery, + MpItemVersionQuery, + MpItemVersionQueryOptions, + MpItemVersionSection, + MpItemVersionView +} from '@shared/models/iot-hub/iot-hub-version.models'; import { CreatorView } from '@shared/models/iot-hub/iot-hub-creator.models'; import { IotHubInstalledItem, InstallItemVersionResult, InstallPlan, InstallPlanResult, UpdateItemVersionResult, ItemPublishedVersionInfo } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { ItemType, ItemTypeFilterInfo, WidgetCategory } from '@shared/models/iot-hub/iot-hub-item.models'; @@ -69,12 +75,7 @@ export class IotHubApiService { } public getPublishedVersions(query: MpItemVersionQuery, config?: IotHubRequestConfig): Observable> { - if (query.options.tbVersion == null) { - query.options.tbVersion = tbVersionToInt(env.tbVersion); - } - if (query.options.peOnly == null) { - query.options.peOnly = false; - } + this.applyPlatformFilters(query.options); return this.http.get>( `${this.baseUrl}/api/versions/published${query.toQuery()}`, { params: this.buildParams(config) } @@ -87,20 +88,28 @@ export class IotHubApiService { * it takes no page, page size or sort direction, and sending them would be sending what the * server does not read. */ - public getPublishedVersionsGrouped(query: MpItemVersionQuery, + public getPublishedVersionsGrouped(query: MpItemVersionGroupedQuery, config?: IotHubRequestConfig): Observable { - if (query.options.tbVersion == null) { - query.options.tbVersion = tbVersionToInt(env.tbVersion); - } - if (query.options.peOnly == null) { - query.options.peOnly = false; - } + this.applyPlatformFilters(query.options); return this.http.get( - `${this.baseUrl}/api/versions/published/grouped${query.toGroupedQuery()}`, + `${this.baseUrl}/api/versions/published/grouped${query.toQuery()}`, { params: this.buildParams(config) } ); } + /** + * What this platform can install, filled in for a caller that did not say: items built for a + * newer ThingsBoard, and PE-only items on a CE instance, cannot be installed from here. + */ + private applyPlatformFilters(options: MpItemVersionQueryOptions): void { + if (options.tbVersion == null) { + options.tbVersion = tbVersionToInt(env.tbVersion); + } + if (options.peOnly == null) { + options.peOnly = false; + } + } + public getFilterInfo(itemType: ItemType, config?: IotHubRequestConfig): Observable { const url = `${this.baseUrl}/api/item-listing/filterInfo/${itemType}` + `?peOnly=false&tbVersion=${tbVersionToInt(env.tbVersion)}`; diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index 47c1ca06e1..f36a8738a1 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -9,7 +9,12 @@ import { catchError, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/ import { MediaBreakpoints } from '@shared/models/constants'; import { PageLink } from '@shared/models/page/page-link'; import { Direction, SortOrder } from '@shared/models/page/sort-order'; -import { MpItemVersionQuery, MpItemVersionSection, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; +import { + MpItemVersionGroupedQuery, + MpItemVersionQuery, + MpItemVersionSection, + MpItemVersionView +} from '@shared/models/iot-hub/iot-hub-version.models'; import { getItemTypeIcon, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; @@ -169,12 +174,8 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { const trimmed = text.trim(); // Two states, one panel: popularity answers "what is worth looking at" with an empty // field, relevance answers "what did I ask for" once there is one. - const sortOrder: SortOrder = trimmed - ? { property: RELEVANCE, direction: Direction.DESC } - : { property: 'totalInstallCount', direction: Direction.DESC }; - // The grouped endpoint sizes its own answer, so the page size here is never sent. - const pageLink = new PageLink(10, 0, trimmed || null, sortOrder); - const query = new MpItemVersionQuery(pageLink); + const sortProperty = trimmed ? RELEVANCE : 'totalInstallCount'; + const query = new MpItemVersionGroupedQuery({}, trimmed, sortProperty); // A failed request must not end the subscription: the interceptor reports it, and the // panel goes back to an empty answer the next keystroke can replace. return this.iotHubApiService.getPublishedVersionsGrouped(query, { ignoreLoading: true }).pipe( diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts index c48a232098..b194ab0371 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts @@ -152,79 +152,86 @@ export interface MpItemVersionQueryOptions { scadaFirst?: boolean; } +/** Every filter, as `&name=value` pairs - shared by both query shapes below. */ +function filtersToQuery(o: MpItemVersionQueryOptions): string { + let query = ''; + if (o.type) { + query += `&type=${o.type}`; + } + if (o.types?.length) { + query += o.types.map(t => `&type=${encodeURIComponent(t)}`).join(''); + } + if (o.peOnly != null) { + query += `&peOnly=${o.peOnly}`; + } + if (o.creatorId) { + query += `&creatorId=${o.creatorId}`; + } + if (o.categories?.length) { + query += o.categories.map(c => `&categories=${encodeURIComponent(c)}`).join(''); + } + if (o.useCases?.length) { + query += o.useCases.map(u => `&useCases=${encodeURIComponent(u)}`).join(''); + } + if (o.cfTypes?.length) { + query += o.cfTypes.map(t => `&cfTypes=${encodeURIComponent(t)}`).join(''); + } + if (o.widgetTypes?.length) { + query += o.widgetTypes.map(t => `&widgetTypes=${encodeURIComponent(t)}`).join(''); + } + if (o.ruleChainTypes?.length) { + query += o.ruleChainTypes.map(t => `&ruleChainTypes=${encodeURIComponent(t)}`).join(''); + } + if (o.tbVersion != null) { + query += `&tbVersion=${o.tbVersion}`; + } + if (o.hardwareTypes?.length) { + query += o.hardwareTypes.map(ht => `&hardwareTypes=${encodeURIComponent(ht)}`).join(''); + } + if (o.connectivity?.length) { + query += o.connectivity.map(c => `&connectivity=${encodeURIComponent(c)}`).join(''); + } + if (o.vendors?.length) { + query += o.vendors.map(v => `&vendors=${encodeURIComponent(v)}`).join(''); + } + if (o.scadaFirst != null) { + query += `&scadaFirst=${o.scadaFirst}`; + } + return query; +} + +/** A paged read: the filters, and the page to cut out of them. */ export class MpItemVersionQuery { constructor(public pageLink: PageLink, public options: MpItemVersionQueryOptions = {}) {} - /** - * The grouped endpoint's query string: the filters, plus a sort key. It sizes its own answer, - * so it declares no page or page size, and each key's direction is fixed by its chain, so it - * declares no sort order either - sending any of the three would be sending something the - * server does not read. - */ - public toGroupedQuery(): string { - const text = this.pageLink.textSearch?.trim(); + public toQuery(): string { + return this.pageLink.toQuery() + filtersToQuery(this.options); + } +} + +/** + * A sectioned read: the filters, what to search for, and which key orders a section. + * + * No `PageLink`, because the grouped endpoint takes no page and no page size - it sizes its own + * answer from the section limit - and no sort direction either, each key's direction being fixed + * by the chain the server switches on. A page link here could only carry values nobody sends. + */ +export class MpItemVersionGroupedQuery { + constructor(public options: MpItemVersionQueryOptions = {}, + public textSearch?: string, + public sortProperty?: string) {} + + public toQuery(): string { const parts: string[] = []; + const text = this.textSearch?.trim(); if (text?.length) { parts.push(`textSearch=${encodeURIComponent(text)}`); } - if (this.pageLink.sortOrder) { - parts.push(`sortProperty=${this.pageLink.sortOrder.property}`); + if (this.sortProperty) { + parts.push(`sortProperty=${this.sortProperty}`); } - // filtersToQuery() emits leading ampersands, which is what toQuery() needs after a page link; + // filtersToQuery() emits leading ampersands, which is what a page link needs in front of it; // here they may be the whole query string, so the first one is dropped. - return `?${`${parts.join('&')}${this.filtersToQuery()}`.replace(/^&/, '')}`; - } - - public toQuery(): string { - return this.pageLink.toQuery() + this.filtersToQuery(); - } - - /** Every filter, as `&name=value` pairs - shared by both query strings above. */ - private filtersToQuery(): string { - let query = ''; - const o = this.options; - if (o.type) { - query += `&type=${o.type}`; - } - if (o.types?.length) { - query += o.types.map(t => `&type=${encodeURIComponent(t)}`).join(''); - } - if (o.peOnly != null) { - query += `&peOnly=${o.peOnly}`; - } - if (o.creatorId) { - query += `&creatorId=${o.creatorId}`; - } - if (o.categories?.length) { - query += o.categories.map(c => `&categories=${encodeURIComponent(c)}`).join(''); - } - if (o.useCases?.length) { - query += o.useCases.map(u => `&useCases=${encodeURIComponent(u)}`).join(''); - } - if (o.cfTypes?.length) { - query += o.cfTypes.map(t => `&cfTypes=${encodeURIComponent(t)}`).join(''); - } - if (o.widgetTypes?.length) { - query += o.widgetTypes.map(t => `&widgetTypes=${encodeURIComponent(t)}`).join(''); - } - if (o.ruleChainTypes?.length) { - query += o.ruleChainTypes.map(t => `&ruleChainTypes=${encodeURIComponent(t)}`).join(''); - } - if (o.tbVersion != null) { - query += `&tbVersion=${o.tbVersion}`; - } - if (o.hardwareTypes?.length) { - query += o.hardwareTypes.map(ht => `&hardwareTypes=${encodeURIComponent(ht)}`).join(''); - } - if (o.connectivity?.length) { - query += o.connectivity.map(c => `&connectivity=${encodeURIComponent(c)}`).join(''); - } - if (o.vendors?.length) { - query += o.vendors.map(v => `&vendors=${encodeURIComponent(v)}`).join(''); - } - if (o.scadaFirst != null) { - query += `&scadaFirst=${o.scadaFirst}`; - } - return query; + return `?${`${parts.join('&')}${filtersToQuery(this.options)}`.replace(/^&/, '')}`; } } From 26aad8e47500093f841cfd3d824a99dd955ec568 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 15 Sep 2026 16:31:42 +0300 Subject: [PATCH 07/23] docs(iot-hub): say what the section mapper does now --- .../app/modules/home/pages/iot-hub/iot-hub-home.component.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index f36a8738a1..ebd8485dd7 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -555,9 +555,8 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { } /** - * Reads the sections the server built. It no longer decides membership - a grouped response - * arrives already capped at four per type - so all this does is put the types in the panel's - * fixed order and carry each one's typeTotal onto the header. + * Reads the sections the server built: they arrive capped and in the order to render them, so + * this only drops the types this panel has no layout for and works out each header's "+N more". */ private toResultGroups(sections: MpItemVersionSection[]): SearchResultGroup[] { return sections From e5a4a7e48920f32a046755df2794060157f3cc3a Mon Sep 17 00:00:00 2001 From: dshvaika Date: Wed, 16 Sep 2026 13:26:27 +0300 Subject: [PATCH 08/23] refactor(iot-hub): one sort menu and one cross-type list, and two failures the panels now survive The sort options lived in three arrays behind three identical local interfaces, and 'relevance' was spelled four ways; the six cross-type item types lived in two more arrays, byte-identical and renamed by this branch on both sides. Adding one option here meant editing three places, and a seventh item type would have needed two. All of it moves to iot-hub-item.models.ts as SortOption, IOT_HUB_SORT_OPTIONS, RELEVANCE_SORT_PROPERTY and CROSS_TYPE_ITEM_TYPES. The type list stays separate from CREATOR_VISIBLE_ITEM_TYPES, which holds the same six: that one is a membership test carrying the type tabs' order, this one is display order with DEVICE leading, and folding them together would have silently reordered the Type facet. The hero popup now sends relevance in both states like every other surface, rather than switching on whether the field has text. Both spellings ask the server for the same rows - with no text it substitutes the install count either way - so this is the code agreeing with the decision recorded on TBIOH-33, not a behaviour change. Two failures that were not survivable: - One of the six getFilterInfo calls failing emptied the whole filter panel. forkJoin is all-or-nothing, so typeOptions went unassigned although it needs no server data, and the i?.categories guards below could never fire. Each request now carries its own catchError, which is what those guards already expected. - A section arriving without items would have thrown inside a subscribe callback, out of reach of the catchError upstream, leaving the popup on its spinner. The response is an unvalidated cast of a new endpoint, so items is defaulted. The facet list held a Set the host mutated in place, which works only while that component is on default change detection. The host now hands over a new Set per toggle. SearchResultGroup.total went unread, and @for takes a track expression rather than a TrackByFunction. --- .../src/app/core/http/iot-hub-api.service.ts | 7 +- .../dashboard-widget-select.component.ts | 31 ++--- .../iot-hub/iot-hub-browse.component.ts | 31 ++--- .../iot-hub/iot-hub-facet-list.component.html | 2 +- .../iot-hub/iot-hub-facet-list.component.ts | 7 +- .../iot-hub/iot-hub-search.component.ts | 106 ++++++++---------- .../pages/iot-hub/iot-hub-home.component.ts | 55 +++++---- .../models/iot-hub/iot-hub-item.models.ts | 44 ++++++++ 8 files changed, 139 insertions(+), 144 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 25c6253bae..7f3b299962 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 @@ -83,10 +83,9 @@ export class IotHubApiService { } /** - * The sectioned answer: one section per item type, in the server's order, each holding at most - * four rows and the total behind them. Its own endpoint, which is why this is its own method - - * it takes no page, page size or sort direction, and sending them would be sending what the - * server does not read. + * The sectioned answer: one section per item type, in the server's order, each capped by the + * server and carrying the total behind that cap. Its own endpoint, which takes no page, page + * size or sort direction. */ public getPublishedVersionsGrouped(query: MpItemVersionGroupedQuery, config?: IotHubRequestConfig): Observable { diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts index 57c621eb8d..7cb0eddd2b 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts @@ -21,7 +21,12 @@ import { ItemSizeStrategy } from '@shared/components/grid/scroll-grid.component' import { coerceBoolean } from '@shared/decorators/coercion'; import { TranslateService } from '@ngx-translate/core'; import { MpItemVersionQuery, MpItemVersionView, widgetTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models'; -import { ItemType, FilterParamInfo, WidgetCategory } from '@shared/models/iot-hub/iot-hub-item.models'; +import { + FilterParamInfo, + IOT_HUB_SORT_OPTIONS, + ItemType, + WidgetCategory +} from '@shared/models/iot-hub/iot-hub-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; @@ -38,12 +43,6 @@ type selectWidgetMode = 'installed' | 'iotHub'; type installedSubMode = 'default' | 'allWidgets'; type iotHubSubMode = 'default' | 'allWidgets' | 'installed' | 'category'; -interface WidgetSelectSortOption { - value: string; - label: string; - direction: Direction; -} - const LOGICAL_ALL_WIDGETS = '__logical_all_widgets__'; const LOGICAL_INSTALLED_FROM_IOT_HUB = '__logical_installed_from_iot_hub__'; @@ -89,22 +88,10 @@ export class DashboardWidgetSelectComponent { searchFocused = false; /** - * Relevance leads, and is therefore the default (iotHubSelectedSortIndex starts at 0). This - * panel has a search field, which is the only thing relevance ranks by; with the field empty - * the backend substitutes the install count, so the picker opens on the order it always had. - * - * scadaFirst is unaffected: the backend prepends it ahead of the caller's sort AND ahead of - * relevance, so a SCADA context still lists SCADA widgets first. - * - * Fourth copy of this list — the others are in TbIotHubSearchComponent, TbIotHubBrowseComponent - * and IOT_HUB_SORT_OPTIONS on thingsboard.io. Kept in step by hand. + * scadaFirst is unaffected by the sort: the backend prepends it ahead of the caller's key AND + * ahead of relevance, so a SCADA context still lists SCADA widgets first. */ - iotHubSortOptions: WidgetSelectSortOption[] = [ - { value: 'relevance', label: 'iot-hub.sort-most-relevant', direction: Direction.DESC }, - { value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC }, - { value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC }, - { value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC } - ]; + readonly iotHubSortOptions = IOT_HUB_SORT_OPTIONS; iotHubSelectedSortIndex = 0; @Input() diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts index 785bd48660..63f561ddad 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts @@ -4,10 +4,15 @@ import { AfterViewInit, Component, ElementRef, EventEmitter, Input, NgZone, OnDe import { Subject } from 'rxjs'; import { debounceTime, takeUntil } from 'rxjs/operators'; import { PageLink } from '@shared/models/page/page-link'; -import { Direction, SortOrder } from '@shared/models/page/sort-order'; +import { SortOrder } from '@shared/models/page/sort-order'; import { PageData } from '@shared/models/page/page-data'; import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; -import { ItemType, FilterParamInfo, CREATOR_VISIBLE_ITEM_TYPES } from '@shared/models/iot-hub/iot-hub-item.models'; +import { + CREATOR_VISIBLE_ITEM_TYPES, + FilterParamInfo, + IOT_HUB_SORT_OPTIONS, + ItemType +} from '@shared/models/iot-hub/iot-hub-item.models'; import { widgetTypeTranslations, cfTypeTranslations, ruleChainTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models'; import { IotHubInstalledItem, DeviceInstalledItemDescriptor } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; @@ -16,12 +21,6 @@ import { ActivatedRoute, Router } from '@angular/router'; import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; import { filterIotHubItemsBySearch, groupIotHubFilterItems, IotHubFilterGroup } from '@home/components/iot-hub/iot-hub-utils'; -interface SortOption { - value: string; - label: string; - direction: Direction; -} - @Component({ selector: 'tb-iot-hub-browse', standalone: false, @@ -126,21 +125,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy activeHardwareTypes = new Set(); activeVendors = new Set(); - /** - * Relevance leads, and is therefore the default (selectedSortIndex starts at 0). A type page - * carries a search field, which is the only thing relevance ranks by; with the field empty the - * backend substitutes the install count, so browsing keeps the order it always had. - * - * Kept in step by hand with TbIotHubSearchComponent's list and with IOT_HUB_SORT_OPTIONS on - * thingsboard.io — three copies, because the two products share no code and this component - * predates the search page's list. - */ - sortOptions: SortOption[] = [ - { value: 'relevance', label: 'iot-hub.sort-most-relevant', direction: Direction.DESC }, - { value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC }, - { value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC }, - { value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC } - ]; + readonly sortOptions = IOT_HUB_SORT_OPTIONS; typeTabs: { type: ItemType; label: string }[] = CREATOR_VISIBLE_ITEM_TYPES.map(t => ({ type: t, diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html index dfde943c22..8468ddc04b 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html @@ -22,7 +22,7 @@ }
- @for (option of visibleOptions; track trackByKey($index, option)) { + @for (option of visibleOptions; track option.key) { {{ labelFor(option.key) }} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts index b9b5625fce..7bcafacccc 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts @@ -26,7 +26,8 @@ export class TbIotHubFacetListComponent { @Input() options: FilterParamInfo[] = []; - /** Keys the host currently has selected. Read, never written. */ + /** Keys the host currently has selected. Read, never written - the host hands over a new Set + * on every toggle rather than mutating this one. */ @Input() selected = new Set(); /** @@ -76,8 +77,4 @@ export class TbIotHubFacetListComponent { onToggle(key: string): void { this.toggled.emit(key); } - - trackByKey(_index: number, option: FilterParamInfo): string { - return option.key; - } } diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts index 6326a52010..7378d45d60 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts @@ -3,36 +3,22 @@ import { Component, OnInit, OnDestroy, Input, Output, EventEmitter, ViewChild, ElementRef } from '@angular/core'; import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; -import { forkJoin, Subject, Subscription } from 'rxjs'; -import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; +import { forkJoin, of, Subject, Subscription } from 'rxjs'; +import { catchError, debounceTime, distinctUntilChanged } from 'rxjs/operators'; import { PageLink } from '@shared/models/page/page-link'; -import { Direction, SortOrder } from '@shared/models/page/sort-order'; +import { SortOrder } from '@shared/models/page/sort-order'; import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; -import { FilterParamInfo, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; +import { + CROSS_TYPE_ITEM_TYPES, + FilterParamInfo, + IOT_HUB_SORT_OPTIONS, + ItemType, + itemTypeTranslations +} from '@shared/models/iot-hub/iot-hub-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubActionsService } from './iot-hub-actions.service'; -interface SortOption { - value: string; - label: string; - direction: Direction; -} - -/** Sort property served by relevance ranking. With no text the backend substitutes the - * install count, so it is a safe default in both states. */ -const RELEVANCE = 'relevance'; - -/** - * Item types the Type facet offers, in the order every other cross-type surface uses (the hero - * popup's sections, the site's). Fixed rather than sorted by count: the counts move with the - * catalogue and a facet whose options reshuffle under the pointer is hard to use. - */ -const FACET_ITEM_TYPES: ItemType[] = [ - ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, ItemType.WIDGET, - ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN -]; - /** * Rows a page holds, as a multiple of the column count, so a page always ends on a complete row. * The floor keeps a one- or two-column phone layout from falling to three cards a page. @@ -84,7 +70,8 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { return [base, base * 2, base * 4]; } - /** Filter panel state. Empty sets mean "no filter", which is what the query object expects. */ + // Filter panel state. Empty sets mean "no filter", which is what the query object expects. + /** Narrow widths only: the facet panel is a block above the results, not a sidebar. */ filtersOpen = false; typeOptions: FilterParamInfo[] = []; @@ -94,18 +81,7 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { activeCategories = new Set(); activeUseCases = new Set(); - sortOptions: SortOption[] = [ - { value: RELEVANCE, label: 'iot-hub.sort-most-relevant', direction: Direction.DESC }, - { value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC }, - { value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC }, - { value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC } - ]; - /** - * Relevance is the default in BOTH states, which is why nothing here switches on whether the - * search field has text. With text it ranks the answer; without it the backend substitutes the - * install count, so a user who never opens this menu sees the order they always saw while - * browsing and the best matches once they type. - */ + readonly sortOptions = IOT_HUB_SORT_OPTIONS; selectedSortIndex = 0; installedWidgets: IotHubInstalledItem[] = []; @@ -156,15 +132,18 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { }; onTypeToggle(key: string): void { - this.toggle(this.activeTypes, key); + this.activeTypes = this.toggled(this.activeTypes, key); + this.reloadFromFirstPage(); } onCategoryToggle(key: string): void { - this.toggle(this.activeCategories, key); + this.activeCategories = this.toggled(this.activeCategories, key); + this.reloadFromFirstPage(); } onUseCaseToggle(key: string): void { - this.toggle(this.activeUseCases, key); + this.activeUseCases = this.toggled(this.activeUseCases, key); + this.reloadFromFirstPage(); } get activeFilterCount(): number { @@ -175,19 +154,26 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { if (this.activeFilterCount === 0) { return; } - this.activeTypes.clear(); - this.activeCategories.clear(); - this.activeUseCases.clear(); - this.pageIndex = 0; - this.loadResults(); + this.activeTypes = new Set(); + this.activeCategories = new Set(); + this.activeUseCases = new Set(); + this.reloadFromFirstPage(); } - private toggle(set: Set, key: string): void { - if (set.has(key)) { - set.delete(key); - } else { - set.add(key); + /** + * Returns a new Set rather than mutating the one passed in: TbIotHubFacetListComponent holds + * this very instance as an @Input, and a mutation it cannot see is a trap for the first person + * to put that component on OnPush. + */ + private toggled(set: Set, key: string): Set { + const next = new Set(set); + if (!next.delete(key)) { + next.add(key); } + return next; + } + + private reloadFromFirstPage(): void { this.pageIndex = 0; this.loadResults(); } @@ -197,27 +183,30 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { * answers are merged here, the way the site merges the same six at build time. Counts are * deliberately not rendered: filterInfo takes no text query, so beside a searched result they * would be the whole catalogue's numbers pretending to describe this answer. + * + * Each request carries its own catchError so one type's failure costs that type's categories + * and use cases, not the panel: a bare forkJoin is all-or-nothing, and the Type facet needs no + * server data at all. */ private loadFilterInfo(): void { const config = { ignoreLoading: true, ignoreErrors: true }; forkJoin( - FACET_ITEM_TYPES.map(type => this.iotHubApiService.getFilterInfo(type, config)) + CROSS_TYPE_ITEM_TYPES.map(type => + this.iotHubApiService.getFilterInfo(type, config).pipe(catchError(() => of(null))) + ) ).subscribe({ next: infos => { // Every item type is offered, not only the ones filterInfo reports facets for: the // endpoint describes a type's categories and vendors, never how many items it has, and // a type whose items carry no categories would vanish from its own facet. - this.typeOptions = FACET_ITEM_TYPES.map(type => ({ + this.typeOptions = CROSS_TYPE_ITEM_TYPES.map(type => ({ key: type as string, totalItems: 0, totalInstallCount: 0 })); this.categoryOptions = this.mergeFacet(infos.map(i => i?.categories)); this.useCaseOptions = this.mergeFacet(infos.map(i => i?.useCases)); - }, - // A facet panel that failed to load is an empty panel, never a broken page: the grid - // beside it answers the query perfectly well without it. - error: () => {} + } }); } @@ -348,11 +337,6 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { this.loadResults(); } - // Type helpers - - - - // Installed items getInstalledItem(item: MpItemVersionView): IotHubInstalledItem | undefined { switch (item.type) { diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index ebd8485dd7..577ed03a08 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -15,7 +15,13 @@ import { MpItemVersionSection, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; -import { getItemTypeIcon, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; +import { + CROSS_TYPE_ITEM_TYPES, + getItemTypeIcon, + ItemType, + itemTypeTranslations, + RELEVANCE_SORT_PROPERTY +} from '@shared/models/iot-hub/iot-hub-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { TranslateService } from '@ngx-translate/core'; @@ -40,24 +46,10 @@ interface HeroTypeConfig { interface SearchResultGroup { type: ItemType; items: MpItemVersionView[]; - /** Rows of this type behind the answer, from the section's total. */ - total: number; - /** total - items.length, floored at 0. Zero means the header shows no "+N more". */ + /** How many rows of this type the header offers beyond the ones shown. Zero renders no "+N more". */ remaining: number; } -/** The types this popup lays out. A section of anything else is dropped rather than rendered - * without a label - the platform publishes no dashboards. Order comes from the server. */ -const SEARCH_GROUP_TYPES: ItemType[] = [ - ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, ItemType.WIDGET, - ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN -]; - -/** Relevance ranking. Sent only while the field has text: with an empty field the backend - * substitutes the install count anyway, and this component knows the field state, so it sends - * the honest value rather than leaning on that safety net. */ -const RELEVANCE = 'relevance'; - @Component({ selector: 'tb-iot-hub-home', standalone: false, @@ -172,10 +164,10 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { switchMap(text => { this.searchLoading = true; const trimmed = text.trim(); - // Two states, one panel: popularity answers "what is worth looking at" with an empty - // field, relevance answers "what did I ask for" once there is one. - const sortProperty = trimmed ? RELEVANCE : 'totalInstallCount'; - const query = new MpItemVersionGroupedQuery({}, trimmed, sortProperty); + // Relevance in both states, the same value every other IoT Hub surface sends: with an + // empty field the backend substitutes the install count, so this panel opens on + // popularity without having to say so. See TBIOH-33 for the decision. + const query = new MpItemVersionGroupedQuery({}, trimmed, RELEVANCE_SORT_PROPERTY); // A failed request must not end the subscription: the interceptor reports it, and the // panel goes back to an empty answer the next keystroke can replace. return this.iotHubApiService.getPublishedVersionsGrouped(query, { ignoreLoading: true }).pipe( @@ -556,17 +548,24 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { /** * Reads the sections the server built: they arrive capped and in the order to render them, so - * this only drops the types this panel has no layout for and works out each header's "+N more". + * this only drops the types this panel has no layout for - the platform publishes no dashboards + * - and works out each header's "+N more". + * + * `items` is defaulted because the response is an unvalidated cast of a new endpoint, and a + * throw here lands in a subscribe callback, where it would leave the panel on its spinner + * rather than reaching the catchError upstream. */ private toResultGroups(sections: MpItemVersionSection[]): SearchResultGroup[] { return sections - .filter(section => SEARCH_GROUP_TYPES.includes(section.itemType)) - .map(section => ({ - type: section.itemType, - items: section.items, - total: section.total, - remaining: Math.max(0, section.total - section.items.length) - })); + .filter(section => CROSS_TYPE_ITEM_TYPES.includes(section.itemType)) + .map(section => { + const items = section.items ?? []; + return { + type: section.itemType, + items, + remaining: Math.max(0, section.total - items.length) + }; + }); } } diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts index abdddc1734..68ca5c0158 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: Copyright The Thingsboard Authors // SPDX-License-Identifier: Apache-2.0 +import { Direction } from '@shared/models/page/sort-order'; + export enum ItemType { WIDGET = 'WIDGET', DASHBOARD = 'DASHBOARD', @@ -54,6 +56,48 @@ export const CREATOR_VISIBLE_ITEM_TYPES: ItemType[] = [ ItemType.RULE_CHAIN, ]; +/** + * Item types a surface that mixes them lays out, in the order they are shown. Distinct from + * CREATOR_VISIBLE_ITEM_TYPES, which is the same six as a membership test and carries the type + * tabs' own order: here DEVICE leads, matching the hero popup's sections and the website. + */ +export const CROSS_TYPE_ITEM_TYPES: ItemType[] = [ + ItemType.DEVICE, + ItemType.SOLUTION_TEMPLATE, + ItemType.WIDGET, + ItemType.CALCULATED_FIELD, + ItemType.ALARM_RULE, + ItemType.RULE_CHAIN, +]; + +/** Sort property served by relevance ranking. */ +export const RELEVANCE_SORT_PROPERTY = 'relevance'; + +export interface SortOption { + value: string; + label: string; + direction: Direction; +} + +/** + * The sort menu every IoT Hub surface carrying a search field offers, and the order it offers + * them in: the first entry is the default each surface opens on. + * + * Relevance is that default in both states. With text it ranks the answer; with none the backend + * substitutes the install count, so a surface opens on the order it opened on before and nothing + * switches on the field state. Agreed with the product owner and recorded on TBIOH-33, which + * supersedes that ticket's SCOPE-IN 2, SCOPE-IN 4 and AC-4. + * + * One list rather than one per surface: a new key must reach all of them, and the surface that + * missed it would keep a different default without failing. + */ +export const IOT_HUB_SORT_OPTIONS: SortOption[] = [ + { value: RELEVANCE_SORT_PROPERTY, label: 'iot-hub.sort-most-relevant', direction: Direction.DESC }, + { value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC }, + { value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC }, + { value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC } +]; + export interface FilterParamInfo { key: string; totalItems: number; From 2d72735070a4dca445ee832b1e58a9b5df37079b Mon Sep 17 00:00:00 2001 From: dshvaika Date: Wed, 16 Sep 2026 13:26:27 +0300 Subject: [PATCH 09/23] style(iot-hub): close the formatting left behind by the layout and grouping changes The results container kept its old indentation after being wrapped in .tb-search-layout, so it read as a sibling of the wrapper and the two closing tags lined up at the same depth while closing different elements. The popup's @for sat in an ng-container carrying no directive. Removing the -compact rule left a blank line before the closing brace in four places. --- .../iot-hub/iot-hub-search.component.html | 80 +++++++++---------- .../iot-hub/iot-hub-search.component.scss | 4 - .../pages/iot-hub/iot-hub-home.component.html | 48 ++++++----- 3 files changed, 63 insertions(+), 69 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html index 5963b7c003..ca98ed1c0c 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html @@ -142,48 +142,48 @@ } -
- - @if (hasError) { -
-
-

{{ 'iot-hub.network-server-unavailable' | translate }}

-

{{ 'iot-hub.network-server-unavailable-text' | translate }}

- -
- } +
+ + @if (hasError) { +
+
+

{{ 'iot-hub.network-server-unavailable' | translate }}

+

{{ 'iot-hub.network-server-unavailable-text' | translate }}

+ +
+ } - - @if (!hasError && totalElements === 0 && searchText?.trim()) { -
-
-

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

-

{{ 'iot-hub.try-adjusting-search' | translate }}

-
- } + + @if (!hasError && totalElements === 0 && searchText?.trim()) { +
+
+

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

+

{{ 'iot-hub.try-adjusting-search' | translate }}

+
+ } - - @if (results.length > 0) { -
- @for (item of results; track item.id) { - - - } -
- } -
+ + @if (results.length > 0) { +
+ @for (item of results; track item.id) { + + + } +
+ } +
diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss index 2556d03f3d..32c7a51458 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss @@ -279,21 +279,18 @@ @media #{$mat-gt-xxl} { .tb-search-card-grid { grid-template-columns: repeat(6, 1fr); - } } @media #{$mat-lt-xl} { .tb-search-card-grid { grid-template-columns: repeat(4, 1fr); - } } @media #{$mat-lt-xmd} { .tb-search-card-grid { grid-template-columns: repeat(3, 1fr); - } } @@ -316,7 +313,6 @@ .tb-search-card-grid { grid-template-columns: repeat(2, 1fr); - } } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index 07905a8d21..c4d720976b 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -97,32 +97,30 @@ } - - @for (item of group.items; track item.id) { - - @if (isCompactType(item.type)) { -
- {{ getCompactIcon(item) }} -
- } @else { -
- @if (getItemImage(item); as imgUrl) { - - } @else { - {{ getItemTypeIcon(item.type) }} - } -
- } -
- {{ item.name }} - - person - {{ item.creatorDisplayName }} - + @for (item of group.items; track item.id) { + + @if (isCompactType(item.type)) { +
+ {{ getCompactIcon(item) }}
-
- } - + } @else { +
+ @if (getItemImage(item); as imgUrl) { + + } @else { + {{ getItemTypeIcon(item.type) }} + } +
+ } +
+ {{ item.name }} + + person + {{ item.creatorDisplayName }} + +
+ + } } } From edf81221ad1bd23b70eb150b2ceaafe1fa04dc92 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Wed, 16 Sep 2026 13:27:19 +0300 Subject: [PATCH 10/23] fix(iot-hub): encode creatorId and type into the query string These were the only two of the thirteen fields interpolated raw, and creatorId is not an internal value: iot-hub-browse and the creator profile both read it straight off the route with nothing between the URL and the request, so a crafted id could close the parameter and append its own. The UUID shape is a convention here, not something this code enforces. --- .../src/app/shared/models/iot-hub/iot-hub-version.models.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts index b194ab0371..a5afaea23c 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts @@ -156,7 +156,7 @@ export interface MpItemVersionQueryOptions { function filtersToQuery(o: MpItemVersionQueryOptions): string { let query = ''; if (o.type) { - query += `&type=${o.type}`; + query += `&type=${encodeURIComponent(o.type)}`; } if (o.types?.length) { query += o.types.map(t => `&type=${encodeURIComponent(t)}`).join(''); @@ -165,7 +165,7 @@ function filtersToQuery(o: MpItemVersionQueryOptions): string { query += `&peOnly=${o.peOnly}`; } if (o.creatorId) { - query += `&creatorId=${o.creatorId}`; + query += `&creatorId=${encodeURIComponent(o.creatorId)}`; } if (o.categories?.length) { query += o.categories.map(c => `&categories=${encodeURIComponent(c)}`).join(''); From dab4ec72f9df0089c6651b29e794c766e5e601e6 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Wed, 16 Sep 2026 14:38:38 +0300 Subject: [PATCH 11/23] refactor(iot-hub): drop the creatorId query parameter nothing produces The type page adopted `?creatorId=` from the URL whenever its input was unbound. Nothing in the platform builds such a URL: the only navigations carrying query parameters send `search` and `itemType`, and the creator profile scopes its list by binding the component's input rather than by navigating. The branch was reachable only by typing the parameter in by hand, and there it rescoped a Hub-wide type page with no visible sign of why the counts had changed. Both live callers - the creator profile and the add-item dialog - bind the input, which the removed code deferred to in any case. --- .../home/components/iot-hub/iot-hub-browse.component.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts index 63f561ddad..2be0408826 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts @@ -171,12 +171,6 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy if (params['search']) { this.textSearch = params['search']; } - // A search section header on a creator profile lands here scoped to that creator. The - // bound input wins: an embedded host (the add-item dialog) sets its own scope, and must - // not pick one up from whatever URL happens to be open behind the dialog. - if (!this.creatorId && !this.embedded && params['creatorId']) { - this.creatorId = params['creatorId']; - } if (this.fixedSubType) { const subtypes = this.getActiveSubtypes(); if (subtypes) { From 6aae7899bf9c8a55bef1904b4a9be3db74153838 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Wed, 16 Sep 2026 14:38:38 +0300 Subject: [PATCH 12/23] docs(iot-hub): cite what a reader can find Two comments explaining why relevance is the default in both states pointed at an internal ticket, one of them at three numbered sections of it that are being rewritten precisely because the code no longer matches them. Neither pointer is reachable from this repository, and the numbering is due to move. The reasoning stays inline, with the accepted cost named: the menu reads "Most relevant" over an install-ordered list until the user types. --- .../modules/home/pages/iot-hub/iot-hub-home.component.ts | 4 ++-- .../src/app/shared/models/iot-hub/iot-hub-item.models.ts | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index 577ed03a08..91511f533d 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -165,8 +165,8 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { this.searchLoading = true; const trimmed = text.trim(); // Relevance in both states, the same value every other IoT Hub surface sends: with an - // empty field the backend substitutes the install count, so this panel opens on - // popularity without having to say so. See TBIOH-33 for the decision. + // empty field the backend serves the install count under this key, so the panel opens on + // popularity without this component having to know it. const query = new MpItemVersionGroupedQuery({}, trimmed, RELEVANCE_SORT_PROPERTY); // A failed request must not end the subscription: the interceptor reports it, and the // panel goes back to an empty answer the next keystroke can replace. diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts index 68ca5c0158..8fbe84440b 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts @@ -83,10 +83,11 @@ export interface SortOption { * The sort menu every IoT Hub surface carrying a search field offers, and the order it offers * them in: the first entry is the default each surface opens on. * - * Relevance is that default in both states. With text it ranks the answer; with none the backend - * substitutes the install count, so a surface opens on the order it opened on before and nothing - * switches on the field state. Agreed with the product owner and recorded on TBIOH-33, which - * supersedes that ticket's SCOPE-IN 2, SCOPE-IN 4 and AC-4. + * Relevance is that default with or without text. With text it ranks the answer; with none the + * backend serves the install count under the same key, so a surface opens on the order it opened + * on before and nothing here switches on the field state. The cost is a menu reading "Most + * relevant" over an install-ordered list until the user types; the alternative - flipping the + * selector once text appears - moves a control the user did not touch and reorders nothing. * * One list rather than one per surface: a new key must reach all of them, and the surface that * missed it would keep a different default without failing. From c5a3bea6dfed1da693bc6263c36e0fa2bc9708f1 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Wed, 16 Sep 2026 15:22:10 +0300 Subject: [PATCH 13/23] fix(iot-hub): let the keyboard reach every row of the search popup The popup keeps focus in the input and walks its rows with an active-descendant key manager, which only knows about options. A section header written as a span with role="button" and tabindex="0" is therefore unreachable: the arrow keys skip it, its keyup.enter can never fire because it can never hold focus, and Tab does not help since leaving the input closes the panel. That header is the only way from the popup into a type page, so without a mouse there was no way in at all. The footer had the same shape, though its action is also on the input's own Enter. The header also sat inside the group's label element, which is presentational, so the section's name came out as the header's whole text - "Devices +12 more" - wrapping a control nobody could operate. Header and footer are now options like every other row. They take part in arrow navigation, they read as part of the list, and the group wrapper goes away with the label it was distorting. Rows also acted on (click) alone. Pressing Enter on a highlighted result runs _selectViaInteraction, which is not a DOM click, so the card never opened from the keyboard. Every row now acts on (onSelectionChange) guarded by isUserInput, one path for pointer and keyboard both. Enter in the field needed a guard to go with that: the trigger acts on keydown and this handler runs on keyup, which the trigger's preventDefault does not stop, so one Enter would have opened a result and then navigated away from it. --- .../pages/iot-hub/iot-hub-home.component.html | 76 +++++++++---------- .../pages/iot-hub/iot-hub-home.component.scss | 66 +++++++--------- .../pages/iot-hub/iot-hub-home.component.ts | 9 +++ 3 files changed, 75 insertions(+), 76 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index c4d720976b..b2be21ac32 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -85,53 +85,51 @@ } @else { @for (group of searchResultGroups; track group.type) { - - - {{ getSearchGroupLabel(group.type) }} - @if (group.remaining > 0) { - - {{ 'iot-hub.section-more' | translate:{ count: group.remaining } }} - chevron_right - - } - - @for (item of group.items; track item.id) { - - @if (isCompactType(item.type)) { -
- {{ getCompactIcon(item) }} -
- } @else { -
- @if (getItemImage(item); as imgUrl) { - - } @else { - {{ getItemTypeIcon(item.type) }} - } -
- } -
- {{ item.name }} - - person - {{ item.creatorDisplayName }} - -
-
+ + {{ getSearchGroupLabel(group.type) }} + @if (group.remaining > 0) { + + {{ 'iot-hub.section-more' | translate:{ count: group.remaining } }} + chevron_right + } -
+ + @for (item of group.items; track item.id) { + + @if (isCompactType(item.type)) { +
+ {{ getCompactIcon(item) }} +
+ } @else { +
+ @if (getItemImage(item); as imgUrl) { + + } @else { + {{ getItemTypeIcon(item.type) }} + } +
+ } +
+ {{ item.name }} + + person + {{ item.creatorDisplayName }} + +
+
+ } } } - +
diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss index d8934e82ff..98b4ab0389 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss @@ -220,45 +220,32 @@ 0 114px 46px 0 rgba(0, 0, 0, 0.01), 0 178px 50px 0 rgba(0, 0, 0, 0); - // Section group — 12px gap between groups - .mat-mdc-optgroup + .mat-mdc-optgroup .mat-mdc-optgroup-label { + // Section header — an option like every other row, not a button beside them, so the arrow keys + // reach it and a screen reader reads it in the list. It IS the way into the type page: title + // left, how much is not shown plus a chevron right. There is deliberately no per-section + // "see all" row under the items; six of those on one panel is what this variant avoids. + // Design: 14px Medium, 0.25 tracking, black-tertiary, 4px V / 16px H, 12px above each section. + .mat-mdc-option.tb-search-popup-group-header { + padding: 4px 16px; + min-height: 28px; margin-top: 12px; + + &:first-child { + margin-top: 0; + } + + .mdc-list-item__primary-text { + justify-content: space-between; + } } - // Section title — Design: 14px Medium, 0.25 tracking, black-tertiary, 4px V / 16px H - .mat-mdc-optgroup .mat-mdc-optgroup-label { - padding: 4px 16px; - min-height: 28px; + .tb-search-popup-group-label { font-size: 14px; font-weight: 500; line-height: 20px; letter-spacing: 0.25px; color: rgba(0, 0, 0, 0.54); white-space: nowrap; - - .mdc-list-item__primary-text { - font-size: 14px; - font-weight: 500; - line-height: 20px; - letter-spacing: 0.25px; - color: rgba(0, 0, 0, 0.54); - // The header spans the panel so the count can sit against the right edge. Material's own - // label span is only as wide as its text. - width: 100%; - } - } - - // Section header — the label IS the link into the type page: title left, how much is not shown - // plus a chevron right. There is deliberately no per-section "see all" row under the items; - // six of those on one panel is what this variant was chosen to avoid. - .tb-search-popup-group-header { - display: flex; - align-items: center; - justify-content: space-between; - gap: 16px; - width: 100%; - cursor: pointer; - outline: none; } .tb-search-popup-group-more { @@ -281,7 +268,7 @@ } // Item row — Design: 8px V / 16px H, 16px gap, centered - .mat-mdc-optgroup .mat-mdc-option:not(.mat-mdc-option-multiple) { + .mat-mdc-option:not(.mat-mdc-option-multiple) { padding: 8px 16px; min-height: auto; height: auto; @@ -426,26 +413,31 @@ } // Footer — Design: 40px h, 8px V / 16px H, 1px top border, tb-primary text - .tb-search-popup-footer { + .mat-mdc-option.tb-search-popup-footer { position: sticky; bottom: 0; + z-index: 1; border-top: 1px solid rgba(0, 0, 0, 0.12); height: 40px; min-height: 40px; padding: 8px 16px; - display: flex; - align-items: center; - justify-content: flex-start; font-size: 14px; font-weight: 500; line-height: 20px; letter-spacing: 0.25px; color: $tb-primary-color; - cursor: pointer; background: white; white-space: nowrap; - &:hover { + .mdc-list-item__primary-text { + justify-content: flex-start; + font: inherit; + letter-spacing: inherit; + color: inherit; + } + + &:hover:not(.mdc-list-item--disabled), + &.mat-mdc-option-active:not(.mdc-list-item--disabled) { background: #f5f5f5; } } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index 91511f533d..8e6038ef96 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -239,7 +239,16 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { setTimeout(() => this.searchAutoTrigger?.openPanel()); } + /** + * Enter in the field opens the search page - unless the panel has an option highlighted, which + * the trigger has already acted on during keydown. This runs on keyup, which preventDefault on + * the keydown does not stop, so without the guard one Enter would both open a result and + * navigate away from it. + */ onSearch(): void { + if (this.searchAutoTrigger?.activeOption) { + return; + } this.seeAllResults(); } From 14e3025a24842b66d4df2c67fec1faace5e6a4a1 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Thu, 17 Sep 2026 13:15:27 +0300 Subject: [PATCH 14/23] fix(iot-hub): make the popup's Enter guard and row padding hold on their own Three things from the re-review, two of them introduced by the commit that turned the popup's header and footer into options. **The Enter guard never fired.** It asked the autocomplete trigger for its active option during keyup, but the trigger clears that inside the same keydown - it calls _selectViaInteraction and then _resetActiveItem, which with no autoActiveFirstOption sets the active index to -1. So the guard always fell through, and one Enter on a highlighted row opened it and then navigated away from it. That is worse than the behaviour before, where the click handler simply never ran. The row that acts now records it through rowSelectedByUser, which does not depend on the order the two handlers run in, and typing clears the flag since a pointer selection leaves no keyup behind it. **The header's own padding was overridden.** Under one ancestor chain, `.mat-mdc-option.tb-search-popup-group-header` and `.mat-mdc-option:not(.mat-mdc-option-multiple)` both weigh (0,4,0), and the second was declared later, so every section header shipped 8px taller than the 4px the comment above it documents - with up to six of them in a 424px panel. The catch-all could not match the old span header; it matches an option. Each row kind now carries its own class and the shared parts sit in one rule, so nothing here rests on source order. The footer had the same collision and only won by being declared last. **The hover-scrollbar block is a mixin.** This branch added a second byte-identical copy of it. Both now call tb-iot-hub-hover-scrollbar from the partial they already import. The mixin records what is deliberately NOT settled here: whether these panels should keep a thumb that is invisible until hover, and whether to add the standardised scrollbar-width / scrollbar-color that Firefox reads, is a question for the IoT Hub filter UI as a whole - iot-hub-browse and dashboard-widget-select carry the same treatment and predate this branch. --- .../components/iot-hub/_iot-hub-common.scss | 36 +++++++++++++++++ .../iot-hub/iot-hub-facet-list.component.scss | 27 +------------ .../iot-hub/iot-hub-search.component.scss | 27 +------------ .../pages/iot-hub/iot-hub-home.component.html | 8 ++-- .../pages/iot-hub/iot-hub-home.component.scss | 40 +++++++++++-------- .../pages/iot-hub/iot-hub-home.component.ts | 31 +++++++++++--- 6 files changed, 91 insertions(+), 78 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss b/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss index d247f20112..96697ebe74 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss @@ -119,3 +119,39 @@ pointer-events: none; } } + +// Scroll area that shows its thumb only while the container is hovered — the filter panels' +// own treatment, kept here so the two that use it cannot drift apart. +// +// Not the app-wide one: theme.scss keeps its thumb permanently visible. Whether these panels +// should do the same, and whether to add the standardised scrollbar-width / scrollbar-color +// that Firefox reads, is a question for the IoT Hub filter UI as a whole rather than for one +// panel; iot-hub-browse and dashboard-widget-select carry copies of this same treatment. +@mixin tb-iot-hub-hover-scrollbar { + &::-webkit-scrollbar { + width: 6px; + } + + &::-webkit-scrollbar-track { + background-color: transparent; + } + + &::-webkit-scrollbar-thumb { + background-color: transparent; + border-radius: 3px; + } + + &:hover { + &::-webkit-scrollbar-track { + background-color: rgba(0, 0, 0, 0.04); + } + + &::-webkit-scrollbar-thumb { + background-color: rgba(0, 0, 0, 0.2); + + &:hover { + background-color: rgba(0, 0, 0, 0.35); + } + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss index e5fc43f803..4df80a68e1 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss @@ -45,32 +45,7 @@ overflow-y: auto; } - &::-webkit-scrollbar { - width: 6px; - } - - &::-webkit-scrollbar-track { - background-color: transparent; - } - - &::-webkit-scrollbar-thumb { - background-color: transparent; - border-radius: 3px; - } - - &:hover { - &::-webkit-scrollbar-track { - background-color: rgba(0, 0, 0, 0.04); - } - - &::-webkit-scrollbar-thumb { - background-color: rgba(0, 0, 0, 0.2); - - &:hover { - background-color: rgba(0, 0, 0, 0.35); - } - } - } + @include tb-iot-hub-hover-scrollbar; } .tb-iot-hub-facet-search { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss index 32c7a51458..3f946404ad 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss @@ -221,32 +221,7 @@ overflow-y: auto; padding-top: 20px; - &::-webkit-scrollbar { - width: 6px; - } - - &::-webkit-scrollbar-track { - background-color: transparent; - } - - &::-webkit-scrollbar-thumb { - background-color: transparent; - border-radius: 3px; - } - - &:hover { - &::-webkit-scrollbar-track { - background-color: rgba(0, 0, 0, 0.04); - } - - &::-webkit-scrollbar-thumb { - background-color: rgba(0, 0, 0, 0.2); - - &:hover { - background-color: rgba(0, 0, 0, 0.35); - } - } - } + @include tb-iot-hub-hover-scrollbar; } // The close button and heading belong to the narrow layout only. diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index b2be21ac32..564f89ca46 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -86,7 +86,7 @@ } @else { @for (group of searchResultGroups; track group.type) { + (onSelectionChange)="rowSelectedByUser($event) && navigateToSection(group.type)"> {{ getSearchGroupLabel(group.type) }} @if (group.remaining > 0) { @@ -96,8 +96,8 @@ } @for (item of group.items; track item.id) { - + @if (isCompactType(item.type)) {
{{ getCompactIcon(item) }} @@ -123,7 +123,7 @@ } } + (onSelectionChange)="rowSelectedByUser($event) && seeAllResults()"> @if (searchText?.trim(); as query) { {{ 'iot-hub.see-results-for' | translate:{ search: query } }} } @else { diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss index 98b4ab0389..8a89ebae44 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss @@ -220,6 +220,27 @@ 0 114px 46px 0 rgba(0, 0, 0, 0.01), 0 178px 50px 0 rgba(0, 0, 0, 0); + // Every row of the panel shares the flex line and the highlight; the boxes differ per kind + // below. Each kind is selected by its own class rather than by leaning on source order, since + // .mat-mdc-option. and .mat-mdc-option:not(...) tie on specificity. + .mat-mdc-option { + .mdc-list-item__primary-text { + display: flex; + align-items: center; + gap: 16px; + width: 100%; + } + + &:hover:not(.mdc-list-item--disabled), + &.mat-mdc-option-active:not(.mdc-list-item--disabled) { + background: rgba(0, 0, 0, 0.04); + } + + .mat-icon, tb-icon { + margin-right: 0; + } + } + // Section header — an option like every other row, not a button beside them, so the arrow keys // reach it and a screen reader reads it in the list. It IS the way into the type page: title // left, how much is not shown plus a chevron right. There is deliberately no per-section @@ -268,26 +289,10 @@ } // Item row — Design: 8px V / 16px H, 16px gap, centered - .mat-mdc-option:not(.mat-mdc-option-multiple) { + .mat-mdc-option.tb-search-popup-item { padding: 8px 16px; min-height: auto; height: auto; - - &:hover:not(.mdc-list-item--disabled), - &.mat-mdc-option-active:not(.mdc-list-item--disabled) { - background: rgba(0, 0, 0, 0.04); - } - - .mat-icon, tb-icon { - margin-right: 0; - } - - .mdc-list-item__primary-text { - display: flex; - align-items: center; - gap: 16px; - width: 100%; - } } // Thumbnail — Design: 99px x 56px, 4px radius, 1px border, 4% bg @@ -392,6 +397,7 @@ .tb-search-popup-no-results { pointer-events: none; opacity: 1 !important; + padding: 8px 16px; } .tb-search-popup-no-results-content { diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index 8e6038ef96..4efb672e33 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -3,6 +3,7 @@ import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/core'; import { Router } from '@angular/router'; 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'; @@ -66,6 +67,7 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { searchLoading = false; @ViewChild(MatAutocompleteTrigger) searchAutoTrigger: MatAutocompleteTrigger; @ViewChild('searchInput', {read: ElementRef}) searchInputRef: ElementRef; + private enterHandledByRow = false; private searchSubject = new Subject(); private searchSubscription: Subscription; @@ -217,6 +219,7 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { } onSearchInput(): void { + this.enterHandledByRow = false; this.searchLoading = true; this.searchSubject.next(this.searchText || ''); } @@ -240,13 +243,31 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { } /** - * Enter in the field opens the search page - unless the panel has an option highlighted, which - * the trigger has already acted on during keydown. This runs on keyup, which preventDefault on - * the keydown does not stop, so without the guard one Enter would both open a result and - * navigate away from it. + * Gate on every row's selection: false for the panel's own bookkeeping, true when the user + * picked the row - and then it records that this keystroke has been dealt with. + * + * One Enter reaches two handlers. The autocomplete trigger acts on keydown, the field's own + * handler on keyup, and preventDefault on the first does not stop the second. The trigger's + * activeOption cannot tell them apart either: it clears it inside that same keydown, so by + * keyup it reads empty whether or not a row acted. The row that acted says so instead, which + * does not depend on the order the two handlers run in. + */ + rowSelectedByUser(event: MatOptionSelectionChange): boolean { + if (!event.isUserInput) { + return false; + } + this.enterHandledByRow = true; + return true; + } + + /** + * Enter in the field opens the search page, unless a row has just acted on this same press. + * The flag is also cleared on input, since a pointer selection sets it with no keyup to follow + * and would otherwise swallow the next Enter. */ onSearch(): void { - if (this.searchAutoTrigger?.activeOption) { + if (this.enterHandledByRow) { + this.enterHandledByRow = false; return; } this.seeAllResults(); From c410558dcaa7ef4a793ad7ee11c2c1087cb2e366 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Thu, 17 Sep 2026 15:29:46 +0300 Subject: [PATCH 15/23] fix(iot-hub): arm the popup's Enter flag only where a keyup is coming The flag was set by any user selection, but only the keyboard leaves a second half to deal with: the trigger acts on keydown, the field's own handler on keyup, and preventDefault on the first does not stop the second. A pointer selection is finished when it returns, so the flag stayed set with nothing to consume it, and the next onSearch took the early return - click a result, close the detail dialog, press the magnifier, and the search page did not open. The magnifier is the plain case because it calls onSearch with no keystroke at all; Enter in the field does the same once the dialog restores focus there. It is armed from the trigger's activeOption now, which is readable only at that moment - the trigger holds it while it calls _selectViaInteraction and clears it on the next line of its own handler - and which a pointer never sets. Focusing the field and clearing it drop the flag as well, which covers the one pointer selection that can still arm it: arrowing to a row and then clicking a different one. --- .../pages/iot-hub/iot-hub-home.component.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index 4efb672e33..cf242faeb3 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -225,6 +225,7 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { } onSearchFocus(): void { + this.enterHandledByRow = false; if (!this.searchLoaded) { this.searchLoading = true; this.searchSubject.next(this.searchText || ''); @@ -236,6 +237,7 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { }; clearSearch(): void { + this.enterHandledByRow = false; this.searchText = ''; this.searchSubject.next(''); this.searchInputRef?.nativeElement?.focus(); @@ -244,26 +246,30 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { /** * Gate on every row's selection: false for the panel's own bookkeeping, true when the user - * picked the row - and then it records that this keystroke has been dealt with. + * picked the row - and then it records whether a keyup is still coming for it. * * One Enter reaches two handlers. The autocomplete trigger acts on keydown, the field's own - * handler on keyup, and preventDefault on the first does not stop the second. The trigger's - * activeOption cannot tell them apart either: it clears it inside that same keydown, so by - * keyup it reads empty whether or not a row acted. The row that acted says so instead, which - * does not depend on the order the two handlers run in. + * handler on keyup, and preventDefault on the first does not stop the second. Only the + * keyboard leaves that second half to deal with, so only the keyboard arms the flag: a pointer + * selection is finished when it returns, and a flag left standing there would swallow the next + * onSearch - which the magnifier button can raise with no keystroke at all. + * + * activeOption is what tells the two apart, and it is readable only here: the trigger holds it + * while it calls _selectViaInteraction and clears it on the next line of its own handler, so by + * keyup it reads empty either way. A pointer never sets it. */ rowSelectedByUser(event: MatOptionSelectionChange): boolean { if (!event.isUserInput) { return false; } - this.enterHandledByRow = true; + this.enterHandledByRow = !!this.searchAutoTrigger?.activeOption; return true; } /** * Enter in the field opens the search page, unless a row has just acted on this same press. - * The flag is also cleared on input, since a pointer selection sets it with no keyup to follow - * and would otherwise swallow the next Enter. + * Every path that re-enters the field clears the flag too, so nothing survives the keystroke + * it belongs to - including an arrow-then-click, the one selection that arms it by pointer. */ onSearch(): void { if (this.enterHandledByRow) { From ca95ecd4423292cae76372f3259bef6d22ae3df0 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 29 Sep 2026 13:40:19 +0300 Subject: [PATCH 16/23] feat(iot-hub): show the search popup as one ranked list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The popup asked /api/versions/published/grouped and rendered one section per item type, so a query answered best by a widget still opened on devices. It now asks for page 0 of the flat read the search page makes (relevance sort, 10 rows) and renders those rows in the server's order, so the best match leads whatever its type. - Each row names its type before the author ("Widget · pinkevych.d"), in the type's colour with its itemTypeIcons icon. The verified mark moves in front of the author like on the item cards; an unverified author keeps the person icon. - Items without a screenshot (calculated fields, alarm rules, rule chains) sit in the same 99x56 frame as a screenshot with a 36px coloured tile inside, so names line up down the list. - The footer says "See all N results for ..." when the search matched more than the popup shows; N discounts the rows this page dropped (dashboards). - itemTypeColors joins itemTypeIcons as the one type palette; the hero reads it instead of repeating the six colours. Removes getPublishedVersionsGrouped, MpItemVersionGroupedQuery, MpItemVersionSection and the iot-hub.section-more key. --- .../src/app/core/http/iot-hub-api.service.ts | 16 --- .../pages/iot-hub/iot-hub-home.component.html | 67 ++++++----- .../pages/iot-hub/iot-hub-home.component.scss | 112 +++++++++--------- .../pages/iot-hub/iot-hub-home.component.ts | 100 +++++++--------- .../models/iot-hub/iot-hub-item.models.ts | 15 +++ .../models/iot-hub/iot-hub-version.models.ts | 38 ------ .../assets/locale/locale.constant-en_US.json | 2 +- 7 files changed, 151 insertions(+), 199 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 7f3b299962..c5037048fb 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 @@ -7,10 +7,8 @@ import { Observable } from 'rxjs'; import { PageData } from '@shared/models/page/page-data'; import { PageLink } from '@shared/models/page/page-link'; import { - MpItemVersionGroupedQuery, MpItemVersionQuery, MpItemVersionQueryOptions, - MpItemVersionSection, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import { CreatorView } from '@shared/models/iot-hub/iot-hub-creator.models'; @@ -82,20 +80,6 @@ export class IotHubApiService { ); } - /** - * The sectioned answer: one section per item type, in the server's order, each capped by the - * server and carrying the total behind that cap. Its own endpoint, which takes no page, page - * size or sort direction. - */ - public getPublishedVersionsGrouped(query: MpItemVersionGroupedQuery, - config?: IotHubRequestConfig): Observable { - this.applyPlatformFilters(query.options); - return this.http.get( - `${this.baseUrl}/api/versions/published/grouped${query.toQuery()}`, - { params: this.buildParams(config) } - ); - } - /** * What this platform can install, filled in for a caller that did not say: items built for a * newer ThingsBoard, and PE-only items on a CE instance, cannot be installed from here. diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index 564f89ca46..5963c9e536 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -72,7 +72,7 @@ - } @else if (searchResultGroups.length === 0 && searchLoaded) { + } @else if (searchResults.length === 0 && searchLoaded) {
search_off @@ -84,48 +84,53 @@
} @else { - @for (group of searchResultGroups; track group.type) { - - {{ getSearchGroupLabel(group.type) }} - @if (group.remaining > 0) { - - {{ 'iot-hub.section-more' | translate:{ count: group.remaining } }} - chevron_right - - } - - @for (item of group.items; track item.id) { - + @for (item of searchResults; track item.id) { + + +
@if (isCompactType(item.type)) {
{{ getCompactIcon(item) }}
+ } @else if (getItemImage(item); as imgUrl) { + } @else { -
- @if (getItemImage(item); as imgUrl) { - - } @else { - {{ getItemTypeIcon(item.type) }} - } -
+ {{ getItemTypeIcon(item.type) }} } -
- {{ item.name }} - - person - {{ item.creatorDisplayName }} +
+
+ {{ item.name }} + + + + {{ getItemTypeIcon(item.type) }} + {{ getItemTypeLabel(item.type) }} -
- - } + @if (item.creatorDisplayName) { + + @if (item.creatorVerified) { + verified + } @else { + person + } + {{ item.creatorDisplayName }} + + } + +
+
} } @if (searchText?.trim(); as query) { - {{ 'iot-hub.see-results-for' | translate:{ search: query } }} + @if (searchTotal > searchResults.length) { + {{ 'iot-hub.see-all-results-for' | translate:{ count: searchTotal, search: query } }} + } @else { + {{ 'iot-hub.see-results-for' | translate:{ search: query } }} + } } @else { {{ 'iot-hub.see-all-results' | translate }} } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss index 8a89ebae44..157d6e1faf 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss @@ -241,53 +241,6 @@ } } - // Section header — an option like every other row, not a button beside them, so the arrow keys - // reach it and a screen reader reads it in the list. It IS the way into the type page: title - // left, how much is not shown plus a chevron right. There is deliberately no per-section - // "see all" row under the items; six of those on one panel is what this variant avoids. - // Design: 14px Medium, 0.25 tracking, black-tertiary, 4px V / 16px H, 12px above each section. - .mat-mdc-option.tb-search-popup-group-header { - padding: 4px 16px; - min-height: 28px; - margin-top: 12px; - - &:first-child { - margin-top: 0; - } - - .mdc-list-item__primary-text { - justify-content: space-between; - } - } - - .tb-search-popup-group-label { - font-size: 14px; - font-weight: 500; - line-height: 20px; - letter-spacing: 0.25px; - color: rgba(0, 0, 0, 0.54); - white-space: nowrap; - } - - .tb-search-popup-group-more { - display: flex; - align-items: center; - gap: 2px; - flex-shrink: 0; - font-size: 12px; - font-weight: 500; - line-height: 16px; - letter-spacing: 0.25px; - color: $tb-primary-color; - - .mat-icon { - width: 18px; - height: 18px; - font-size: 18px; - line-height: 18px; - } - } - // Item row — Design: 8px V / 16px H, 16px gap, centered .mat-mdc-option.tb-search-popup-item { padding: 8px 16px; @@ -322,11 +275,11 @@ color: rgba(0, 0, 0, 0.38); } - // Icon square — Design: 56x56, 4.667px radius, colored bg + // Icon tile for an item with no screenshot, centred in the thumbnail frame: 36x36, colored bg .tb-search-popup-icon-square { - width: 56px; - height: 56px; - border-radius: 4.667px; + width: 36px; + height: 36px; + border-radius: 6px; flex-shrink: 0; display: flex; align-items: center; @@ -334,9 +287,9 @@ } .tb-search-popup-icon-inner { - font-size: 28px; - width: 28px; - height: 28px; + font-size: 22px; + width: 22px; + height: 22px; color: white !important; --tb-icon-color: white; } @@ -373,13 +326,64 @@ letter-spacing: 0.25px; color: rgba(0, 0, 0, 0.54); white-space: nowrap; + min-width: 0; mat-icon { + flex-shrink: 0; font-size: 16px; width: 16px; height: 16px; margin-right: 0; color: rgba(0, 0, 0, 0.54); + + // Same teal the IoT Hub item cards give a verified creator. + &.tb-search-popup-verified { + color: #00695c; + } + } + } + + // Shares the meta row with the item type, so a long name is cut rather than overflowing. + .tb-search-popup-author-name { + overflow: hidden; + text-overflow: ellipsis; + } + + // Meta row: the item type, a middle dot, then the author - "Widget · pinkevych.d". + .tb-search-popup-meta { + display: flex; + align-items: center; + gap: 4px; + min-width: 0; + } + + // Item type in its own colour, darkened so the paler ones (rule chain, calculated field) stay + // legible as text. + .tb-search-popup-type { + display: flex; + align-items: center; + gap: 4px; + flex-shrink: 0; + font-size: 12px; + font-weight: 500; + line-height: 16px; + letter-spacing: 0.25px; + color: color-mix(in srgb, var(--tb-search-popup-type-color, #5f6368) 75%, #000); + white-space: nowrap; + + tb-icon { + font-size: 14px; + width: 14px; + height: 14px; + line-height: 14px; + color: inherit; + } + + // No author, nothing to separate from. + &:not(:last-child)::after { + content: '·'; + font-weight: 700; + color: rgba(0, 0, 0, 0.54); } } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index cf242faeb3..c7c6a9ad07 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -10,16 +10,14 @@ import { catchError, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/ import { MediaBreakpoints } from '@shared/models/constants'; import { PageLink } from '@shared/models/page/page-link'; import { Direction, SortOrder } from '@shared/models/page/sort-order'; -import { - MpItemVersionGroupedQuery, - MpItemVersionQuery, - MpItemVersionSection, - MpItemVersionView -} from '@shared/models/iot-hub/iot-hub-version.models'; +import { PageData } from '@shared/models/page/page-data'; +import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import { CROSS_TYPE_ITEM_TYPES, + getItemTypeColor, getItemTypeIcon, ItemType, + itemTypeColors, itemTypeTranslations, RELEVANCE_SORT_PROPERTY } from '@shared/models/iot-hub/iot-hub-item.models'; @@ -44,12 +42,11 @@ interface HeroTypeConfig { icon: string; } -interface SearchResultGroup { - type: ItemType; - items: MpItemVersionView[]; - /** How many rows of this type the header offers beyond the ones shown. Zero renders no "+N more". */ - remaining: number; -} +/** + * Rows the search popup shows: the first page of the search page's own request, so the popup is + * a preview of what "See results for ..." opens on. + */ +const SEARCH_POPUP_PAGE_SIZE = 10; @Component({ selector: 'tb-iot-hub-home', @@ -62,7 +59,13 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { readonly ItemType = ItemType; searchText = ''; - searchResultGroups: SearchResultGroup[] = []; + searchResults: MpItemVersionView[] = []; + /** + * What the footer's "See all N results" counts: the matches less the rows this page dropped, so + * a panel that shows everything it can open never claims more. Rows beyond this page that the + * panel could not show are still counted - only this page's drops are known. + */ + searchTotal = 0; searchLoaded = false; searchLoading = false; @ViewChild(MatAutocompleteTrigger) searchAutoTrigger: MatAutocompleteTrigger; @@ -74,27 +77,27 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { heroTypes: HeroTypeConfig[] = [ { - type: ItemType.DEVICE, labelKey: 'item.type-device-plural', color: '#4b63cc', + type: ItemType.DEVICE, labelKey: 'item.type-device-plural', color: itemTypeColors[ItemType.DEVICE], icon: 'assets/iot-hub/hero-device-cluster.svg' }, { - type: ItemType.SOLUTION_TEMPLATE, labelKey: 'item.type-solution-template-plural', color: '#2b6bb4', + type: ItemType.SOLUTION_TEMPLATE, labelKey: 'item.type-solution-template-plural', color: itemTypeColors[ItemType.SOLUTION_TEMPLATE], icon: 'assets/iot-hub/hero-solution-template-cluster.svg' }, { - type: ItemType.WIDGET, labelKey: 'item.type-widget-plural', color: '#2c9755', + type: ItemType.WIDGET, labelKey: 'item.type-widget-plural', color: itemTypeColors[ItemType.WIDGET], icon: 'assets/iot-hub/hero-widget-cluster.svg' }, { - type: ItemType.CALCULATED_FIELD, labelKey: 'item.type-calculated-field-plural', color: '#3cb4e0', + type: ItemType.CALCULATED_FIELD, labelKey: 'item.type-calculated-field-plural', color: itemTypeColors[ItemType.CALCULATED_FIELD], icon: 'assets/iot-hub/hero-calculated-field-cluster.svg' }, { - type: ItemType.ALARM_RULE, labelKey: 'item.type-alarm-rule-plural', color: '#d66f2e', + type: ItemType.ALARM_RULE, labelKey: 'item.type-alarm-rule-plural', color: itemTypeColors[ItemType.ALARM_RULE], icon: 'assets/iot-hub/hero-alarm-rule-cluster.svg' }, { - type: ItemType.RULE_CHAIN, labelKey: 'item.type-rule-chain-plural', color: '#a95ae2', + type: ItemType.RULE_CHAIN, labelKey: 'item.type-rule-chain-plural', color: itemTypeColors[ItemType.RULE_CHAIN], icon: 'assets/iot-hub/hero-rule-chain-cluster.svg' } ]; @@ -166,18 +169,26 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { switchMap(text => { this.searchLoading = true; const trimmed = text.trim(); + // One flat list ranked across every type, so the best match leads whatever its type. // Relevance in both states, the same value every other IoT Hub surface sends: with an // empty field the backend serves the install count under this key, so the panel opens on // popularity without this component having to know it. - const query = new MpItemVersionGroupedQuery({}, trimmed, RELEVANCE_SORT_PROPERTY); + 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); // A failed request must not end the subscription: the interceptor reports it, and the // panel goes back to an empty answer the next keystroke can replace. - return this.iotHubApiService.getPublishedVersionsGrouped(query, { ignoreLoading: true }).pipe( - catchError(() => of([] as MpItemVersionSection[])) + return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true }).pipe( + catchError(() => of({ data: [], totalElements: 0 } as PageData)) ); }) - ).subscribe(sections => { - this.searchResultGroups = this.toResultGroups(sections); + ).subscribe(page => { + // The platform publishes no dashboards, so a type this panel has no layout for is dropped; + // the popup then shows fewer rows rather than asking for more. + const data = page.data ?? []; + this.searchResults = data.filter(item => CROSS_TYPE_ITEM_TYPES.includes(item.type)); + this.searchTotal = Math.max(this.searchResults.length, + (page.totalElements ?? 0) - (data.length - this.searchResults.length)); this.searchLoaded = true; this.searchLoading = false; }); @@ -285,17 +296,6 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { void this.router.navigate(['/iot-hub/search'], { queryParams: { search } }); } - /** - * The section header is the way into the rest of a type - the panel carries no per-section - * "see all" row, which would put six identical calls to action on one panel. The query goes - * with it, so the type page opens on the same search rather than on the whole type. - */ - navigateToSection(type: ItemType): void { - this.searchAutoTrigger?.closePanel(); - const search = this.searchText?.trim() || undefined; - void this.router.navigate(['/iot-hub', this.getTypeRoute(type)], { queryParams: { search } }); - } - isCompactType(type: ItemType): boolean { return type === ItemType.CALCULATED_FIELD || type === ItemType.ALARM_RULE @@ -314,9 +314,13 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { return getItemTypeIcon(type); } - getSearchGroupLabel(type: ItemType): string { + getItemTypeColor(type: ItemType): string { + return getItemTypeColor(type); + } + + getItemTypeLabel(type: ItemType): string { const key = itemTypeTranslations.get(type); - return key ? this.translate.instant(key + '-plural') : type; + return key ? this.translate.instant(key) : type; } navigateToBrowse(type: ItemType): void { @@ -582,26 +586,4 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { }); } - /** - * Reads the sections the server built: they arrive capped and in the order to render them, so - * this only drops the types this panel has no layout for - the platform publishes no dashboards - * - and works out each header's "+N more". - * - * `items` is defaulted because the response is an unvalidated cast of a new endpoint, and a - * throw here lands in a subscribe callback, where it would leave the panel on its spinner - * rather than reaching the catchError upstream. - */ - private toResultGroups(sections: MpItemVersionSection[]): SearchResultGroup[] { - return sections - .filter(section => CROSS_TYPE_ITEM_TYPES.includes(section.itemType)) - .map(section => { - const items = section.items ?? []; - return { - type: section.itemType, - items, - remaining: Math.max(0, section.total - items.length) - }; - }); - } - } diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts index 8fbe84440b..e21582ea1a 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts @@ -41,6 +41,21 @@ export const itemTypeIcons: Record = { export const getItemTypeIcon = (type?: string | null): string => type && itemTypeIcons[type] ? itemTypeIcons[type] : 'category'; +// Canonical colour per item type - the IoT Hub home's type palette - for anything that marks an +// item's type with a colour: the hero's type cycle and the search popup's type label. +export const itemTypeColors: Record = { + [ItemType.WIDGET]: '#2c9755', + [ItemType.DASHBOARD]: '#5f6368', + [ItemType.SOLUTION_TEMPLATE]: '#2b6bb4', + [ItemType.CALCULATED_FIELD]: '#3cb4e0', + [ItemType.RULE_CHAIN]: '#a95ae2', + [ItemType.ALARM_RULE]: '#d66f2e', + [ItemType.DEVICE]: '#4b63cc' +}; + +export const getItemTypeColor = (type?: string | null): string => + type && itemTypeColors[type] ? itemTypeColors[type] : '#5f6368'; + /** * Item types discoverable to creators in the marketplace UI. * DASHBOARD is intentionally absent (IoT Hub no longer accepts Dashboard contributions). diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts index a5afaea23c..685fc27cb1 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts @@ -108,17 +108,6 @@ export interface MpItemVersionView { checksum?: string; } -/** - * One item type's share of a grouped search: the rows to show and how many exist behind them. - * A grouped answer is a list of these, in the server's section order, and a type nothing matched - * has no section — so a "+N more" header is `total - items.length`. - */ -export interface MpItemVersionSection { - itemType: ItemType; - total: number; - items: MpItemVersionView[]; -} - // 404 body shapes returned by the public listing item-version endpoint // (GET /api/listings/public/by-slug/{slug}/item-version) when no // version matches the caller's edition / platform combination. @@ -208,30 +197,3 @@ export class MpItemVersionQuery { return this.pageLink.toQuery() + filtersToQuery(this.options); } } - -/** - * A sectioned read: the filters, what to search for, and which key orders a section. - * - * No `PageLink`, because the grouped endpoint takes no page and no page size - it sizes its own - * answer from the section limit - and no sort direction either, each key's direction being fixed - * by the chain the server switches on. A page link here could only carry values nobody sends. - */ -export class MpItemVersionGroupedQuery { - constructor(public options: MpItemVersionQueryOptions = {}, - public textSearch?: string, - public sortProperty?: string) {} - - public toQuery(): string { - const parts: string[] = []; - const text = this.textSearch?.trim(); - if (text?.length) { - parts.push(`textSearch=${encodeURIComponent(text)}`); - } - if (this.sortProperty) { - parts.push(`sortProperty=${this.sortProperty}`); - } - // filtersToQuery() emits leading ampersands, which is what a page link needs in front of it; - // here they may be the whole query string, so the first one is dropped. - return `?${`${parts.join('&')}${filtersToQuery(this.options)}`.replace(/^&/, '')}`; - } -} 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 e19cb64cff..f3818e8179 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3708,6 +3708,7 @@ "search": "Search...", "search-published-items": "Search published items...", "see-all-results": "See all results", + "see-all-results-for": "See all {{ count }} results for \"{{ search }}\"", "see-results-for": "See results for \"{{ search }}\"", "no-search-results": "No results found for '{{ search }}'", "no-items-available": "No items available", @@ -3780,7 +3781,6 @@ "sort-most-installed": "Most installed", "sort-newest": "Newest", "sort-name": "Name (A-Z)", - "section-more": "{ count, plural, =1 {+1 more} other {+# more} }", "type-filter-label": "Type", "category": "Category", "use-case": "Use case", From 368d6fd94d5a9c01998c0442c8527a7f32ccdb5f Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 29 Sep 2026 17:16:06 +0300 Subject: [PATCH 17/23] refactor(iot-hub): one source for the platform scope and the type palette's default From the review: - iot-hub-api.service builds peOnly/tbVersion from one platformScope(), used by applyPlatformFilters and by the reads that wrote the pair into the URL by hand (filterInfo, widgetCategories, the listing item-version lookup). - DEFAULT_ITEM_TYPE_COLOR names the grey the palette falls back to; the alarm-rules-unavailable page reads itemTypeColors instead of its own copy. - isCompactItemType() next to CROSS_TYPE_ITEM_TYPES, used by the item card and the popup. - A stale "shared by both query shapes" comment left from the grouped query, and other comments, trimmed to the non-obvious intent. --- .../src/app/core/http/iot-hub-api.service.ts | 34 +++++++++---------- .../components/iot-hub/_iot-hub-common.scss | 8 +---- .../iot-hub/iot-hub-item-card.component.html | 3 +- .../iot-hub/iot-hub-item-card.component.ts | 15 +++----- ...-alarm-rules-unavailable-page.component.ts | 4 +-- .../iot-hub-creator-profile.component.html | 2 -- .../models/iot-hub/iot-hub-item.models.ts | 33 +++++++----------- .../models/iot-hub/iot-hub-version.models.ts | 9 ++--- 8 files changed, 40 insertions(+), 68 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 c5037048fb..fe579b5b88 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 @@ -80,31 +80,31 @@ export class IotHubApiService { ); } - /** - * What this platform can install, filled in for a caller that did not say: items built for a - * newer ThingsBoard, and PE-only items on a CE instance, cannot be installed from here. - */ + /** What this platform can install: no PE-only items, nothing built for a newer ThingsBoard. */ + private platformScope(): { peOnly: boolean; tbVersion: number } { + return { peOnly: false, tbVersion: tbVersionToInt(env.tbVersion) }; + } + + /** Fills in the platform scope wherever the caller did not set it. */ private applyPlatformFilters(options: MpItemVersionQueryOptions): void { - if (options.tbVersion == null) { - options.tbVersion = tbVersionToInt(env.tbVersion); - } - if (options.peOnly == null) { - options.peOnly = false; - } + const scope = this.platformScope(); + options.tbVersion ??= scope.tbVersion; + options.peOnly ??= scope.peOnly; + } + + private platformScopeParams(): string[] { + const scope = this.platformScope(); + return [`peOnly=${scope.peOnly}`, `tbVersion=${scope.tbVersion}`]; } public getFilterInfo(itemType: ItemType, config?: IotHubRequestConfig): Observable { - const url = `${this.baseUrl}/api/item-listing/filterInfo/${itemType}` - + `?peOnly=false&tbVersion=${tbVersionToInt(env.tbVersion)}`; + const url = `${this.baseUrl}/api/item-listing/filterInfo/${itemType}?${this.platformScopeParams().join('&')}`; return this.http.get(url, { params: this.buildParams(config) }); } public getWidgetCategories(textSearch?: string, scadaFirst?: boolean, config?: IotHubRequestConfig): Observable { - const queryParams: string[] = [ - `peOnly=false`, - `tbVersion=${tbVersionToInt(env.tbVersion)}` - ]; + const queryParams: string[] = this.platformScopeParams(); if (textSearch?.trim()) { queryParams.push(`textSearch=${encodeURIComponent(textSearch.trim())}`); } @@ -144,7 +144,7 @@ export class IotHubApiService { public getListingItemVersion(slug: string, config?: IotHubRequestConfig): Observable { const queryParams = [ 'ce=true', - `tbVersion=${tbVersionToInt(env.tbVersion)}` + `tbVersion=${this.platformScope().tbVersion}` ]; return this.http.get( `${this.baseUrl}/api/listings/public/by-slug/${encodeURIComponent(slug)}/item-version?${queryParams.join('&')}`, diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss b/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss index 96697ebe74..b6264d6ce3 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss @@ -120,13 +120,7 @@ } } -// Scroll area that shows its thumb only while the container is hovered — the filter panels' -// own treatment, kept here so the two that use it cannot drift apart. -// -// Not the app-wide one: theme.scss keeps its thumb permanently visible. Whether these panels -// should do the same, and whether to add the standardised scrollbar-width / scrollbar-color -// that Firefox reads, is a question for the IoT Hub filter UI as a whole rather than for one -// panel; iot-hub-browse and dashboard-widget-select carry copies of this same treatment. +// Scroll area whose thumb shows only while the container is hovered (the filter panels'). @mixin tb-iot-hub-hover-scrollbar { &::-webkit-scrollbar { width: 6px; diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html index 16bca59bf7..4a73740979 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html @@ -78,8 +78,7 @@ } @else {
- + {{ getPlaceholderIcon() }}
} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts index f57582fb29..123de28c3f 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { Component, EventEmitter, Input, Output } from '@angular/core'; import { MpItemVersionView, cfTypeTranslations, cfTypeIcons, ruleChainTypeTranslations, widgetTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models'; -import { getItemTypeIcon, ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; +import { getItemTypeIcon, isCompactItemType, ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { TranslateService } from '@ngx-translate/core'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; @@ -24,13 +24,8 @@ export class TbIotHubItemCardComponent { @Input() showSubtype = false; @Input() mode: 'default' | 'add' = 'default'; /** - * `auto` lets the item's type choose, which is what a single-type grid wants: calculated - * fields, alarm rules and rule chains have nothing to preview, so they get a compact row and - * the grid gives them wider cells. - * - * `preview` forces the tall card on every type. A grid that mixes types cannot widen its - * cells for some rows only, and a horizontal row squeezed into a cell sized for a preview - * truncates its own title and leaves the rest of the cell empty. + * `auto`: compact row for the types with nothing to preview (single-type grids widen their + * cells for it). `preview`: the tall card for every type, for grids that mix types. */ @Input() layout: 'auto' | 'preview' = 'auto'; @Output() cardClick = new EventEmitter(); @@ -60,9 +55,7 @@ export class TbIotHubItemCardComponent { if (this.layout === 'preview') { return false; } - return this.item.type === ItemType.CALCULATED_FIELD - || this.item.type === ItemType.ALARM_RULE - || this.item.type === ItemType.RULE_CHAIN; + return isCompactItemType(this.item.type); } getPreviewUrl(): string | null { diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-alarm-rules-unavailable-page.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-alarm-rules-unavailable-page.component.ts index c648eeb14a..f8ec79e525 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-alarm-rules-unavailable-page.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-alarm-rules-unavailable-page.component.ts @@ -3,6 +3,7 @@ import { Component } from '@angular/core'; import { Router } from '@angular/router'; import { environment as env } from '@env/environment'; +import { ItemType, itemTypeColors } from '@shared/models/iot-hub/iot-hub-item.models'; @Component({ selector: 'tb-iot-hub-alarm-rules-unavailable-page', @@ -12,8 +13,7 @@ import { environment as env } from '@env/environment'; }) export class TbIotHubAlarmRulesUnavailablePageComponent { - // Same colour as the ALARM_RULE HeroTypeConfig entry on the home page. - readonly alarmRulesColor = '#d66f2e'; + readonly alarmRulesColor = itemTypeColors[ItemType.ALARM_RULE]; readonly currentTbVersion: string = env.tbVersion; diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html index 51d834e8ed..42f92fc3d1 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html @@ -96,8 +96,6 @@
-

diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts index e21582ea1a..ea2077e634 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts @@ -41,11 +41,13 @@ export const itemTypeIcons: Record = { export const getItemTypeIcon = (type?: string | null): string => type && itemTypeIcons[type] ? itemTypeIcons[type] : 'category'; -// Canonical colour per item type - the IoT Hub home's type palette - for anything that marks an -// item's type with a colour: the hero's type cycle and the search popup's type label. +/** Colour for a type with no colour of its own. */ +export const DEFAULT_ITEM_TYPE_COLOR = '#5f6368'; + +/** Colour per item type, wherever an item's type is marked with one. */ export const itemTypeColors: Record = { [ItemType.WIDGET]: '#2c9755', - [ItemType.DASHBOARD]: '#5f6368', + [ItemType.DASHBOARD]: DEFAULT_ITEM_TYPE_COLOR, [ItemType.SOLUTION_TEMPLATE]: '#2b6bb4', [ItemType.CALCULATED_FIELD]: '#3cb4e0', [ItemType.RULE_CHAIN]: '#a95ae2', @@ -54,7 +56,7 @@ export const itemTypeColors: Record = { }; export const getItemTypeColor = (type?: string | null): string => - type && itemTypeColors[type] ? itemTypeColors[type] : '#5f6368'; + type && itemTypeColors[type] ? itemTypeColors[type] : DEFAULT_ITEM_TYPE_COLOR; /** * Item types discoverable to creators in the marketplace UI. @@ -71,11 +73,7 @@ export const CREATOR_VISIBLE_ITEM_TYPES: ItemType[] = [ ItemType.RULE_CHAIN, ]; -/** - * Item types a surface that mixes them lays out, in the order they are shown. Distinct from - * CREATOR_VISIBLE_ITEM_TYPES, which is the same six as a membership test and carries the type - * tabs' own order: here DEVICE leads, matching the hero popup's sections and the website. - */ +/** Item types a cross-type surface (search page, popup) shows, in display order. */ export const CROSS_TYPE_ITEM_TYPES: ItemType[] = [ ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, @@ -85,6 +83,10 @@ export const CROSS_TYPE_ITEM_TYPES: ItemType[] = [ ItemType.RULE_CHAIN, ]; +/** Types drawn as a coloured icon tile rather than a screenshot. */ +export const isCompactItemType = (type?: string | null): boolean => + type === ItemType.CALCULATED_FIELD || type === ItemType.ALARM_RULE || type === ItemType.RULE_CHAIN; + /** Sort property served by relevance ranking. */ export const RELEVANCE_SORT_PROPERTY = 'relevance'; @@ -95,17 +97,8 @@ export interface SortOption { } /** - * The sort menu every IoT Hub surface carrying a search field offers, and the order it offers - * them in: the first entry is the default each surface opens on. - * - * Relevance is that default with or without text. With text it ranks the answer; with none the - * backend serves the install count under the same key, so a surface opens on the order it opened - * on before and nothing here switches on the field state. The cost is a menu reading "Most - * relevant" over an install-ordered list until the user types; the alternative - flipping the - * selector once text appears - moves a control the user did not touch and reorders nothing. - * - * One list rather than one per surface: a new key must reach all of them, and the surface that - * missed it would keep a different default without failing. + * The sort menu of every IoT Hub surface with a search field; the first entry is the default. + * Relevance stays the default with an empty field, where it orders by install count. */ export const IOT_HUB_SORT_OPTIONS: SortOption[] = [ { value: RELEVANCE_SORT_PROPERTY, label: 'iot-hub.sort-most-relevant', direction: Direction.DESC }, diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts index 685fc27cb1..8ba587342c 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts @@ -120,12 +120,7 @@ export interface ListingItemVersionNotFound { export interface MpItemVersionQueryOptions { /** Single item type, for a surface pinned to one (the type pages, the add-item dialog). */ type?: string; - /** - * Several item types at once, for a cross-type surface whose Type facet is multi-select. - * Emitted as a repeated `type` parameter, which is the shape the backend reads - * (`@RequestParam List type`). Kept separate from `type` rather than widening it, - * so a caller that means "exactly this type" cannot be handed an array by accident. - */ + /** Several item types at once, sent as a repeated `type` parameter. */ types?: string[]; peOnly?: boolean; creatorId?: string; @@ -141,7 +136,7 @@ export interface MpItemVersionQueryOptions { scadaFirst?: boolean; } -/** Every filter, as `&name=value` pairs - shared by both query shapes below. */ +/** Every filter, as `&name=value` pairs. */ function filtersToQuery(o: MpItemVersionQueryOptions): string { let query = ''; if (o.type) { From 6fc35a4d0ede33a6d977ce2a82adfde02974f1b9 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 29 Sep 2026 17:16:06 +0300 Subject: [PATCH 18/23] fix(iot-hub): offer no relevance sort on the widget picker's Installed list That list is sorted in the browser, and relevance is a score only the Hub computes: sortInstalledVersions read a 'relevance' field no row has, so "Most relevant" left the list unsorted under a label saying otherwise. The Installed list now offers the other three keys, and a relevance choice made on the IoT Hub list falls back to the first of them there. The sort is kept by value rather than by menu index, since the two lists differ in length. --- .../dashboard-widget-select.component.html | 6 ++-- .../dashboard-widget-select.component.ts | 32 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html index aa5c1deb90..c75165d122 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html @@ -80,12 +80,12 @@ } @if (selectWidgetMode === 'iotHub' && iotHubSubMode !== 'default') { - @for (option of iotHubSortOptions; track option.value; let i = $index) { - + @for (option of iotHubSortOptions; track option.value) { + } } diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts index 7cb0eddd2b..7132063ed2 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts @@ -25,8 +25,13 @@ import { FilterParamInfo, IOT_HUB_SORT_OPTIONS, ItemType, + RELEVANCE_SORT_PROPERTY, + SortOption, WidgetCategory } from '@shared/models/iot-hub/iot-hub-item.models'; + +/** The Installed list is sorted locally, and only the Hub can rank by relevance. */ +const INSTALLED_SORT_OPTIONS = IOT_HUB_SORT_OPTIONS.filter(o => o.value !== RELEVANCE_SORT_PROPERTY); import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; @@ -87,12 +92,7 @@ export class DashboardWidgetSelectComponent { includeDeprecated = false; searchFocused = false; - /** - * scadaFirst is unaffected by the sort: the backend prepends it ahead of the caller's key AND - * ahead of relevance, so a SCADA context still lists SCADA widgets first. - */ - readonly iotHubSortOptions = IOT_HUB_SORT_OPTIONS; - iotHubSelectedSortIndex = 0; + private iotHubSelectedSortValue = IOT_HUB_SORT_OPTIONS[0].value; @Input() aliasController: IAliasController; @@ -302,7 +302,7 @@ export class DashboardWidgetSelectComponent { this.iotHubWidgetsFetchFunction = (pageSize, page, filter) => { const search = typeof filter === 'string' ? filter.split('|')[0] : filter; - const sort = this.iotHubSortOptions[this.iotHubSelectedSortIndex]; + const sort = this.iotHubSelectedSort; const sortOrder: SortOrder = { property: sort.value, direction: sort.direction }; const pageLink = new PageLink(pageSize, page, search || null, sortOrder); const effectiveCategories = this.iotHubSelectedCategory @@ -569,9 +569,19 @@ export class DashboardWidgetSelectComponent { this.reloadIotHubWidgets(); } - onIotHubSortChange(index: number): void { - if (this.iotHubSelectedSortIndex !== index) { - this.iotHubSelectedSortIndex = index; + get iotHubSortOptions(): SortOption[] { + return this.iotHubSubMode === 'installed' ? INSTALLED_SORT_OPTIONS : IOT_HUB_SORT_OPTIONS; + } + + /** The chosen sort, or the list's first option where the chosen one is not offered. */ + get iotHubSelectedSort(): SortOption { + const options = this.iotHubSortOptions; + return options.find(o => o.value === this.iotHubSelectedSortValue) ?? options[0]; + } + + onIotHubSortChange(option: SortOption): void { + if (this.iotHubSelectedSort.value !== option.value) { + this.iotHubSelectedSortValue = option.value; this.installedWidgetVersions = null; this.reloadIotHubWidgets(); } @@ -844,7 +854,7 @@ export class DashboardWidgetSelectComponent { } private sortInstalledVersions(versions: MpItemVersionView[]): MpItemVersionView[] { - const sort = this.iotHubSortOptions[this.iotHubSelectedSortIndex]; + const sort = this.iotHubSelectedSort; const sign = sort.direction === Direction.ASC ? 1 : -1; const copy = [...versions]; copy.sort((a, b) => { From 3b4dc3198576a0c3c17807ced1c10d2b21e4d1c5 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 29 Sep 2026 17:16:06 +0300 Subject: [PATCH 19/23] refactor(iot-hub): handle Enter in the popup on keydown, with no cross-event flag Enter in the field opens the search page unless the autocomplete has just used the press to select a highlighted row, which it marks with preventDefault in its own keydown handler, registered before the field's. The field now listens on keydown.enter and checks event.defaultPrevented, which replaces the enterHandledByRow flag, the four places that reset it, and the read of the trigger's activeOption at one exact moment. Checked in a browser: arrow + Enter on a row opens the row only, Enter in the field opens the search page, click a row / close the dialog / click the magnifier opens the search page, and arrow to the footer + Enter opens it once. Also from the review: - The popup asks for the six cross-type types rather than filtering dashboards out afterwards, so totalElements is exact and "See all N" needs no arithmetic. - Row and footer selection go through onRowSelected / onFooterSelected instead of a side-effecting predicate in the template. - isCompactType delegates to the shared isCompactItemType; comments trimmed. --- .../pages/iot-hub/iot-hub-home.component.html | 12 ++- .../pages/iot-hub/iot-hub-home.component.scss | 9 +-- .../pages/iot-hub/iot-hub-home.component.ts | 78 ++++++------------- 3 files changed, 32 insertions(+), 67 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index 5963c9e536..d244bbe06a 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -54,13 +54,13 @@ [matAutocomplete]="searchAuto" (input)="onSearchInput()" (focus)="onSearchFocus()" - (keyup.enter)="onSearch()"> + (keydown.enter)="onSearchEnter($event)"> @if (searchText) { } - @@ -86,9 +86,8 @@ } @else { @for (item of searchResults; track item.id) { - + (onSelectionChange)="onRowSelected($event, item)"> +
@if (isCompactType(item.type)) {
@@ -102,7 +101,6 @@
{{ item.name }} - {{ getItemTypeIcon(item.type) }} @@ -124,7 +122,7 @@ } } + (onSelectionChange)="onFooterSelected($event)"> @if (searchText?.trim(); as query) { @if (searchTotal > searchResults.length) { {{ 'iot-hub.see-all-results-for' | translate:{ count: searchTotal, search: query } }} diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss index 157d6e1faf..7440403390 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss @@ -220,9 +220,7 @@ 0 114px 46px 0 rgba(0, 0, 0, 0.01), 0 178px 50px 0 rgba(0, 0, 0, 0); - // Every row of the panel shares the flex line and the highlight; the boxes differ per kind - // below. Each kind is selected by its own class rather than by leaning on source order, since - // .mat-mdc-option. and .mat-mdc-option:not(...) tie on specificity. + // Shared by every row; each row kind below is selected by its own class. .mat-mdc-option { .mdc-list-item__primary-text { display: flex; @@ -357,8 +355,7 @@ min-width: 0; } - // Item type in its own colour, darkened so the paler ones (rule chain, calculated field) stay - // legible as text. + // Item type in its colour, darkened so the paler ones stay legible. .tb-search-popup-type { display: flex; align-items: center; @@ -368,7 +365,7 @@ font-weight: 500; line-height: 16px; letter-spacing: 0.25px; - color: color-mix(in srgb, var(--tb-search-popup-type-color, #5f6368) 75%, #000); + color: color-mix(in srgb, var(--tb-search-popup-type-color) 75%, #000); white-space: nowrap; tb-icon { diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index c7c6a9ad07..8f44ec2c30 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -15,6 +15,7 @@ import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/io import { CROSS_TYPE_ITEM_TYPES, getItemTypeColor, + isCompactItemType, getItemTypeIcon, ItemType, itemTypeColors, @@ -42,10 +43,7 @@ interface HeroTypeConfig { icon: string; } -/** - * Rows the search popup shows: the first page of the search page's own request, so the popup is - * a preview of what "See results for ..." opens on. - */ +/** Rows the search popup shows: page 0 of the search page's own request. */ const SEARCH_POPUP_PAGE_SIZE = 10; @Component({ @@ -60,17 +58,12 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { searchText = ''; searchResults: MpItemVersionView[] = []; - /** - * What the footer's "See all N results" counts: the matches less the rows this page dropped, so - * a panel that shows everything it can open never claims more. Rows beyond this page that the - * panel could not show are still counted - only this page's drops are known. - */ + /** Everything the search matched, for the footer's "See all N results". */ searchTotal = 0; searchLoaded = false; searchLoading = false; @ViewChild(MatAutocompleteTrigger) searchAutoTrigger: MatAutocompleteTrigger; @ViewChild('searchInput', {read: ElementRef}) searchInputRef: ElementRef; - private enterHandledByRow = false; private searchSubject = new Subject(); private searchSubscription: Subscription; @@ -169,26 +162,19 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { switchMap(text => { this.searchLoading = true; const trimmed = text.trim(); - // One flat list ranked across every type, so the best match leads whatever its type. - // Relevance in both states, the same value every other IoT Hub surface sends: with an - // empty field the backend serves the install count under this key, so the panel opens on - // popularity without this component having to know it. + // One list ranked across every type the platform surfaces. With an empty field relevance + // is served as the install count. 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); - // A failed request must not end the subscription: the interceptor reports it, and the - // panel goes back to an empty answer the next keystroke can replace. + const query = new MpItemVersionQuery(pageLink, { types: CROSS_TYPE_ITEM_TYPES }); + // A failure must not end the subscription; the next keystroke replaces the empty answer. return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true }).pipe( catchError(() => of({ data: [], totalElements: 0 } as PageData)) ); }) ).subscribe(page => { - // The platform publishes no dashboards, so a type this panel has no layout for is dropped; - // the popup then shows fewer rows rather than asking for more. - const data = page.data ?? []; - this.searchResults = data.filter(item => CROSS_TYPE_ITEM_TYPES.includes(item.type)); - this.searchTotal = Math.max(this.searchResults.length, - (page.totalElements ?? 0) - (data.length - this.searchResults.length)); + this.searchResults = page.data ?? []; + this.searchTotal = page.totalElements ?? 0; this.searchLoaded = true; this.searchLoading = false; }); @@ -230,13 +216,11 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { } onSearchInput(): void { - this.enterHandledByRow = false; this.searchLoading = true; this.searchSubject.next(this.searchText || ''); } onSearchFocus(): void { - this.enterHandledByRow = false; if (!this.searchLoaded) { this.searchLoading = true; this.searchSubject.next(this.searchText || ''); @@ -248,43 +232,30 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { }; clearSearch(): void { - this.enterHandledByRow = false; this.searchText = ''; this.searchSubject.next(''); this.searchInputRef?.nativeElement?.focus(); setTimeout(() => this.searchAutoTrigger?.openPanel()); } - /** - * Gate on every row's selection: false for the panel's own bookkeeping, true when the user - * picked the row - and then it records whether a keyup is still coming for it. - * - * One Enter reaches two handlers. The autocomplete trigger acts on keydown, the field's own - * handler on keyup, and preventDefault on the first does not stop the second. Only the - * keyboard leaves that second half to deal with, so only the keyboard arms the flag: a pointer - * selection is finished when it returns, and a flag left standing there would swallow the next - * onSearch - which the magnifier button can raise with no keystroke at all. - * - * activeOption is what tells the two apart, and it is readable only here: the trigger holds it - * while it calls _selectViaInteraction and clears it on the next line of its own handler, so by - * keyup it reads empty either way. A pointer never sets it. - */ - rowSelectedByUser(event: MatOptionSelectionChange): boolean { - if (!event.isUserInput) { - return false; + onRowSelected(event: MatOptionSelectionChange, item: MpItemVersionView): void { + if (event.isUserInput) { + this.openItemDetail(item); + } + } + + onFooterSelected(event: MatOptionSelectionChange): void { + if (event.isUserInput) { + this.seeAllResults(); } - this.enterHandledByRow = !!this.searchAutoTrigger?.activeOption; - return true; } /** - * Enter in the field opens the search page, unless a row has just acted on this same press. - * Every path that re-enters the field clears the flag too, so nothing survives the keystroke - * it belongs to - including an arrow-then-click, the one selection that arms it by pointer. + * Enter in the field opens the search page - unless the autocomplete has just used this press + * to select a highlighted row, which it marks with preventDefault before this handler runs. */ - onSearch(): void { - if (this.enterHandledByRow) { - this.enterHandledByRow = false; + onSearchEnter(event: KeyboardEvent): void { + if (event.defaultPrevented || event.isComposing) { return; } this.seeAllResults(); @@ -297,11 +268,10 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { } isCompactType(type: ItemType): boolean { - return type === ItemType.CALCULATED_FIELD - || type === ItemType.ALARM_RULE - || type === ItemType.RULE_CHAIN; + return isCompactItemType(type); } + getCompactIcon(item: MpItemVersionView): string { return item.icon || getItemTypeIcon(item.type); } From a427a6a3d20cba5802896efbaa53b9a1bb33a664 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 29 Sep 2026 17:16:06 +0300 Subject: [PATCH 20/23] fix(iot-hub): scope the search page to the cross-type types, and let a newer load win From the review of the search page: - No Type facet selected now sends the six types the platform surfaces, as the popup does, instead of every type the Hub holds: without the old grouping step a published dashboard would have rendered as a card and been counted. - Every reload goes through one Subject + switchMap, so a newer request cancels an older one; toggling two facets quickly can no longer leave the grid on the first answer. - The ResizeObserver callback runs inside NgZone.run, as in TbIotHubBrowseComponent; zone.js does not patch ResizeObserver, so a reload started from it did not render. Checked: widening the window reloads with the larger page size and renders it with no other event. - The facet list takes option keys (string[]) and computes its visible list once per change instead of on every change-detection pass; the Type facet's placeholder zero counts and the facet count summing are gone. - Shared in iot-hub-utils: filterByLabel (behind filterIotHubItemsBySearch), measureGridColumns (used by this component and the browse page), and IOT_HUB_FILTER_SCROLL_THRESHOLD in place of the literal 8 in both panels. - The page padding and the component's pull-out margin derive from one --tb-search-page-pad per breakpoint. Resize fields sit with the other state. - Comments trimmed to the non-obvious intent. --- .../iot-hub/iot-hub-browse.component.html | 24 +-- .../iot-hub/iot-hub-browse.component.ts | 21 ++- .../iot-hub/iot-hub-facet-list.component.html | 10 +- .../iot-hub/iot-hub-facet-list.component.scss | 10 +- .../iot-hub/iot-hub-facet-list.component.ts | 64 +++----- .../iot-hub/iot-hub-search.component.html | 8 +- .../iot-hub/iot-hub-search.component.scss | 33 ++-- .../iot-hub/iot-hub-search.component.ts | 147 +++++++----------- .../home/components/iot-hub/iot-hub-utils.ts | 24 ++- .../iot-hub-search-page.component.scss | 34 ++-- 10 files changed, 150 insertions(+), 225 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html index 40ffca34c8..dbc1c3c811 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html @@ -43,8 +43,8 @@ }
} -
@for (opt of getFilteredItems(subtypeOptions, 'subtype'); track opt.key) { } -
@for (group of getGroupedFilterItems(vendorOptions, 'vendor'); track group.label) { @if (group.label) { @@ -114,8 +114,8 @@ }
} -
@for (ht of getFilteredItems(hardwareTypeOptions, 'hardwareType'); track ht.key) { } -
@for (group of getFilteredConnectivityGroups('connectivity'); track group.group) {
{{ group.group }}
@@ -182,8 +182,8 @@ }
} -
@for (cat of getFilteredItems(categoryOptions, 'category'); track cat.key) { } -
@for (group of getGroupedFilterItems(useCaseOptions, 'useCase'); track group.label) { @if (group.label) { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts index 2be0408826..40276cd769 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts @@ -19,7 +19,13 @@ import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { TranslateService } from '@ngx-translate/core'; import { ActivatedRoute, Router } from '@angular/router'; import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; -import { filterIotHubItemsBySearch, groupIotHubFilterItems, IotHubFilterGroup } from '@home/components/iot-hub/iot-hub-utils'; +import { + filterIotHubItemsBySearch, + groupIotHubFilterItems, + IOT_HUB_FILTER_SCROLL_THRESHOLD, + IotHubFilterGroup, + measureGridColumns +} from '@home/components/iot-hub/iot-hub-utils'; @Component({ selector: 'tb-iot-hub-browse', @@ -43,6 +49,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy } readonly ItemType = ItemType; + readonly scrollThreshold = IOT_HUB_FILTER_SCROLL_THRESHOLD; @Input() creatorId: string; @Input() embedded = false; @@ -212,17 +219,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy if (!el) { return this.probeCols; } - // Force layout so `grid-template-columns` resolves to pixel tracks, not `repeat(...)`. - void el.offsetWidth; - const tracks = getComputedStyle(el).gridTemplateColumns; - if (!tracks || tracks === 'none') { - return 1; - } - if (tracks.startsWith('repeat(')) { - const match = tracks.match(/^repeat\(\s*(\d+)\s*,/); - return match ? parseInt(match[1], 10) : 1; - } - return Math.max(1, tracks.trim().split(/\s+/).filter(t => t.length > 0).length); + return measureGridColumns(el); } private adjustPageSize(): void { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html index 8468ddc04b..658ed108df 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html @@ -12,9 +12,9 @@ @if (searchable) {