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 ccd592d569..6fc29dea6d 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -4200,6 +4200,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", @@ -4266,7 +4267,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",