From 8a7f35cee66e080bb30b9aff3b21a9c184488bd2 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 5 Sep 2022 19:38:51 +0200 Subject: [PATCH] Improve rename automation dialog (#13601) --- .../dialog-automation-rename.ts | 35 +++++++++++++++++-- .../config/automation/ha-automation-editor.ts | 17 ++------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts b/src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts index ffcc401094..e97976e3f7 100644 --- a/src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts +++ b/src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts @@ -8,6 +8,7 @@ import { haStyle, haStyleDialog } from "../../../../resources/styles"; import type { HomeAssistant } from "../../../../types"; import type { AutomationRenameDialog } from "./show-dialog-automation-rename"; import "../../../../components/ha-textarea"; +import "../../../../components/ha-alert"; import "../../../../components/ha-textfield"; @customElement("ha-dialog-automation-rename") @@ -16,6 +17,8 @@ class DialogAutomationRename extends LitElement implements HassDialog { @state() private _opened = false; + @state() private _error?: string; + private _params!: AutomationRenameDialog; private _newName?: string; @@ -25,7 +28,9 @@ class DialogAutomationRename extends LitElement implements HassDialog { public showDialog(params: AutomationRenameDialog): void { this._opened = true; this._params = params; - this._newName = params.config.alias || ""; + this._newName = + params.config.alias || + this.hass.localize("ui.panel.config.automation.editor.default_name"); this._newDescription = params.config.description || ""; } @@ -49,9 +54,20 @@ class DialogAutomationRename extends LitElement implements HassDialog { @closed=${this.closeDialog} .heading=${createCloseHeading( this.hass, - this.hass.localize("ui.panel.config.automation.editor.rename") + this.hass.localize( + this._params.config.alias + ? "ui.panel.config.automation.editor.rename" + : "ui.panel.config.automation.editor.save" + ) )} > + ${this._error + ? html`${this.hass.localize( + "ui.panel.config.automation.editor.missing_name" + )}` + : ""} @@ -82,7 +99,11 @@ class DialogAutomationRename extends LitElement implements HassDialog { ${this.hass.localize("ui.dialogs.generic.cancel")} - ${this.hass.localize("ui.panel.config.automation.editor.rename")} + ${this.hass.localize( + this._params.config.alias + ? "ui.panel.config.automation.editor.rename" + : "ui.panel.config.automation.editor.save" + )} `; @@ -99,6 +120,10 @@ class DialogAutomationRename extends LitElement implements HassDialog { } private _save(): void { + if (!this._newName) { + this._error = "Name is required"; + return; + } this._params.updateAutomation({ ...this._params.config, alias: this._newName, @@ -116,6 +141,10 @@ class DialogAutomationRename extends LitElement implements HassDialog { ha-textarea { display: block; } + ha-alert { + display: block; + margin-bottom: 16px; + } `, ]; } diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts index bbe0c81d1f..936c45eb3c 100644 --- a/src/panels/config/automation/ha-automation-editor.ts +++ b/src/panels/config/automation/ha-automation-editor.ts @@ -298,7 +298,9 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { @subscribe-automation-config=${this._subscribeAutomationConfig} > ${this._errors - ? html`
${this._errors}
` + ? html` + ${this._errors} + ` : ""} ${this._mode === "gui" ? "use_blueprint" in this._config @@ -629,14 +631,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { const id = this.automationId || String(Date.now()); if (!this.automationId) { await this._promptAutomationAlias(); - if (!this._config!.alias) { - showAlertDialog(this, { - text: this.hass.localize( - "ui.panel.config.automation.editor.missing_name" - ), - }); - return; - } } this.hass!.callApi( @@ -681,11 +675,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { ha-card { overflow: hidden; } - .errors { - padding: 20px; - font-weight: bold; - color: var(--error-color); - } .content { padding-bottom: 20px; }