diff --git a/src/panels/config/automation/action/ha-automation-action-row.ts b/src/panels/config/automation/action/ha-automation-action-row.ts index feada8f6b6..eb7b13ea5b 100644 --- a/src/panels/config/automation/action/ha-automation-action-row.ts +++ b/src/panels/config/automation/action/ha-automation-action-row.ts @@ -1,5 +1,4 @@ import { consume } from "@lit-labs/context"; -import type { ActionDetail } from "@material/mwc-list/mwc-list-foundation"; import { mdiAlertCircleCheck, mdiArrowDown, @@ -27,7 +26,9 @@ import { stopPropagation } from "../../../../common/dom/stop_propagation"; import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter"; import { handleStructError } from "../../../../common/structs/handle-errors"; import "../../../../components/ha-alert"; -import "../../../../components/ha-button-menu"; +import "../../../../components/ha-md-button-menu"; +import "../../../../components/ha-md-menu-item"; +import "../../../../components/ha-md-divider"; import "../../../../components/ha-card"; import "../../../../components/ha-expansion-panel"; import "../../../../components/ha-icon-button"; @@ -240,89 +241,104 @@ export default class HaAutomationActionRow extends LitElement { ` : nothing} - - + ${this.hass.localize( "ui.panel.config.automation.editor.actions.run" )} - - + + - + ${this.hass.localize( "ui.panel.config.automation.editor.actions.rename" )} - - + + -
  • + - + ${this.hass.localize( "ui.panel.config.automation.editor.actions.duplicate" )} - + - + ${this.hass.localize( "ui.panel.config.automation.editor.triggers.copy" )} - - + + - + ${this.hass.localize( "ui.panel.config.automation.editor.triggers.cut" )} - - + + - ${this.hass.localize("ui.panel.config.automation.editor.move_up")} - + - ${this.hass.localize( "ui.panel.config.automation.editor.move_down" )} - + - + ${this.hass.localize( `ui.panel.config.automation.editor.edit_${!yamlMode ? "yaml" : "ui"}` )} - - + + -
  • + - + ${this.action.enabled === false ? this.hass.localize( "ui.panel.config.automation.editor.actions.enable" @@ -331,15 +347,15 @@ export default class HaAutomationActionRow extends LitElement { "ui.panel.config.automation.editor.actions.disable" )} - - + ${this.hass.localize( @@ -347,11 +363,11 @@ export default class HaAutomationActionRow extends LitElement { )} - -
    + +
    ) { - switch (ev.detail.index) { - case 0: - this._runAction(); - break; - case 1: - await this._renameAction(); - break; - case 2: - fireEvent(this, "duplicate"); - break; - case 3: - this._setClipboard(); - break; - case 4: - this._setClipboard(); - fireEvent(this, "value-changed", { value: null }); - break; - case 5: - fireEvent(this, "move-up"); - break; - case 6: - fireEvent(this, "move-down"); - break; - case 7: - if (this._yamlMode) { - this._switchUiMode(); - } else { - this._switchYamlMode(); - } - this.expand(); - break; - case 8: - this._onDisable(); - break; - case 9: - this._onDelete(); - break; - } - } - private _setClipboard() { this._clipboard = { ...this._clipboard, @@ -472,16 +447,16 @@ export default class HaAutomationActionRow extends LitElement { }; } - private _onDisable() { + private _onDisable = () => { const enabled = !(this.action.enabled ?? true); const value = { ...this.action, enabled }; fireEvent(this, "value-changed", { value }); if (this._yamlMode) { this._yamlEditor?.setValue(value); } - } + }; - private async _runAction() { + private _runAction = async () => { const validated = await validateConfig(this.hass, { actions: this.action, }); @@ -513,9 +488,9 @@ export default class HaAutomationActionRow extends LitElement { "ui.panel.config.automation.editor.actions.run_action_success" ), }); - } + }; - private _onDelete() { + private _onDelete = () => { showConfirmationDialog(this, { title: this.hass.localize( "ui.panel.config.automation.editor.actions.delete_confirm_title" @@ -530,7 +505,7 @@ export default class HaAutomationActionRow extends LitElement { fireEvent(this, "value-changed", { value: null }); }, }); - } + }; private _onYamlChange(ev: CustomEvent) { ev.stopPropagation(); @@ -561,7 +536,7 @@ export default class HaAutomationActionRow extends LitElement { this._yamlMode = true; } - private async _renameAction(): Promise { + private _renameAction = async (): Promise => { const alias = await showPromptDialog(this, { title: this.hass.localize( "ui.panel.config.automation.editor.actions.change_alias" @@ -598,7 +573,37 @@ export default class HaAutomationActionRow extends LitElement { this._yamlEditor?.setValue(value); } } - } + }; + + private _duplicateAction = () => { + fireEvent(this, "duplicate"); + }; + + private _copyAction = () => { + this._setClipboard(); + }; + + private _cutAction = () => { + this._setClipboard(); + fireEvent(this, "value-changed", { value: null }); + }; + + private _moveUp = () => { + fireEvent(this, "move-up"); + }; + + private _moveDown = () => { + fireEvent(this, "move-down"); + }; + + private _toggleYamlMode = () => { + if (this._yamlMode) { + this._switchUiMode(); + } else { + this._switchYamlMode(); + } + this.expand(); + }; public expand() { this.updateComplete.then(() => { @@ -610,7 +615,6 @@ export default class HaAutomationActionRow extends LitElement { return [ haStyle, css` - ha-button-menu, ha-icon-button { --mdc-theme-text-primary-on-background: var(--primary-text-color); } @@ -649,18 +653,11 @@ export default class HaAutomationActionRow extends LitElement { border-top-right-radius: var(--ha-card-border-radius, 12px); border-top-left-radius: var(--ha-card-border-radius, 12px); } - - mwc-list-item[disabled] { - --mdc-theme-text-primary-on-background: var(--disabled-text-color); - } - mwc-list-item.hidden { - display: none; - } .warning ul { margin: 4px 0; } - li[role="separator"] { - border-bottom-color: var(--divider-color); + ha-md-menu-item > ha-svg-icon { + --mdc-icon-size: 24px; } `, ];