Browse Source
Forward-port of thingsboard/thingsboard#16148: the hero search popup asks the Hub for sectioned results and renders them, the search page gains a filter panel and a column-driven page size, and relevance becomes the sort default on every surface that carries a search field. Merged with no conflicts. Two files auto-merged - iot-hub-components.module.ts, where lts-4.3 and this branch each added a declaration, and the en_US locale, where lts-4.3 added 708 lines and this branch four keys.pull/16161/head
21 changed files with 1120 additions and 422 deletions
@ -0,0 +1,31 @@ |
|||
<!-- |
|||
|
|||
SPDX-FileCopyrightText: Copyright The Thingsboard Authors |
|||
SPDX-License-Identifier: Apache-2.0 |
|||
|
|||
--> |
|||
<mat-expansion-panel [expanded]="expanded" class="tb-iot-hub-facet-panel"> |
|||
<mat-expansion-panel-header> |
|||
<mat-panel-title>{{ label | translate }}</mat-panel-title> |
|||
</mat-expansion-panel-header> |
|||
|
|||
@if (searchable) { |
|||
<div class="tb-iot-hub-facet-search"> |
|||
<mat-icon>search</mat-icon> |
|||
<input [placeholder]="'iot-hub.search' | translate" [(ngModel)]="search"> |
|||
@if (search) { |
|||
<button mat-icon-button class="tb-iot-hub-facet-search-clear" (click)="search = ''"> |
|||
<mat-icon>close</mat-icon> |
|||
</button> |
|||
} |
|||
</div> |
|||
} |
|||
|
|||
<div class="tb-iot-hub-facet-items" [class.scrollable]="scrollable"> |
|||
@for (option of visibleOptions; track option.key) { |
|||
<mat-checkbox [checked]="isSelected(option.key)" (change)="onToggle(option.key)"> |
|||
{{ labelFor(option.key) }} |
|||
</mat-checkbox> |
|||
} |
|||
</div> |
|||
</mat-expansion-panel> |
|||
@ -0,0 +1,67 @@ |
|||
// 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; |
|||
} |
|||
|
|||
@include tb-iot-hub-hover-scrollbar; |
|||
} |
|||
|
|||
.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; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
// 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 - the host hands over a new Set |
|||
* on every toggle rather than mutating this one. */ |
|||
@Input() selected = new Set<string>(); |
|||
|
|||
/** |
|||
* 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<string>(); |
|||
|
|||
/** |
|||
* 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); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue