Handle reconnect while in raw edit (#8500)

This commit is contained in:
Bram Kragten 2021-03-01 16:55:39 +01:00 committed by GitHub
parent 1642c68493
commit 5ff757ad65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View File

@ -257,7 +257,7 @@ class LovelacePanel extends LitElement {
} }
} }
this._state = "loaded"; this._state = this._state === "yaml-editor" ? this._state : "loaded";
this._setLovelaceConfig(conf, confMode); this._setLovelaceConfig(conf, confMode);
} }

View File

@ -11,11 +11,13 @@ import {
internalProperty, internalProperty,
LitElement, LitElement,
property, property,
PropertyValues,
TemplateResult, TemplateResult,
} from "lit-element"; } from "lit-element";
import { classMap } from "lit-html/directives/class-map"; import { classMap } from "lit-html/directives/class-map";
import { array, assert, object, optional, string, type } from "superstruct"; import { array, assert, object, optional, string, type } from "superstruct";
import { computeRTL } from "../../common/util/compute_rtl"; import { computeRTL } from "../../common/util/compute_rtl";
import { deepEqual } from "../../common/util/deep-equal";
import "../../components/ha-circular-progress"; import "../../components/ha-circular-progress";
import "../../components/ha-code-editor"; import "../../components/ha-code-editor";
import type { HaCodeEditor } from "../../components/ha-code-editor"; import type { HaCodeEditor } from "../../components/ha-code-editor";
@ -29,6 +31,7 @@ import {
import "../../layouts/ha-app-layout"; import "../../layouts/ha-app-layout";
import { haStyle } from "../../resources/styles"; import { haStyle } from "../../resources/styles";
import type { HomeAssistant } from "../../types"; import type { HomeAssistant } from "../../types";
import { showToast } from "../../util/toast";
import type { Lovelace } from "./types"; import type { Lovelace } from "./types";
const lovelaceStruct = type({ const lovelaceStruct = type({
@ -101,10 +104,37 @@ class LovelaceFullConfigEditor extends LitElement {
`; `;
} }
protected firstUpdated() { protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
this.yamlEditor.value = safeDump(this.lovelace!.config); this.yamlEditor.value = safeDump(this.lovelace!.config);
} }
protected updated(changedProps: PropertyValues) {
const oldLovelace = changedProps.get("lovelace") as Lovelace | undefined;
if (
oldLovelace &&
this.lovelace &&
oldLovelace.config !== this.lovelace.config &&
!deepEqual(oldLovelace.config, this.lovelace.config)
) {
showToast(this, {
message: this.hass!.localize(
"ui.panel.lovelace.editor.raw_editor.lovelace_changed"
),
action: {
action: () => {
this.yamlEditor.value = safeDump(this.lovelace!.config);
},
text: this.hass!.localize(
"ui.panel.lovelace.editor.raw_editor.reload"
),
},
duration: 0,
dismissable: false,
});
}
}
static get styles(): CSSResult[] { static get styles(): CSSResult[] {
return [ return [
haStyle, haStyle,

View File

@ -2654,6 +2654,8 @@
"save": "Save", "save": "Save",
"unsaved_changes": "Unsaved changes", "unsaved_changes": "Unsaved changes",
"saved": "Saved", "saved": "Saved",
"reload": "Reload",
"lovelace_changed": "The Lovelace config was updated, do you want to load the updated config in the editor and lose your current changes?",
"confirm_remove_config_title": "Are you sure you want to remove your Lovelace UI configuration?", "confirm_remove_config_title": "Are you sure you want to remove your Lovelace UI configuration?",
"confirm_remove_config_text": "We will automatically generate your Lovelace UI views with your areas and devices if you remove your Lovelace UI configuration.", "confirm_remove_config_text": "We will automatically generate your Lovelace UI views with your areas and devices if you remove your Lovelace UI configuration.",
"confirm_unsaved_changes": "You have unsaved changes, are you sure you want to exit?", "confirm_unsaved_changes": "You have unsaved changes, are you sure you want to exit?",