Move trigger ID to overflow menu (#11136)

This commit is contained in:
Paulus Schoutsen 2022-01-10 14:54:23 -08:00 committed by GitHub
parent 920d2972ea
commit 04f2e2e70c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 11 deletions

View File

@ -87,6 +87,8 @@ export default class HaAutomationTriggerRow extends LitElement {
@state() private _yamlMode = false; @state() private _yamlMode = false;
@state() private _requestShowId = false;
private _processedTypes = memoizeOne( private _processedTypes = memoizeOne(
(localize: LocalizeFunc): [string, string][] => (localize: LocalizeFunc): [string, string][] =>
OPTIONS.map( OPTIONS.map(
@ -103,6 +105,7 @@ export default class HaAutomationTriggerRow extends LitElement {
protected render() { protected render() {
const selected = OPTIONS.indexOf(this.trigger.platform); const selected = OPTIONS.indexOf(this.trigger.platform);
const yamlMode = this._yamlMode || selected === -1; const yamlMode = this._yamlMode || selected === -1;
const showId = "id" in this.trigger || this._requestShowId;
return html` return html`
<ha-card> <ha-card>
@ -114,6 +117,11 @@ export default class HaAutomationTriggerRow extends LitElement {
.label=${this.hass.localize("ui.common.menu")} .label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical} .path=${mdiDotsVertical}
></ha-icon-button> ></ha-icon-button>
<mwc-list-item>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.edit_id"
)}
</mwc-list-item>
<mwc-list-item .disabled=${selected === -1}> <mwc-list-item .disabled=${selected === -1}>
${yamlMode ${yamlMode
? this.hass.localize( ? this.hass.localize(
@ -189,6 +197,8 @@ export default class HaAutomationTriggerRow extends LitElement {
)} )}
</mwc-select> </mwc-select>
${showId
? html`
<paper-input <paper-input
.label=${this.hass.localize( .label=${this.hass.localize(
"ui.panel.config.automation.editor.triggers.id" "ui.panel.config.automation.editor.triggers.id"
@ -197,6 +207,8 @@ export default class HaAutomationTriggerRow extends LitElement {
@value-changed=${this._idChanged} @value-changed=${this._idChanged}
> >
</paper-input> </paper-input>
`
: ""}
<div @ui-mode-not-available=${this._handleUiModeNotAvailable}> <div @ui-mode-not-available=${this._handleUiModeNotAvailable}>
${dynamicElement( ${dynamicElement(
`ha-automation-trigger-${this.trigger.platform}`, `ha-automation-trigger-${this.trigger.platform}`,
@ -219,12 +231,15 @@ export default class HaAutomationTriggerRow extends LitElement {
private _handleAction(ev: CustomEvent<ActionDetail>) { private _handleAction(ev: CustomEvent<ActionDetail>) {
switch (ev.detail.index) { switch (ev.detail.index) {
case 0: case 0:
this._switchYamlMode(); this._requestShowId = true;
break; break;
case 1: case 1:
fireEvent(this, "duplicate"); this._switchYamlMode();
break; break;
case 2: case 2:
fireEvent(this, "duplicate");
break;
case 3:
this._onDelete(); this._onDelete();
break; break;
} }
@ -275,6 +290,7 @@ export default class HaAutomationTriggerRow extends LitElement {
if (newId === (this.trigger.id ?? "")) { if (newId === (this.trigger.id ?? "")) {
return; return;
} }
this._requestShowId = true;
const value = { ...this.trigger }; const value = { ...this.trigger };
if (!newId) { if (!newId) {
delete value.id; delete value.id;

View File

@ -1558,7 +1558,8 @@
"introduction": "Triggers are what starts the processing of an automation rule. It is possible to specify multiple triggers for the same rule. Once a trigger starts, Home Assistant will validate the conditions, if any, and call the action.", "introduction": "Triggers are what starts the processing of an automation rule. It is possible to specify multiple triggers for the same rule. Once a trigger starts, Home Assistant will validate the conditions, if any, and call the action.",
"learn_more": "Learn more about triggers", "learn_more": "Learn more about triggers",
"add": "Add trigger", "add": "Add trigger",
"id": "Trigger ID (used by the trigger condition)", "id": "Trigger ID",
"edit_id": "Edit trigger ID",
"duplicate": "Duplicate", "duplicate": "Duplicate",
"delete": "[%key:ui::panel::mailbox::delete_button%]", "delete": "[%key:ui::panel::mailbox::delete_button%]",
"delete_confirm": "Are you sure you want to delete this?", "delete_confirm": "Are you sure you want to delete this?",