Compare commits

...

2 Commits

Author SHA1 Message Date
Bram Kragten
c8a830f4ec use input instead of change
So when you press enter, the correct value is saved
2022-09-08 16:41:26 +02:00
Bram Kragten
d15c6b5e40 Improve rename automation dialog 2022-09-05 18:02:11 +02:00
2 changed files with 37 additions and 19 deletions

View File

@@ -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 || "";
}
@@ -48,9 +53,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`<ha-alert alert-type="error"
>${this.hass.localize(
"ui.panel.config.automation.editor.missing_name"
)}</ha-alert
>`
: ""}
<ha-textfield
dialogInitialFocus
.value=${this._newName}
@@ -60,8 +76,9 @@ class DialogAutomationRename extends LitElement implements HassDialog {
.label=${this.hass.localize(
"ui.panel.config.automation.editor.alias"
)}
required
type="string"
@change=${this._valueChanged}
@input=${this._valueChanged}
></ha-textfield>
<ha-textarea
@@ -74,14 +91,18 @@ class DialogAutomationRename extends LitElement implements HassDialog {
name="description"
autogrow
.value=${this._newDescription}
@change=${this._valueChanged}
@input=${this._valueChanged}
></ha-textarea>
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
${this.hass.localize("ui.dialogs.generic.cancel")}
</mwc-button>
<mwc-button @click=${this._save} slot="primaryAction">
${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"
)}
</mwc-button>
</ha-dialog>
`;
@@ -98,6 +119,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,
@@ -115,6 +140,10 @@ class DialogAutomationRename extends LitElement implements HassDialog {
ha-textarea {
display: block;
}
ha-alert {
display: block;
margin-bottom: 16px;
}
`,
];
}

View File

@@ -284,7 +284,9 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
@subscribe-automation-config=${this._subscribeAutomationConfig}
>
${this._errors
? html`<div class="errors">${this._errors}</div>`
? html`<ha-alert alert-type="error">
${this._errors}
</ha-alert>`
: ""}
${this._mode === "gui"
? "use_blueprint" in this._config
@@ -609,14 +611,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
const id = this.automationId || String(Date.now());
if (!this._config!.alias) {
await this._promptAutomationAlias();
if (!this._config!.alias) {
showAlertDialog(this, {
text: this.hass.localize(
"ui.panel.config.automation.editor.missing_name"
),
});
return;
}
}
this.hass!.callApi(
@@ -661,11 +655,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;
}