mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-07 01:50:31 +00:00
Add collapse/expand all for automations (#26695)
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import type { CSSResultGroup } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import type { LocalizeKeys } from "../../../common/translations/localize";
|
||||
import "../../../components/ha-alert";
|
||||
import "../../../components/ha-form/ha-form";
|
||||
import type { HaForm } from "../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../components/ha-form/types";
|
||||
import type { HaSelector } from "../../../components/ha-selector/ha-selector";
|
||||
import type { HaActionSelector } from "../../../components/ha-selector/ha-selector-action";
|
||||
import type { HaConditionSelector } from "../../../components/ha-selector/ha-selector-condition";
|
||||
import "../../../components/ha-yaml-editor";
|
||||
import type { Field } from "../../../data/script";
|
||||
import { SELECTOR_SELECTOR_BUILDING_BLOCKS } from "../../../data/selector/selector_selector";
|
||||
@@ -33,6 +37,9 @@ export default class HaScriptFieldSelectorEditor extends LitElement {
|
||||
|
||||
@state() private _yamlError?: undefined | "yaml_error" | "key_not_unique";
|
||||
|
||||
@query("ha-form")
|
||||
private _formElement?: HaForm;
|
||||
|
||||
private _schema = memoizeOne(
|
||||
(selector: any) =>
|
||||
[
|
||||
@@ -138,6 +145,41 @@ export default class HaScriptFieldSelectorEditor extends LitElement {
|
||||
this.hass.localize(`ui.panel.config.script.editor.field.${error}` as any) ||
|
||||
error;
|
||||
|
||||
private _getSelectorElements() {
|
||||
if (this._formElement) {
|
||||
const selectors =
|
||||
this._formElement.shadowRoot?.querySelectorAll<HaSelector>(
|
||||
"ha-selector"
|
||||
);
|
||||
|
||||
const selectorElements: (HaConditionSelector | HaActionSelector)[] = [];
|
||||
|
||||
selectors?.forEach((selector) => {
|
||||
selectorElements.push(
|
||||
...Array.from(
|
||||
selector.shadowRoot?.querySelectorAll<
|
||||
HaConditionSelector | HaActionSelector
|
||||
>("ha-selector-condition, ha-selector-action") || []
|
||||
)
|
||||
);
|
||||
});
|
||||
return selectorElements;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public expandAll() {
|
||||
this._getSelectorElements().forEach((element) => {
|
||||
element.expandAll?.();
|
||||
});
|
||||
}
|
||||
|
||||
public collapseAll() {
|
||||
this._getSelectorElements().forEach((element) => {
|
||||
element.collapseAll?.();
|
||||
});
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
haStyle,
|
||||
|
||||
Reference in New Issue
Block a user