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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"codemirror": "^5.49.0",
"cpx": "^1.5.0",
"deep-clone-simple": "^1.1.1",
"deep-freeze": "^0.0.1",
"es6-object-assign": "^1.1.0",
"fecha": "^3.0.2",
"fuse.js": "^3.4.4",
Expand Down
18 changes: 13 additions & 5 deletions src/panels/lovelace/ha-panel-lovelace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "@material/mwc-button";
import * as deepFreeze from "deep-freeze";

import {
fetchConfig,
Expand Down Expand Up @@ -263,15 +264,22 @@ class LovelacePanel extends LitElement {

private _checkLovelaceConfig(config: LovelaceConfig) {
// Somehow there can be badges with value null, we remove those
config.views.forEach((view) => {
if (view.badges) {
view.badges = view.badges.filter(Boolean);
let checkedConfig;
config.views.forEach((view, index) => {
if (view.badges && !view.badges.every(Boolean)) {
checkedConfig = checkedConfig || {
...config,
views: [...config.views],
};
checkedConfig.views[index] = { ...view };
Comment thread
thomasloven marked this conversation as resolved.
checkedConfig.views[index].badges = view.badges.filter(Boolean);
}
});
return checkedConfig ? deepFreeze(checkedConfig) : config;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will now only freeze the config when there are faulty badges.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

private _setLovelaceConfig(config: LovelaceConfig, mode: Lovelace["mode"]) {
this._checkLovelaceConfig(config);
config = this._checkLovelaceConfig(config);
this.lovelace = {
config,
mode,
Expand All @@ -295,7 +303,7 @@ class LovelacePanel extends LitElement {
},
saveConfig: async (newConfig: LovelaceConfig): Promise<void> => {
const { config: previousConfig, mode: previousMode } = this.lovelace!;
this._checkLovelaceConfig(newConfig);
newConfig = this._checkLovelaceConfig(newConfig);
Comment thread
thomasloven marked this conversation as resolved.
try {
// Optimistic update
this._updateLovelace({
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5403,6 +5403,11 @@ deep-extend@^0.6.0, deep-extend@~0.6.0:
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==

deep-freeze@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/deep-freeze/-/deep-freeze-0.0.1.tgz#3a0b0005de18672819dfd38cd31f91179c893e84"
integrity sha1-OgsABd4YZygZ39OM0x+RF5yJPoQ=

deep-is@~0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
Expand Down