mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add back button to history and logbook when coming from more info dialog (#15811)
This commit is contained in:
parent
6cb4b5f429
commit
3afe1f83c7
@ -151,20 +151,34 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
return entity?.device_id ?? null;
|
return entity?.device_id ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setView(view: View) {
|
||||||
|
history.replaceState(
|
||||||
|
{
|
||||||
|
...history.state,
|
||||||
|
dialogParams: {
|
||||||
|
...history.state?.dialogParams,
|
||||||
|
view,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
""
|
||||||
|
);
|
||||||
|
this._currView = view;
|
||||||
|
}
|
||||||
|
|
||||||
private _goBack() {
|
private _goBack() {
|
||||||
if (this._childView) {
|
if (this._childView) {
|
||||||
this._childView = undefined;
|
this._childView = undefined;
|
||||||
} else {
|
} else {
|
||||||
this._currView = "info";
|
this.setView("info");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _goToHistory() {
|
private _goToHistory() {
|
||||||
this._currView = "history";
|
this.setView("history");
|
||||||
}
|
}
|
||||||
|
|
||||||
private _goToSettings(): void {
|
private _goToSettings(): void {
|
||||||
this._currView = "settings";
|
this.setView("settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _showChildView(ev: CustomEvent): Promise<void> {
|
private async _showChildView(ev: CustomEvent): Promise<void> {
|
||||||
@ -206,7 +220,7 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
|
|
||||||
private _goToRelated(ev): void {
|
private _goToRelated(ev): void {
|
||||||
if (!shouldHandleRequestSelectedEvent(ev)) return;
|
if (!shouldHandleRequestSelectedEvent(ev)) return;
|
||||||
this._currView = "related";
|
this.setView("related");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
|
@ -4,6 +4,7 @@ import { customElement, property, state } from "lit/decorators";
|
|||||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { computeDomain } from "../../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
|
import { createSearchParam } from "../../common/url/search-params";
|
||||||
import "../../components/chart/state-history-charts";
|
import "../../components/chart/state-history-charts";
|
||||||
import "../../components/chart/statistics-chart";
|
import "../../components/chart/statistics-chart";
|
||||||
import {
|
import {
|
||||||
@ -100,9 +101,13 @@ export class MoreInfoHistory extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._showMoreHref = `/history?entity_id=${
|
const params = {
|
||||||
this.entityId
|
entity_id: this.entityId,
|
||||||
}&start_date=${startOfYesterday().toISOString()}`;
|
start_date: startOfYesterday().toISOString(),
|
||||||
|
back: "1",
|
||||||
|
};
|
||||||
|
|
||||||
|
this._showMoreHref = `/history?${createSearchParam(params)}`;
|
||||||
|
|
||||||
this._getStateHistory();
|
this._getStateHistory();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import { customElement, property } from "lit/decorators";
|
|||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { createSearchParam } from "../../common/url/search-params";
|
||||||
import "../../panels/logbook/ha-logbook";
|
import "../../panels/logbook/ha-logbook";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
|
||||||
@ -55,9 +56,13 @@ export class MoreInfoLogbook extends LitElement {
|
|||||||
super.willUpdate(changedProps);
|
super.willUpdate(changedProps);
|
||||||
|
|
||||||
if (changedProps.has("entityId") && this.entityId) {
|
if (changedProps.has("entityId") && this.entityId) {
|
||||||
this._showMoreHref = `/logbook?entity_id=${
|
const params = {
|
||||||
this.entityId
|
entity_id: this.entityId,
|
||||||
}&start_date=${startOfYesterday().toISOString()}`;
|
start_date: startOfYesterday().toISOString(),
|
||||||
|
back: "1",
|
||||||
|
};
|
||||||
|
|
||||||
|
this._showMoreHref = `/logbook?${createSearchParam(params)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,11 @@ import { ensureArray } from "../../common/array/ensure-array";
|
|||||||
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
||||||
import { LocalStorage } from "../../common/decorators/local-storage";
|
import { LocalStorage } from "../../common/decorators/local-storage";
|
||||||
import { navigate } from "../../common/navigate";
|
import { navigate } from "../../common/navigate";
|
||||||
|
import { constructUrlCurrentPath } from "../../common/url/construct-url";
|
||||||
import {
|
import {
|
||||||
createSearchParam,
|
createSearchParam,
|
||||||
extractSearchParamsObject,
|
extractSearchParamsObject,
|
||||||
|
removeSearchParam,
|
||||||
} from "../../common/url/search-params";
|
} from "../../common/url/search-params";
|
||||||
import { computeRTL } from "../../common/util/compute_rtl";
|
import { computeRTL } from "../../common/util/compute_rtl";
|
||||||
import { MIN_TIME_BETWEEN_UPDATES } from "../../components/chart/ha-chart-base";
|
import { MIN_TIME_BETWEEN_UPDATES } from "../../components/chart/ha-chart-base";
|
||||||
@ -83,6 +85,9 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _areaDeviceLookup?: AreaDeviceLookup;
|
@state() private _areaDeviceLookup?: AreaDeviceLookup;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private _showBack?: boolean;
|
||||||
|
|
||||||
@query("state-history-charts")
|
@query("state-history-charts")
|
||||||
private _stateHistoryCharts?: StateHistoryCharts;
|
private _stateHistoryCharts?: StateHistoryCharts;
|
||||||
|
|
||||||
@ -126,15 +131,27 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _goBack(): void {
|
||||||
|
history.back();
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<ha-app-layout>
|
<ha-app-layout>
|
||||||
<app-header slot="header" fixed>
|
<app-header slot="header" fixed>
|
||||||
<app-toolbar>
|
<app-toolbar>
|
||||||
<ha-menu-button
|
${this._showBack
|
||||||
.hass=${this.hass}
|
? html`
|
||||||
.narrow=${this.narrow}
|
<ha-icon-button-arrow-prev
|
||||||
></ha-menu-button>
|
@click=${this._goBack}
|
||||||
|
></ha-icon-button-arrow-prev>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<ha-menu-button
|
||||||
|
.hass=${this.hass}
|
||||||
|
.narrow=${this.narrow}
|
||||||
|
></ha-menu-button>
|
||||||
|
`}
|
||||||
<div main-title>${this.hass.localize("panel.history")}</div>
|
<div main-title>${this.hass.localize("panel.history")}</div>
|
||||||
${this._targetPickerValue
|
${this._targetPickerValue
|
||||||
? html`
|
? html`
|
||||||
@ -252,6 +269,17 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
|
super.firstUpdated(changedProps);
|
||||||
|
const searchParams = extractSearchParamsObject();
|
||||||
|
if (searchParams.back === "1" && history.length > 1) {
|
||||||
|
this._showBack = true;
|
||||||
|
navigate(constructUrlCurrentPath(removeSearchParam("back")), {
|
||||||
|
replace: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
if (
|
if (
|
||||||
this._targetPickerValue &&
|
this._targetPickerValue &&
|
||||||
|
@ -14,9 +14,11 @@ import { css, html, LitElement, PropertyValues } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
||||||
import { navigate } from "../../common/navigate";
|
import { navigate } from "../../common/navigate";
|
||||||
|
import { constructUrlCurrentPath } from "../../common/url/construct-url";
|
||||||
import {
|
import {
|
||||||
createSearchParam,
|
createSearchParam,
|
||||||
extractSearchParamsObject,
|
extractSearchParamsObject,
|
||||||
|
removeSearchParam,
|
||||||
} from "../../common/url/search-params";
|
} from "../../common/url/search-params";
|
||||||
import "../../components/entity/ha-entity-picker";
|
import "../../components/entity/ha-entity-picker";
|
||||||
import "../../components/ha-date-range-picker";
|
import "../../components/ha-date-range-picker";
|
||||||
@ -41,6 +43,9 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
|
|
||||||
@state() private _ranges?: DateRangePickerRanges;
|
@state() private _ranges?: DateRangePickerRanges;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private _showBack?: boolean;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -53,15 +58,27 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
this._time = { range: [start, end] };
|
this._time = { range: [start, end] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _goBack(): void {
|
||||||
|
history.back();
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<ha-app-layout>
|
<ha-app-layout>
|
||||||
<app-header slot="header" fixed>
|
<app-header slot="header" fixed>
|
||||||
<app-toolbar>
|
<app-toolbar>
|
||||||
<ha-menu-button
|
${this._showBack
|
||||||
.hass=${this.hass}
|
? html`
|
||||||
.narrow=${this.narrow}
|
<ha-icon-button-arrow-prev
|
||||||
></ha-menu-button>
|
@click=${this._goBack}
|
||||||
|
></ha-icon-button-arrow-prev>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<ha-menu-button
|
||||||
|
.hass=${this.hass}
|
||||||
|
.narrow=${this.narrow}
|
||||||
|
></ha-menu-button>
|
||||||
|
`}
|
||||||
<div main-title>${this.hass.localize("panel.logbook")}</div>
|
<div main-title>${this.hass.localize("panel.logbook")}</div>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
@click=${this._refreshLogbook}
|
@click=${this._refreshLogbook}
|
||||||
@ -132,6 +149,14 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this.hass.loadBackendTranslation("title");
|
this.hass.loadBackendTranslation("title");
|
||||||
|
|
||||||
|
const searchParams = extractSearchParamsObject();
|
||||||
|
if (searchParams.back === "1" && history.length > 1) {
|
||||||
|
this._showBack = true;
|
||||||
|
navigate(constructUrlCurrentPath(removeSearchParam("back")), {
|
||||||
|
replace: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public connectedCallback(): void {
|
public connectedCallback(): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user