From 21263a1ffb83ae8fce9a36eced4b64daf011db0e Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 2 Apr 2024 12:45:39 +0200 Subject: [PATCH] Improve more info dialog navigation for specific view (#20312) --- src/dialogs/more-info/ha-more-info-dialog.ts | 55 +++++++++++++++++--- src/translations/en.json | 1 + 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/dialogs/more-info/ha-more-info-dialog.ts b/src/dialogs/more-info/ha-more-info-dialog.ts index ecc3411f08..33413df92b 100644 --- a/src/dialogs/more-info/ha-more-info-dialog.ts +++ b/src/dialogs/more-info/ha-more-info-dialog.ts @@ -77,6 +77,8 @@ declare global { } } +const DEFAULT_VIEW: View = "info"; + @customElement("ha-more-info-dialog") export class MoreInfoDialog extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -85,7 +87,9 @@ export class MoreInfoDialog extends LitElement { @state() private _entityId?: string | null; - @state() private _currView: View = "info"; + @state() private _currView: View = DEFAULT_VIEW; + + @state() private _initialView: View = DEFAULT_VIEW; @state() private _childView?: ChildView; @@ -102,7 +106,8 @@ export class MoreInfoDialog extends LitElement { this.closeDialog(); return; } - this._currView = params.view || "info"; + this._currView = params.view || DEFAULT_VIEW; + this._initialView = params.view || DEFAULT_VIEW; this._childView = undefined; this.large = false; this._loadEntityRegistryEntry(); @@ -127,6 +132,7 @@ export class MoreInfoDialog extends LitElement { this._entry = undefined; this._childView = undefined; this._infoEditMode = false; + this._initialView = DEFAULT_VIEW; fireEvent(this, "dialog-closed", { dialog: this.localName }); } @@ -183,10 +189,15 @@ export class MoreInfoDialog extends LitElement { if (this._childView) { this._childView = undefined; } else { - this.setView("info"); + this.setView(this._initialView); } } + private _resetInitialView() { + this._initialView = DEFAULT_VIEW; + this.setView(DEFAULT_VIEW); + } + private _goToHistory() { this.setView("history"); } @@ -262,7 +273,10 @@ export class MoreInfoDialog extends LitElement { const title = this._childView?.viewTitle ?? name; - const isInfoView = this._currView === "info" && !this._childView; + const isDefaultView = this._currView === DEFAULT_VIEW && !this._childView; + const isSpecificInitialView = + this._initialView !== DEFAULT_VIEW && !this._childView; + const showCloseIcon = isDefaultView || isSpecificInitialView; return html` - ${isInfoView + ${showCloseIcon ? html` ${title} - ${isInfoView + ${isDefaultView ? html` ${this.shouldShowHistory(domain) ? html` @@ -407,7 +421,34 @@ export class MoreInfoDialog extends LitElement { ` : nothing} ` - : nothing} + : isSpecificInitialView + ? html` + + + + + ${this.hass.localize("ui.dialogs.more_info_control.info")} + + + + ` + : nothing}