Skip to content

Commit

Permalink
Fix badges not saved in view editor (#19971)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Mar 4, 2024
1 parent b5bb6c6 commit 88ccbcd
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/panels/lovelace/editor/view-editor/hui-dialog-edit-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -99,7 +95,6 @@ export class HuiDialogEditView extends LitElement {

if (this._params.viewIndex === undefined) {
this._config = {};
this._badges = [];
this._dirty = false;
return;
}
Expand All @@ -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 });
Expand Down Expand Up @@ -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`
Expand All @@ -178,7 +169,7 @@ export class HuiDialogEditView extends LitElement {
`
: nothing}
<div class="preview-badges">
${this._badges.map(
${this._config.badges.map(
(badgeConfig) => html`
<hui-badge-preview
.hass=${this.hass}
Expand All @@ -191,7 +182,7 @@ export class HuiDialogEditView extends LitElement {
: nothing}
<hui-entity-editor
.hass=${this.hass}
.entities=${this._badges}
.entities=${this._config?.badges || []}
@entities-changed=${this._badgesChanged}
></hui-entity-editor>
`;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -501,7 +495,6 @@ export class HuiDialogEditView extends LitElement {
}
const { badges, ...config } = ev.detail.value;
this._config = config;
this._badges = badges;
this._dirty = true;
}

Expand Down

0 comments on commit 88ccbcd

Please sign in to comment.