mirror of
https://github.com/home-assistant/frontend.git
synced 2026-02-04 01:10:33 -06:00
Fix back button in energy panel (#29214)
This commit is contained in:
parent
b991a8122b
commit
0fbde5024e
@ -115,6 +115,8 @@ class PanelEnergy extends LitElement {
|
||||
@state()
|
||||
private _prefs?: EnergyPreferences;
|
||||
|
||||
@state() private _searchParms = new URLSearchParams(window.location.search);
|
||||
|
||||
@state()
|
||||
private _error?: string;
|
||||
|
||||
@ -248,6 +250,8 @@ class PanelEnergy extends LitElement {
|
||||
.lovelace=${this._lovelace}
|
||||
.route=${this.route}
|
||||
.panel=${this.panel}
|
||||
.backButton=${this._searchParms.has("historyBack")}
|
||||
.backPath=${this._searchParms.get("backPath") || "/"}
|
||||
.extraActionItems=${this._extraActionItems}
|
||||
@reload-energy-panel=${this._reloadConfig}
|
||||
class=${classMap({ "has-period-selector": showEnergySelector })}
|
||||
|
||||
@ -65,6 +65,17 @@ class HuiEnergyDistrubutionCard
|
||||
];
|
||||
}
|
||||
|
||||
private get _energyDashboardHref(): string {
|
||||
const params = new URLSearchParams({
|
||||
historyBack: "1",
|
||||
});
|
||||
const backPath = window.location.pathname;
|
||||
if (backPath) {
|
||||
params.append("backPath", backPath);
|
||||
}
|
||||
return `/energy?${params.toString()}`;
|
||||
}
|
||||
|
||||
public getCardSize(): Promise<number> | number {
|
||||
return 3;
|
||||
}
|
||||
@ -789,7 +800,11 @@ class HuiEnergyDistrubutionCard
|
||||
${this._config.link_dashboard
|
||||
? html`
|
||||
<div class="card-actions">
|
||||
<ha-button appearance="plain" size="small" href="/energy">
|
||||
<ha-button
|
||||
appearance="plain"
|
||||
size="small"
|
||||
href=${this._energyDashboardHref}
|
||||
>
|
||||
${this.hass.localize(
|
||||
"ui.panel.lovelace.cards.energy.energy_distribution.go_to_energy_dashboard"
|
||||
)}
|
||||
|
||||
@ -146,6 +146,10 @@ class HUIRoot extends LitElement {
|
||||
|
||||
@property({ type: Boolean, attribute: "no-edit" }) public noEdit = false;
|
||||
|
||||
@property({ attribute: false }) public backButton = false;
|
||||
|
||||
@property({ attribute: false }) public backPath?: string;
|
||||
|
||||
@state() private _curView?: number | "hass-unused-entities";
|
||||
|
||||
private _configChangedByUndo = false;
|
||||
@ -567,7 +571,7 @@ class HUIRoot extends LitElement {
|
||||
<div class="action-items">${this._renderActionItems()}</div>
|
||||
`
|
||||
: html`
|
||||
${isSubview
|
||||
${isSubview || this.backButton
|
||||
? html`
|
||||
<ha-icon-button-arrow-prev
|
||||
.hass=${this.hass}
|
||||
@ -880,6 +884,8 @@ class HUIRoot extends LitElement {
|
||||
|
||||
if (curViewConfig?.back_path != null) {
|
||||
navigate(curViewConfig.back_path, { replace: true });
|
||||
} else if (this.backPath) {
|
||||
navigate(this.backPath, { replace: true });
|
||||
} else if (history.length > 1) {
|
||||
goBack();
|
||||
} else if (!views[0].subview) {
|
||||
|
||||
@ -305,7 +305,9 @@ export class HomeOverviewViewStrategy extends ReactiveElement {
|
||||
summary: "energy",
|
||||
tap_action: {
|
||||
action: "navigate",
|
||||
navigation_path: "/energy?historyBack=1",
|
||||
navigation_path: config.home_panel
|
||||
? "/energy?historyBack=1&backPath=/home"
|
||||
: "/energy?historyBack=1",
|
||||
},
|
||||
} satisfies HomeSummaryCard),
|
||||
].filter(Boolean) as LovelaceCardConfig[];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user