mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-16 23:26:34 +00:00
Show yaml parsing errors in hui-element-editor (#23690)
This commit is contained in:
parent
9934ea4b4f
commit
eda0ea077c
@ -4,6 +4,7 @@ import { property, query, state } from "lit/decorators";
|
|||||||
import { cache } from "lit/directives/cache";
|
import { cache } from "lit/directives/cache";
|
||||||
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
|
import { debounce } from "../../../common/util/debounce";
|
||||||
import { handleStructError } from "../../../common/structs/handle-errors";
|
import { handleStructError } from "../../../common/structs/handle-errors";
|
||||||
import { deepEqual } from "../../../common/util/deep-equal";
|
import { deepEqual } from "../../../common/util/deep-equal";
|
||||||
import "../../../components/ha-alert";
|
import "../../../components/ha-alert";
|
||||||
@ -67,6 +68,11 @@ export abstract class HuiElementEditor<
|
|||||||
// Error: Configuration broken - do not save
|
// Error: Configuration broken - do not save
|
||||||
@state() private _errors?: string[];
|
@state() private _errors?: string[];
|
||||||
|
|
||||||
|
// Error from unparseable YAML, but don't show it immediately to prevent showing immediately on every keystroke
|
||||||
|
@state() private _pendingYamlError?: string;
|
||||||
|
|
||||||
|
@state() private _yamlError = false;
|
||||||
|
|
||||||
// Warning: GUI editor can't handle configuration - ok to save
|
// Warning: GUI editor can't handle configuration - ok to save
|
||||||
@state() private _warnings?: string[];
|
@state() private _warnings?: string[];
|
||||||
|
|
||||||
@ -237,6 +243,7 @@ export abstract class HuiElementEditor<
|
|||||||
autofocus
|
autofocus
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@value-changed=${this._handleYAMLChanged}
|
@value-changed=${this._handleYAMLChanged}
|
||||||
|
@blur=${this._onBlurYaml}
|
||||||
@keydown=${this._ignoreKeydown}
|
@keydown=${this._ignoreKeydown}
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
></ha-yaml-editor>
|
></ha-yaml-editor>
|
||||||
@ -327,6 +334,34 @@ export abstract class HuiElementEditor<
|
|||||||
if (ev.detail.isValid) {
|
if (ev.detail.isValid) {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
this._errors = undefined;
|
this._errors = undefined;
|
||||||
|
this._pendingYamlError = undefined;
|
||||||
|
this._yamlError = false;
|
||||||
|
this._debounceYamlError.cancel();
|
||||||
|
this._setConfig();
|
||||||
|
} else if (this._yamlError) {
|
||||||
|
// If we're already showing a yaml error, don't bother to debounce, just update immediately.
|
||||||
|
this._errors = [ev.detail.errorMsg];
|
||||||
|
} else {
|
||||||
|
this._pendingYamlError = ev.detail.errorMsg;
|
||||||
|
this._debounceYamlError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _debounceYamlError = debounce(() => {
|
||||||
|
if (this._pendingYamlError) {
|
||||||
|
this._yamlError = true;
|
||||||
|
this._errors = [this._pendingYamlError];
|
||||||
|
this._pendingYamlError = undefined;
|
||||||
|
this._setConfig();
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
private _onBlurYaml() {
|
||||||
|
this._debounceYamlError.cancel();
|
||||||
|
if (this._pendingYamlError) {
|
||||||
|
this._yamlError = true;
|
||||||
|
this._errors = [this._pendingYamlError];
|
||||||
|
this._pendingYamlError = undefined;
|
||||||
this._setConfig();
|
this._setConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user