Restore trigger id in overflow menu for trigger (#27702)

This commit is contained in:
Paul Bottein
2025-10-30 03:26:25 +01:00
committed by GitHub
parent 13ace24b83
commit 0147dbab00
3 changed files with 34 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ import {
mdiContentCopy, mdiContentCopy,
mdiContentCut, mdiContentCut,
mdiDelete, mdiDelete,
mdiIdentifier,
mdiPlayCircleOutline, mdiPlayCircleOutline,
mdiPlaylistEdit, mdiPlaylistEdit,
mdiPlusCircleMultipleOutline, mdiPlusCircleMultipleOutline,
@@ -40,6 +41,8 @@ export default class HaAutomationSidebarTrigger extends LitElement {
@property({ type: Number, attribute: "sidebar-key" }) @property({ type: Number, attribute: "sidebar-key" })
public sidebarKey?: number; public sidebarKey?: number;
@state() private _requestShowId = false;
@state() private _warnings?: string[]; @state() private _warnings?: string[];
@query(".sidebar-editor") @query(".sidebar-editor")
@@ -47,6 +50,7 @@ export default class HaAutomationSidebarTrigger extends LitElement {
protected willUpdate(changedProperties) { protected willUpdate(changedProperties) {
if (changedProperties.has("config")) { if (changedProperties.has("config")) {
this._requestShowId = false;
this._warnings = undefined; this._warnings = undefined;
if (this.config) { if (this.config) {
this.yamlMode = this.config.yamlMode; this.yamlMode = this.config.yamlMode;
@@ -101,6 +105,24 @@ export default class HaAutomationSidebarTrigger extends LitElement {
</div> </div>
</ha-md-menu-item> </ha-md-menu-item>
${!this.yamlMode &&
!("id" in this.config.config) &&
!this._requestShowId
? html`<ha-md-menu-item
slot="menu-items"
.clickAction=${this._showTriggerId}
.disabled=${this.disabled || type === "list"}
>
<ha-svg-icon slot="start" .path=${mdiIdentifier}></ha-svg-icon>
<div class="overflow-label">
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.edit_id"
)}
<span class="shortcut-placeholder ${isMac ? "mac" : ""}"></span>
</div>
</ha-md-menu-item>`
: nothing}
<ha-md-divider <ha-md-divider
slot="menu-items" slot="menu-items"
role="separator" role="separator"
@@ -250,6 +272,7 @@ export default class HaAutomationSidebarTrigger extends LitElement {
@value-changed=${this._valueChangedSidebar} @value-changed=${this._valueChangedSidebar}
@yaml-changed=${this._yamlChangedSidebar} @yaml-changed=${this._yamlChangedSidebar}
.uiSupported=${this.config.uiSupported} .uiSupported=${this.config.uiSupported}
.showId=${this._requestShowId}
.yamlMode=${this.yamlMode} .yamlMode=${this.yamlMode}
.disabled=${this.disabled} .disabled=${this.disabled}
@ui-mode-not-available=${this._handleUiModeNotAvailable} @ui-mode-not-available=${this._handleUiModeNotAvailable}
@@ -292,6 +315,10 @@ export default class HaAutomationSidebarTrigger extends LitElement {
fireEvent(this, "toggle-yaml-mode"); fireEvent(this, "toggle-yaml-mode");
}; };
private _showTriggerId = () => {
this._requestShowId = true;
};
static styles = [sidebarEditorStyles, overflowStyles]; static styles = [sidebarEditorStyles, overflowStyles];
} }

View File

@@ -29,6 +29,8 @@ export default class HaAutomationTriggerEditor extends LitElement {
@property({ type: Boolean, attribute: "sidebar" }) public inSidebar = false; @property({ type: Boolean, attribute: "sidebar" }) public inSidebar = false;
@property({ type: Boolean, attribute: "show-id" }) public showId = false;
@query("ha-yaml-editor") public yamlEditor?: HaYamlEditor; @query("ha-yaml-editor") public yamlEditor?: HaYamlEditor;
protected render() { protected render() {
@@ -36,6 +38,8 @@ export default class HaAutomationTriggerEditor extends LitElement {
const yamlMode = this.yamlMode || !this.uiSupported; const yamlMode = this.yamlMode || !this.uiSupported;
const showId = "id" in this.trigger || this.showId;
return html` return html`
<div <div
class=${classMap({ class=${classMap({
@@ -70,20 +74,15 @@ export default class HaAutomationTriggerEditor extends LitElement {
></ha-yaml-editor> ></ha-yaml-editor>
` `
: html` : html`
${!isTriggerList(this.trigger) ${showId && !isTriggerList(this.trigger)
? html` ? html`
<ha-textfield <ha-textfield
.label=${`${this.hass.localize( .label=${this.hass.localize(
"ui.panel.config.automation.editor.triggers.id" "ui.panel.config.automation.editor.triggers.id"
)} (${this.hass.localize( )}
"ui.panel.config.automation.editor.triggers.optional"
)})`}
.value=${this.trigger.id || ""} .value=${this.trigger.id || ""}
.disabled=${this.disabled} .disabled=${this.disabled}
@change=${this._idChanged} @change=${this._idChanged}
.helper=${this.hass.localize(
"ui.panel.config.automation.editor.triggers.id_helper"
)}
></ha-textfield> ></ha-textfield>
` `
: nothing} : nothing}

View File

@@ -3945,7 +3945,6 @@
"add": "Add trigger", "add": "Add trigger",
"empty_search": "No triggers found for {term}", "empty_search": "No triggers found for {term}",
"id": "Trigger ID", "id": "Trigger ID",
"id_helper": "Helps identify each run based on which trigger fired.",
"optional": "Optional", "optional": "Optional",
"edit_id": "Edit ID", "edit_id": "Edit ID",
"duplicate": "[%key:ui::common::duplicate%]", "duplicate": "[%key:ui::common::duplicate%]",