Add shortcut to label filter from label config page (#20313)

This commit is contained in:
Bram Kragten 2024-04-02 11:50:50 +02:00 committed by GitHub
parent d8b43597a0
commit bc8012dcc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 134 additions and 2 deletions

View File

@ -379,7 +379,9 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
<hass-tabs-subpage-data-table
.hass=${this.hass}
.narrow=${this.narrow}
back-path="/config"
.backPath=${
this._searchParms.has("historyBack") ? undefined : "/config"
}
id="entity_id"
.route=${this.route}
.tabs=${configSections.automations}
@ -728,6 +730,9 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
if (this._searchParms.has("blueprint")) {
this._filterBlueprint();
}
if (this._searchParms.has("label")) {
this._filterLabel();
}
}
private _filterExpanded(ev) {
@ -815,6 +820,21 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
this._filteredAutomations = items ? [...items] : undefined;
}
private _filterLabel() {
const label = this._searchParms.get("label");
if (!label) {
return;
}
this._filters = {
...this._filters,
"ha-filter-labels": {
value: [label],
items: undefined,
},
};
this._applyFilters();
}
private async _filterBlueprint() {
const blueprint = this._searchParms.get("blueprint");
if (!blueprint) {

View File

@ -185,6 +185,23 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
},
};
}
if (this._searchParms.has("label")) {
this._filterLabel();
}
}
private _filterLabel() {
const label = this._searchParms.get("label");
if (!label) {
return;
}
this._filters = {
...this._filters,
"ha-filter-labels": {
value: [label],
items: undefined,
},
};
}
private _clearFilter() {

View File

@ -758,6 +758,23 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
},
};
}
if (this._searchParms.has("label")) {
this._filterLabel();
}
}
private _filterLabel() {
const label = this._searchParms.get("label");
if (!label) {
return;
}
this._filters = {
...this._filters,
"ha-filter-labels": {
value: [label],
items: undefined,
},
};
}
private _clearFilter() {

View File

@ -1,4 +1,11 @@
import { mdiDelete, mdiHelpCircle, mdiPlus } from "@mdi/js";
import {
mdiDelete,
mdiDevices,
mdiHelpCircle,
mdiPlus,
mdiRobot,
mdiShape,
} from "@mdi/js";
import { LitElement, PropertyValues, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
@ -28,6 +35,7 @@ import "../../../layouts/hass-tabs-subpage-data-table";
import { HomeAssistant, Route } from "../../../types";
import { configSections } from "../ha-panel-config";
import { showLabelDetailDialog } from "./show-dialog-label-detail";
import { navigate } from "../../../common/navigate";
@customElement("ha-config-labels")
export class HaConfigLabels extends LitElement {
@ -81,6 +89,21 @@ export class HaConfigLabels extends LitElement {
.hass=${this.hass}
narrow
.items=${[
{
label: this.hass.localize("ui.panel.config.entities.caption"),
path: mdiShape,
action: () => this._navigateEntities(label),
},
{
label: this.hass.localize("ui.panel.config.devices.caption"),
path: mdiDevices,
action: () => this._navigateDevices(label),
},
{
label: this.hass.localize("ui.panel.config.automation.caption"),
path: mdiRobot,
action: () => this._navigateAutomations(label),
},
{
label: this.hass.localize("ui.common.delete"),
path: mdiDelete,
@ -225,6 +248,20 @@ export class HaConfigLabels extends LitElement {
return false;
}
}
private _navigateEntities(label: LabelRegistryEntry) {
navigate(`/config/entities?historyBack=1&label=${label.label_id}`);
}
private _navigateDevices(label: LabelRegistryEntry) {
navigate(`/config/devices/dashboard?historyBack=1&label=${label.label_id}`);
}
private _navigateAutomations(label: LabelRegistryEntry) {
navigate(
`/config/automation/dashboard?historyBack=1&label=${label.label_id}`
);
}
}
declare global {

View File

@ -96,6 +96,8 @@ class HaSceneDashboard extends SubscribeMixin(LitElement) {
@property({ attribute: false }) public scenes!: SceneEntity[];
@state() private _searchParms = new URLSearchParams(window.location.search);
@state() private _activeFilters?: string[];
@state() private _filteredScenes?: string[] | null;
@ -530,6 +532,27 @@ class HaSceneDashboard extends SubscribeMixin(LitElement) {
this._applyFilters();
}
firstUpdated() {
if (this._searchParms.has("label")) {
this._filterLabel();
}
}
private _filterLabel() {
const label = this._searchParms.get("label");
if (!label) {
return;
}
this._filters = {
...this._filters,
"ha-filter-labels": {
value: [label],
items: undefined,
},
};
this._applyFilters();
}
private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) {
const scene = this.scenes.find((a) => a.entity_id === ev.detail.id);

View File

@ -572,6 +572,24 @@ class HaScriptPicker extends SubscribeMixin(LitElement) {
if (this._searchParms.has("blueprint")) {
this._filterBlueprint();
}
if (this._searchParms.has("label")) {
this._filterLabel();
}
}
private _filterLabel() {
const label = this._searchParms.get("label");
if (!label) {
return;
}
this._filters = {
...this._filters,
"ha-filter-labels": {
value: [label],
items: undefined,
},
};
this._applyFilters();
}
private async _filterBlueprint() {