Fix sidebar for not existing hidden panel (#6944)

Fixes #6940
This commit is contained in:
Bram Kragten 2020-09-12 12:52:37 +02:00 committed by GitHub
parent 8ee29b1e43
commit c979cfb912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -287,27 +287,29 @@ class HaSidebar extends LitElement {
? html` ? html`
${this._hiddenPanels.map((url) => { ${this._hiddenPanels.map((url) => {
const panel = this.hass.panels[url]; const panel = this.hass.panels[url];
if (!panel) {
return "";
}
return html`<paper-icon-item return html`<paper-icon-item
@click=${this._unhidePanel} @click=${this._unhidePanel}
class="hidden-panel" class="hidden-panel"
.panel=${url}
> >
<ha-icon <ha-icon
slot="item-icon" slot="item-icon"
.icon=${panel.url_path === "lovelace" .icon=${panel.url_path === this.hass.defaultPanel
? "mdi:view-dashboard" ? "mdi:view-dashboard"
: panel.icon} : panel.icon}
></ha-icon> ></ha-icon>
<span class="item-text" <span class="item-text"
>${panel.url_path === "lovelace" >${panel.url_path === this.hass.defaultPanel
? hass.localize("panel.states") ? hass.localize("panel.states")
: hass.localize(`panel.${panel.title}`) || : hass.localize(`panel.${panel.title}`) ||
panel.title}</span panel.title}</span
> >
<ha-svg-icon <mwc-icon-button class="hide-panel">
class="hide-panel" <ha-svg-icon .path=${mdiPlus}></ha-svg-icon>
.panel=${url} </mwc-icon-button>
.path=${mdiPlus}
></ha-svg-icon>
</paper-icon-item>`; </paper-icon-item>`;
})} })}
<div class="spacer" disabled></div> <div class="spacer" disabled></div>
@ -544,7 +546,7 @@ class HaSidebar extends LitElement {
private async _unhidePanel(ev: Event) { private async _unhidePanel(ev: Event) {
ev.preventDefault(); ev.preventDefault();
const index = this._hiddenPanels.indexOf((ev.target as any).panel); const index = this._hiddenPanels.indexOf((ev.currentTarget as any).panel);
if (index < 0) { if (index < 0) {
return; return;
} }