Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/panels/lovelace/ha-panel-lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class LovelacePanel extends LitElement {
}
}

this._state = "loaded";
this._state = this._state === "yaml-editor" ? this._state : "loaded";
this._setLovelaceConfig(conf, confMode);
}

Expand Down
32 changes: 31 additions & 1 deletion src/panels/lovelace/hui-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import {
internalProperty,
LitElement,
property,
PropertyValues,
TemplateResult,
} from "lit-element";
import { classMap } from "lit-html/directives/class-map";
import { array, assert, object, optional, string, type } from "superstruct";
import { computeRTL } from "../../common/util/compute_rtl";
import { deepEqual } from "../../common/util/deep-equal";
import "../../components/ha-circular-progress";
import "../../components/ha-code-editor";
import type { HaCodeEditor } from "../../components/ha-code-editor";
Expand All @@ -29,6 +31,7 @@ import {
import "../../layouts/ha-app-layout";
import { haStyle } from "../../resources/styles";
import type { HomeAssistant } from "../../types";
import { showToast } from "../../util/toast";
import type { Lovelace } from "./types";

const lovelaceStruct = type({
Expand Down Expand Up @@ -101,10 +104,37 @@ class LovelaceFullConfigEditor extends LitElement {
`;
}

protected firstUpdated() {
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
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[] {
return [
haStyle,
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,8 @@
"save": "Save",
"unsaved_changes": "Unsaved changes",
"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_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?",
Expand Down