Browse Source
IoT Hub: show the hero search popup as one ranked list, and give the search page filterspull/16134/merge
committed by
GitHub
26 changed files with 1069 additions and 542 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" (ngModelChange)="onSearchChange($event)"> |
||||
|
@if (search) { |
||||
|
<button mat-icon-button class="tb-iot-hub-facet-search-clear" (click)="onSearchChange('')"> |
||||
|
<mat-icon>close</mat-icon> |
||||
|
</button> |
||||
|
} |
||||
|
</div> |
||||
|
} |
||||
|
|
||||
|
<div class="tb-iot-hub-facet-items" [class.scrollable]="scrollable"> |
||||
|
@for (key of visibleOptions; track key) { |
||||
|
<mat-checkbox [checked]="isSelected(key)" (change)="onToggle(key)"> |
||||
|
{{ labelFor(key) }} |
||||
|
</mat-checkbox> |
||||
|
} |
||||
|
</div> |
||||
|
</mat-expansion-panel> |
||||
@ -0,0 +1,63 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright The Thingsboard Authors |
||||
|
// SPDX-License-Identifier: Apache-2.0 |
||||
|
@import "./iot-hub-common"; |
||||
|
|
||||
|
// Matches the type pages' filter panel, minus its rail indent. |
||||
|
.tb-iot-hub-facet-panel.mat-expansion-panel { |
||||
|
box-shadow: none; |
||||
|
border-radius: 0; |
||||
|
background: transparent; |
||||
|
|
||||
|
// Text is indented by --tb-facet-indent (set by the host); the rules between facets are not. |
||||
|
.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 { |
||||
|
// Capped only when long enough to scroll. |
||||
|
&.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,60 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright The Thingsboard Authors
|
||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||
|
import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core'; |
||||
|
import { filterByLabel, IOT_HUB_FILTER_SCROLL_THRESHOLD } from '@home/components/iot-hub/iot-hub-utils'; |
||||
|
|
||||
|
/** |
||||
|
* One checkbox facet of a filter panel: a title, the option keys, and the set of keys currently |
||||
|
* selected. Presentational only - the host decides what a toggle means. |
||||
|
*/ |
||||
|
@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 implements OnChanges { |
||||
|
|
||||
|
/** Translation key for the facet's heading. */ |
||||
|
@Input() label: string; |
||||
|
|
||||
|
@Input() options: string[] = []; |
||||
|
|
||||
|
/** Keys the host has selected. The host hands over a new Set on every toggle. */ |
||||
|
@Input() selected = new Set<string>(); |
||||
|
|
||||
|
/** Turns an option key into what the user reads. */ |
||||
|
@Input() labelFor: (key: string) => string = (key) => key; |
||||
|
|
||||
|
@Input() expanded = true; |
||||
|
|
||||
|
@Output() toggled = new EventEmitter<string>(); |
||||
|
|
||||
|
search = ''; |
||||
|
searchable = false; |
||||
|
visibleOptions: string[] = []; |
||||
|
scrollable = false; |
||||
|
|
||||
|
ngOnChanges(): void { |
||||
|
this.searchable = this.options.length > IOT_HUB_FILTER_SCROLL_THRESHOLD; |
||||
|
this.applySearch(); |
||||
|
} |
||||
|
|
||||
|
onSearchChange(search: string): void { |
||||
|
this.search = search; |
||||
|
this.applySearch(); |
||||
|
} |
||||
|
|
||||
|
isSelected(key: string): boolean { |
||||
|
return this.selected.has(key); |
||||
|
} |
||||
|
|
||||
|
onToggle(key: string): void { |
||||
|
this.toggled.emit(key); |
||||
|
} |
||||
|
|
||||
|
private applySearch(): void { |
||||
|
this.visibleOptions = filterByLabel(this.options, this.search, this.labelFor); |
||||
|
this.scrollable = this.visibleOptions.length > IOT_HUB_FILTER_SCROLL_THRESHOLD; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue