diff --git a/src/panels/lovelace/editor/view-editor/hui-dialog-edit-view.ts b/src/panels/lovelace/editor/view-editor/hui-dialog-edit-view.ts index 4d67c4dbf6..498a7890dc 100644 --- a/src/panels/lovelace/editor/view-editor/hui-dialog-edit-view.ts +++ b/src/panels/lovelace/editor/view-editor/hui-dialog-edit-view.ts @@ -23,7 +23,6 @@ import "../../../../components/ha-dialog"; import "../../../../components/ha-dialog-header"; import "../../../../components/ha-yaml-editor"; import type { HaYamlEditor } from "../../../../components/ha-yaml-editor"; -import { LovelaceBadgeConfig } from "../../../../data/lovelace/config/badge"; import { LovelaceViewConfig, isStrategyView, @@ -61,8 +60,6 @@ export class HuiDialogEditView extends LitElement { @state() private _config?: LovelaceViewConfig; - @state() private _badges?: LovelaceBadgeConfig[]; - @state() private _saving = false; @state() private _curTab?: string; @@ -88,7 +85,6 @@ export class HuiDialogEditView extends LitElement { if (this._yamlMode && changedProperties.has("_yamlMode")) { const viewConfig = { ...this._config, - badges: this._badges, }; this._editor?.setValue(viewConfig); } @@ -99,7 +95,6 @@ export class HuiDialogEditView extends LitElement { if (this._params.viewIndex === undefined) { this._config = {}; - this._badges = []; this._dirty = false; return; } @@ -108,19 +103,15 @@ export class HuiDialogEditView extends LitElement { if (isStrategyView(view)) { const { strategy, ...viewConfig } = view; this._config = viewConfig; - this._badges = []; return; } - const { badges, ...viewConfig } = view; - this._config = viewConfig; - this._badges = badges ? processEditorEntities(badges) : []; + this._config = view; } public closeDialog(): void { this._curTabIndex = 0; this._params = undefined; this._config = {}; - this._badges = []; this._yamlMode = false; this._dirty = false; fireEvent(this, "dialog-closed", { dialog: this.localName }); @@ -166,7 +157,7 @@ export class HuiDialogEditView extends LitElement { break; case "tab-badges": content = html` - ${this._badges?.length + ${this._config?.badges?.length ? html` ${VIEWS_NO_BADGE_SUPPORT.includes(this._type) ? html` @@ -178,7 +169,7 @@ export class HuiDialogEditView extends LitElement { ` : nothing}
- ${this._badges.map( + ${this._config.badges.map( (badgeConfig) => html` `; @@ -420,9 +411,9 @@ export class HuiDialogEditView extends LitElement { } this._saving = true; - const viewConf: LovelaceViewConfig = { + + const viewConf = { ...this._config, - badges: this._badges, }; if (viewConf.type === SECTION_VIEW_LAYOUT && !viewConf.sections?.length) { @@ -487,10 +478,13 @@ export class HuiDialogEditView extends LitElement { } private _badgesChanged(ev: EntitiesEditorEvent): void { - if (!this._badges || !this.hass || !ev.detail || !ev.detail.entities) { + if (!this.hass || !ev.detail || !ev.detail.entities) { return; } - this._badges = processEditorEntities(ev.detail.entities); + this._config = { + ...this._config, + badges: processEditorEntities(ev.detail.entities), + }; this._dirty = true; } @@ -501,7 +495,6 @@ export class HuiDialogEditView extends LitElement { } const { badges, ...config } = ev.detail.value; this._config = config; - this._badges = badges; this._dirty = true; }