mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-29 07:47:19 +00:00
Hide else/default in if/choose actions (#13480)
This commit is contained in:
parent
0038f54cea
commit
8db1881a93
@ -1,6 +1,6 @@
|
|||||||
import { mdiDelete, mdiPlus } from "@mdi/js";
|
import { mdiDelete, mdiPlus } from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
import { ensureArray } from "../../../../../common/ensure-array";
|
import { ensureArray } from "../../../../../common/ensure-array";
|
||||||
import "../../../../../components/ha-icon-button";
|
import "../../../../../components/ha-icon-button";
|
||||||
@ -17,8 +17,10 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property() public action!: ChooseAction;
|
@property() public action!: ChooseAction;
|
||||||
|
|
||||||
|
@state() private _showDefault = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { choose: [{ conditions: [], sequence: [] }], default: [] };
|
return { choose: [{ conditions: [], sequence: [] }] };
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
@ -78,6 +80,8 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
>
|
>
|
||||||
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
|
${this._showDefault || action.default
|
||||||
|
? html`
|
||||||
<h2>
|
<h2>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.type.choose.default"
|
"ui.panel.config.automation.editor.actions.type.choose.default"
|
||||||
@ -88,9 +92,21 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
@value-changed=${this._defaultChanged}
|
@value-changed=${this._defaultChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
|
`
|
||||||
|
: html` <div class="link-button-row">
|
||||||
|
<button class="link" @click=${this._addDefault}>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.type.choose.add_default"
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>`}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _addDefault() {
|
||||||
|
this._showDefault = true;
|
||||||
|
}
|
||||||
|
|
||||||
private _conditionChanged(ev: CustomEvent) {
|
private _conditionChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const value = ev.detail.value as Condition[];
|
const value = ev.detail.value as Condition[];
|
||||||
@ -171,6 +187,9 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
ha-svg-icon {
|
ha-svg-icon {
|
||||||
height: 20px;
|
height: 20px;
|
||||||
}
|
}
|
||||||
|
.link-button-row {
|
||||||
|
padding: 14px;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
import { Action, IfAction } from "../../../../../data/script";
|
import { Action, IfAction } from "../../../../../data/script";
|
||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
@ -15,6 +15,8 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public action!: IfAction;
|
@property({ attribute: false }) public action!: IfAction;
|
||||||
|
|
||||||
|
@state() private _showElse = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return {
|
return {
|
||||||
if: [],
|
if: [],
|
||||||
@ -47,7 +49,8 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
@value-changed=${this._thenChanged}
|
@value-changed=${this._thenChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
|
${this._showElse || action.else
|
||||||
|
? html`
|
||||||
<h3>
|
<h3>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.type.if.else"
|
"ui.panel.config.automation.editor.actions.type.if.else"
|
||||||
@ -58,9 +61,21 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
@value-changed=${this._elseChanged}
|
@value-changed=${this._elseChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
|
`
|
||||||
|
: html` <div class="link-button-row">
|
||||||
|
<button class="link" @click=${this._addElse}>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.type.if.add_else"
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>`}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _addElse() {
|
||||||
|
this._showElse = true;
|
||||||
|
}
|
||||||
|
|
||||||
private _ifChanged(ev: CustomEvent) {
|
private _ifChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const value = ev.detail.value as Condition[];
|
const value = ev.detail.value as Condition[];
|
||||||
@ -96,7 +111,14 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return haStyle;
|
return [
|
||||||
|
haStyle,
|
||||||
|
css`
|
||||||
|
.link-button-row {
|
||||||
|
padding: 14px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2149,6 +2149,7 @@
|
|||||||
"choose": {
|
"choose": {
|
||||||
"label": "Choose",
|
"label": "Choose",
|
||||||
"default": "Default actions",
|
"default": "Default actions",
|
||||||
|
"add_default": "Add default actions",
|
||||||
"option": "Option {number}",
|
"option": "Option {number}",
|
||||||
"add_option": "Add option",
|
"add_option": "Add option",
|
||||||
"remove_option": "Remove option",
|
"remove_option": "Remove option",
|
||||||
@ -2159,7 +2160,8 @@
|
|||||||
"label": "If-then",
|
"label": "If-then",
|
||||||
"if": "If",
|
"if": "If",
|
||||||
"then": "Then",
|
"then": "Then",
|
||||||
"else": "Else"
|
"else": "Else",
|
||||||
|
"add_else": "Add else"
|
||||||
},
|
},
|
||||||
"stop": {
|
"stop": {
|
||||||
"label": "Stop",
|
"label": "Stop",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user