mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Catch yaml errors in script editor (#22853)
This commit is contained in:
parent
c7dae49c42
commit
f51bc40203
@ -79,6 +79,8 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _errors?: string;
|
@state() private _errors?: string;
|
||||||
|
|
||||||
|
@state() private _yamlErrors?: string;
|
||||||
|
|
||||||
@state() private _entityId?: string;
|
@state() private _entityId?: string;
|
||||||
|
|
||||||
@state() private _mode: "gui" | "yaml" = "gui";
|
@state() private _mode: "gui" | "yaml" = "gui";
|
||||||
@ -602,12 +604,14 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
private _yamlChanged(ev: CustomEvent) {
|
private _yamlChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
this._dirty = true;
|
||||||
if (!ev.detail.isValid) {
|
if (!ev.detail.isValid) {
|
||||||
|
this._yamlErrors = ev.detail.errorMsg;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this._yamlErrors = undefined;
|
||||||
this._config = ev.detail.value;
|
this._config = ev.detail.value;
|
||||||
this._errors = undefined;
|
this._errors = undefined;
|
||||||
this._dirty = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async confirmUnsavedChanged(): Promise<boolean> {
|
private async confirmUnsavedChanged(): Promise<boolean> {
|
||||||
@ -723,7 +727,21 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
history.back();
|
history.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _switchUiMode() {
|
private async _switchUiMode() {
|
||||||
|
if (this._yamlErrors) {
|
||||||
|
const result = await showConfirmationDialog(this, {
|
||||||
|
text: html`${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.switch_ui_yaml_error"
|
||||||
|
)}<br /><br />${this._yamlErrors}`,
|
||||||
|
confirmText: this.hass!.localize("ui.common.continue"),
|
||||||
|
destructive: true,
|
||||||
|
dismissText: this.hass!.localize("ui.common.cancel"),
|
||||||
|
});
|
||||||
|
if (!result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._yamlErrors = undefined;
|
||||||
this._mode = "gui";
|
this._mode = "gui";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,6 +781,13 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _saveScript(): Promise<void> {
|
private async _saveScript(): Promise<void> {
|
||||||
|
if (this._yamlErrors) {
|
||||||
|
showToast(this, {
|
||||||
|
message: this._yamlErrors,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.scriptId) {
|
if (!this.scriptId) {
|
||||||
const saved = await this._promptScriptAlias();
|
const saved = await this._promptScriptAlias();
|
||||||
if (!saved) {
|
if (!saved) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user