From e352768388a48b15c4717594909600609aabb0b1 Mon Sep 17 00:00:00 2001 From: Zack Arnett Date: Wed, 19 Aug 2020 04:02:21 -0500 Subject: [PATCH] Save Config Dialog - Convert to MWC (#6590) --- .../lovelace/editor/hui-dialog-save-config.ts | 139 +++++++++--------- 1 file changed, 73 insertions(+), 66 deletions(-) diff --git a/src/panels/lovelace/editor/hui-dialog-save-config.ts b/src/panels/lovelace/editor/hui-dialog-save-config.ts index 83c46f3593..f056413258 100644 --- a/src/panels/lovelace/editor/hui-dialog-save-config.ts +++ b/src/panels/lovelace/editor/hui-dialog-save-config.ts @@ -1,6 +1,5 @@ import "@material/mwc-button"; -import "@polymer/paper-dialog-scrollable/paper-dialog-scrollable"; -import "../../../components/ha-circular-progress"; +import "@material/mwc-icon-button/mwc-icon-button"; import { css, CSSResult, @@ -9,25 +8,28 @@ import { LitElement, property, internalProperty, - query, TemplateResult, } from "lit-element"; +import { mdiHelpCircle } from "@mdi/js"; import { fireEvent } from "../../../common/dom/fire_event"; -import "../../../components/dialog/ha-paper-dialog"; -import type { HaPaperDialog } from "../../../components/dialog/ha-paper-dialog"; -import "../../../components/ha-switch"; -import "../../../components/ha-formfield"; -import "../../../components/ha-yaml-editor"; -import type { PolymerChangedEvent } from "../../../polymer-types"; import { haStyleDialog } from "../../../resources/styles"; import type { HomeAssistant } from "../../../types"; import type { SaveDialogParams } from "./show-save-config-dialog"; import { computeRTLDirection } from "../../../common/util/compute_rtl"; +import type { HassDialog } from "../../../dialogs/make-dialog-manager"; +import "../../../components/ha-switch"; +import "../../../components/ha-formfield"; +import "../../../components/ha-yaml-editor"; +import "../../../components/ha-svg-icon"; +import "../../../components/ha-dialog"; +import "../../../components/ha-circular-progress"; const EMPTY_CONFIG = { views: [] }; +const coreDocumentationURLBase = "https://www.home-assistant.io/lovelace/"; + @customElement("hui-dialog-save-config") -export class HuiSaveConfig extends LitElement { +export class HuiSaveConfig extends LitElement implements HassDialog { @property({ attribute: false }) public hass?: HomeAssistant; @internalProperty() private _params?: SaveDialogParams; @@ -36,18 +38,20 @@ export class HuiSaveConfig extends LitElement { @internalProperty() private _saving: boolean; - @query("ha-paper-dialog") private _dialog?: HaPaperDialog; - public constructor() { super(); this._saving = false; } - public async showDialog(params: SaveDialogParams): Promise { + public showDialog(params: SaveDialogParams): void { this._params = params; this._emptyConfig = false; - await this.updateComplete; - this._dialog!.open(); + } + + public closeDialog(): boolean { + this._params = undefined; + fireEvent(this, "dialog-closed", { dialog: this.localName }); + return true; } protected render(): TemplateResult { @@ -55,15 +59,27 @@ export class HuiSaveConfig extends LitElement { return html``; } return html` - + + + + `} > -

- ${this.hass!.localize("ui.panel.lovelace.editor.save_config.header")} -

- +

${this.hass!.localize("ui.panel.lovelace.editor.save_config.para")}

@@ -105,55 +121,46 @@ export class HuiSaveConfig extends LitElement {

`} - -
- ${this._params.mode === "storage" - ? html` - ${this.hass!.localize( - "ui.panel.lovelace.editor.save_config.cancel" - )} - - - - ${this.hass!.localize( - "ui.panel.lovelace.editor.save_config.save" - )} - - ` - : html` - ${this.hass!.localize( - "ui.panel.lovelace.editor.save_config.close" - )} - - `}
- + ${this._params.mode === "storage" + ? html` + ${this.hass!.localize( + "ui.panel.lovelace.editor.save_config.cancel" + )} + + + + ${this.hass!.localize( + "ui.panel.lovelace.editor.save_config.save" + )} + + ` + : html` + ${this.hass!.localize( + "ui.panel.lovelace.editor.save_config.close" + )} + + `} + `; } - private _closeDialog(): void { - this._dialog!.close(); - } - - private _openedChanged(ev: PolymerChangedEvent): void { - if (!ev.detail.value) { - this._params = undefined; + private _close(ev?: Event) { + if (ev) { + ev.stopPropagation(); } - } - - private _editorRefreshed() { - fireEvent(this._dialog! as HTMLElement, "iron-resize"); + this.closeDialog(); } private _emptyConfigChanged(ev) { @@ -172,7 +179,7 @@ export class HuiSaveConfig extends LitElement { ); lovelace.setEditMode(true); this._saving = false; - this._closeDialog(); + this.closeDialog(); } catch (err) { alert(`Saving failed: ${err.message}`); this._saving = false;