-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Freeze lovelace configuration on load #4862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
775f00d
b60a5f5
f0a1535
ad1641f
eb0bffd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||
|
|
@@ -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 }; | ||
| checkedConfig.views[index].badges = view.badges.filter(Boolean); | ||
| } | ||
| }); | ||
| return checkedConfig ? deepFreeze(checkedConfig) : config; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will now only freeze the config when there are faulty badges.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
@@ -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); | ||
|
thomasloven marked this conversation as resolved.
|
||
| try { | ||
| // Optimistic update | ||
| this._updateLovelace({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.