Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/dialogs/make-dialog-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export const showDialog = async (
dialogElement.showDialog(dialogParams);
};

export const replaceDialog = () => {
history.replaceState({ ...history.state, replaced: true }, "");
};

export const closeDialog = async (dialogTag: string): Promise<boolean> => {
if (!(dialogTag in LOADED)) {
return true;
Expand Down
2 changes: 2 additions & 0 deletions src/dialogs/more-info/ha-more-info-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import "./controls/more-info-default";
import "./ha-more-info-history";
import "./ha-more-info-logbook";
import "./more-info-content";
import { replaceDialog } from "../make-dialog-manager";

const DOMAINS_NO_INFO = ["camera", "configurator"];
/**
Expand Down Expand Up @@ -293,6 +294,7 @@ export class MoreInfoDialog extends LitElement {
}

private _gotoSettings() {
replaceDialog();
showEntityEditorDialog(this, {
entity_id: this._entityId!,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
property,
TemplateResult,
} from "lit-element";
import { fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-dialog";
import {
DeviceAction,
Expand All @@ -22,6 +23,7 @@ import "./ha-device-actions-card";
import "./ha-device-conditions-card";
import "./ha-device-triggers-card";
import { DeviceAutomationDialogParams } from "./show-dialog-device-automation";
import "@material/mwc-button/mwc-button";

@customElement("dialog-device-automation")
export class DialogDeviceAutomation extends LitElement {
Expand All @@ -40,6 +42,11 @@ export class DialogDeviceAutomation extends LitElement {
await this.updateComplete;
}

public closeDialog(): void {
this._params = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}

protected firstUpdated(changedProps) {
super.firstUpdated(changedProps);
this.hass.loadBackendTranslation("device_automation");
Expand Down Expand Up @@ -84,14 +91,14 @@ export class DialogDeviceAutomation extends LitElement {
return html`
<ha-dialog
open
@closing="${this._close}"
@closed=${this.closeDialog}
.heading=${this.hass.localize(
`ui.panel.config.devices.${
this._params.script ? "script" : "automation"
}.create`
)}
>
<div @chip-clicked=${this._close}>
<div @chip-clicked=${this.closeDialog}>
${this._triggers.length ||
this._conditions.length ||
this._actions.length
Expand Down Expand Up @@ -126,17 +133,13 @@ export class DialogDeviceAutomation extends LitElement {
"ui.panel.config.devices.automation.no_device_automations"
)}
</div>
<mwc-button slot="primaryAction" @click="${this._close}">
Close
<mwc-button slot="primaryAction" @click=${this.closeDialog}>
${this.hass.localize("ui.common.close")}
</mwc-button>
</ha-dialog>
`;
}

private _close(): void {
this._params = undefined;
}

static get styles(): CSSResult {
return haStyleDialog;
}
Expand Down
2 changes: 2 additions & 0 deletions src/panels/config/entities/dialog-entity-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { documentationUrl } from "../../../util/documentation-url";
import { PLATFORMS_WITH_SETTINGS_TAB } from "./const";
import "./entity-registry-settings";
import type { EntityRegistryDetailDialogParams } from "./show-dialog-entity-editor";
import { replaceDialog } from "../../../dialogs/make-dialog-manager";

interface Tabs {
[key: string]: Tab;
Expand Down Expand Up @@ -235,6 +236,7 @@ export class DialogEntityEditor extends LitElement {
}

private _openMoreInfo(): void {
replaceDialog();
fireEvent(this, "hass-more-info", {
entityId: this._params!.entity_id,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { haStyleDialog } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types";
import type { Lovelace } from "../../types";
import "./hui-lovelace-editor";
import { fireEvent } from "../../../../common/dom/fire_event";

@customElement("hui-dialog-edit-lovelace")
export class HuiDialogEditLovelace extends LitElement {
Expand Down Expand Up @@ -46,6 +47,12 @@ export class HuiDialogEditLovelace extends LitElement {
this._dialog.open();
}

public closeDialog(): void {
this._config = undefined;
this._dialog.close();
fireEvent(this, "dialog-closed", { dialog: this.localName });
}

private get _dialog(): HaPaperDialog {
return this.shadowRoot!.querySelector("ha-paper-dialog")!;
}
Expand All @@ -69,7 +76,7 @@ export class HuiDialogEditLovelace extends LitElement {
></hui-lovelace-editor
></paper-dialog-scrollable>
<div class="paper-dialog-buttons">
<mwc-button @click="${this._closeDialog}"
<mwc-button @click=${this.closeDialog}
>${this.hass!.localize("ui.common.cancel")}</mwc-button
>
<mwc-button
Expand All @@ -90,17 +97,12 @@ export class HuiDialogEditLovelace extends LitElement {
`;
}

private _closeDialog(): void {
this._config = undefined;
this._dialog.close();
}

private async _save(): Promise<void> {
if (!this._config) {
return;
}
if (!this._isConfigChanged()) {
this._closeDialog();
this.closeDialog();
return;
}

Expand All @@ -114,7 +116,7 @@ export class HuiDialogEditLovelace extends LitElement {

try {
await lovelace.saveConfig(config);
this._closeDialog();
this.closeDialog();
} catch (err) {
alert(`Saving failed: ${err.message}`);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
LovelaceConfig,
LovelaceDashboard,
} from "../../../../data/lovelace";
import { fireEvent } from "../../../../common/dom/fire_event";
import { haStyleDialog } from "../../../../resources/styles";
import { HomeAssistant } from "../../../../types";
import "../../components/hui-views-list";
Expand Down Expand Up @@ -45,6 +46,7 @@ export class HuiDialogSelectView extends LitElement {

public closeDialog(): void {
this._params = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}

protected render(): TemplateResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
property,
TemplateResult,
} from "lit-element";
import { HASSDomEvent } from "../../../../common/dom/fire_event";
import { fireEvent, HASSDomEvent } from "../../../../common/dom/fire_event";
import { navigate } from "../../../../common/navigate";
import "../../../../components/ha-circular-progress";
import "../../../../components/ha-dialog";
Expand Down Expand Up @@ -82,6 +82,7 @@ export class HuiDialogEditView extends LitElement {
this._params = undefined;
this._config = {};
this._badges = [];
fireEvent(this, "dialog-closed", { dialog: this.localName });
}

private get _viewConfigTitle(): string {
Expand Down
8 changes: 8 additions & 0 deletions src/state/url-sync-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export const urlSyncMixin = <

private _popstateChangeListener = (ev: PopStateEvent) => {
if (this._ignoreNextPopState) {
if (ev.state?.oldState?.replaced) {
// if the previous dialog was replaced, and the current dialog is closed, we should also remove the replaced dialog from history
if (DEBUG) {
console.log("remove old state", ev.state.oldState);
}
history.back();
return;
}
this._ignoreNextPopState = false;
return;
}
Expand Down