1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 02:38:53 +00:00

Migrate dialog-download-decrypted-backup to ha-wa-dialog (#28442)

* Migrate dialog-download-decrypted-backup.ts from ha-md-dialog to ha-wa-dialog

* Fixes from other migrations
This commit is contained in:
Aidan Timson
2025-12-09 07:28:44 +00:00
committed by GitHub
parent 47d1fdf673
commit 41cabde393

View File

@@ -1,18 +1,12 @@
import { mdiClose } from "@mdi/js";
import type { CSSResultGroup } from "lit"; import type { CSSResultGroup } from "lit";
import { LitElement, css, html, nothing } from "lit"; import { LitElement, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../../common/dom/fire_event"; import { fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-dialog-header";
import "../../../../components/ha-icon-button";
import "../../../../components/ha-icon-next";
import "../../../../components/ha-md-dialog";
import type { HaMdDialog } from "../../../../components/ha-md-dialog";
import "../../../../components/ha-md-list";
import "../../../../components/ha-md-list-item";
import "../../../../components/ha-svg-icon";
import "../../../../components/ha-password-field";
import "../../../../components/ha-alert"; import "../../../../components/ha-alert";
import "../../../../components/ha-button";
import "../../../../components/ha-dialog-footer";
import "../../../../components/ha-wa-dialog";
import "../../../../components/ha-password-field";
import { import {
canDecryptBackupOnDownload, canDecryptBackupOnDownload,
getPreferredAgentForDownload, getPreferredAgentForDownload,
@@ -27,102 +21,96 @@ import type { DownloadDecryptedBackupDialogParams } from "./show-dialog-download
class DialogDownloadDecryptedBackup extends LitElement implements HassDialog { class DialogDownloadDecryptedBackup extends LitElement implements HassDialog {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@state() private _opened = false; @state() private _open = false;
@state() private _params?: DownloadDecryptedBackupDialogParams; @state() private _params?: DownloadDecryptedBackupDialogParams;
@query("ha-md-dialog") private _dialog?: HaMdDialog;
@state() private _encryptionKey = ""; @state() private _encryptionKey = "";
@state() private _error = ""; @state() private _error = "";
public showDialog(params: DownloadDecryptedBackupDialogParams): void { public showDialog(params: DownloadDecryptedBackupDialogParams): void {
this._opened = true; this._open = true;
this._params = params; this._params = params;
} }
public closeDialog() { public closeDialog() {
this._dialog?.close(); this._open = false;
return true; return true;
} }
private _dialogClosed() { private _dialogClosed() {
if (this._opened) { if (this._open) {
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
this._opened = false; this._open = false;
this._params = undefined; this._params = undefined;
this._encryptionKey = ""; this._encryptionKey = "";
this._error = ""; this._error = "";
} }
protected render() { protected render() {
if (!this._opened || !this._params) { if (!this._params) {
return nothing; return nothing;
} }
return html` return html`
<ha-md-dialog open @closed=${this._dialogClosed} disable-cancel-action> <ha-wa-dialog
<ha-dialog-header slot="headline"> .hass=${this.hass}
<ha-icon-button .open=${this._open}
slot="navigationIcon" header-title=${this.hass.localize(
@click=${this.closeDialog} "ui.panel.config.backup.dialogs.download.title"
.label=${this.hass.localize("ui.common.close")} )}
.path=${mdiClose} prevent-scrim-close
></ha-icon-button> @closed=${this._dialogClosed}
<span slot="title"> >
${this.hass.localize( <p>
"ui.panel.config.backup.dialogs.download.title" ${this.hass.localize(
)} "ui.panel.config.backup.dialogs.download.description"
</span> )}
</ha-dialog-header> </p>
<p>
${this.hass.localize(
"ui.panel.config.backup.dialogs.download.download_backup_encrypted",
{
download_it_encrypted: html`<button
class="link"
@click=${this._downloadEncrypted}
>
${this.hass.localize(
"ui.panel.config.backup.dialogs.download.download_it_encrypted"
)}
</button>`,
}
)}
</p>
<div slot="content"> <ha-password-field
<p> .label=${this.hass.localize(
${this.hass.localize( "ui.panel.config.backup.dialogs.download.encryption_key"
"ui.panel.config.backup.dialogs.download.description" )}
)} @input=${this._keyChanged}
</p> ></ha-password-field>
<p>
${this.hass.localize(
"ui.panel.config.backup.dialogs.download.download_backup_encrypted",
{
download_it_encrypted: html`<button
class="link"
@click=${this._downloadEncrypted}
>
${this.hass.localize(
"ui.panel.config.backup.dialogs.download.download_it_encrypted"
)}
</button>`,
}
)}
</p>
<ha-password-field ${this._error
.label=${this.hass.localize( ? html`<ha-alert alert-type="error">${this._error}</ha-alert>`
"ui.panel.config.backup.dialogs.download.encryption_key" : nothing}
)} <ha-dialog-footer slot="footer">
@input=${this._keyChanged} <ha-button
></ha-password-field> slot="secondaryAction"
appearance="plain"
${this._error @click=${this._cancel}
? html`<ha-alert alert-type="error">${this._error}</ha-alert>` >
: nothing}
</div>
<div slot="actions">
<ha-button appearance="plain" @click=${this._cancel}>
${this.hass.localize("ui.common.cancel")} ${this.hass.localize("ui.common.cancel")}
</ha-button> </ha-button>
<ha-button @click=${this._submit}> <ha-button slot="primaryAction" @click=${this._submit}>
${this.hass.localize( ${this.hass.localize(
"ui.panel.config.backup.dialogs.download.download" "ui.panel.config.backup.dialogs.download.download"
)} )}
</ha-button> </ha-button>
</div> </ha-dialog-footer>
</ha-md-dialog> </ha-wa-dialog>
`; `;
} }
@@ -191,17 +179,8 @@ class DialogDownloadDecryptedBackup extends LitElement implements HassDialog {
haStyle, haStyle,
haStyleDialog, haStyleDialog,
css` css`
ha-md-dialog { ha-wa-dialog {
--dialog-content-padding: 8px 24px; --dialog-content-padding: var(--ha-space-2) var(--ha-space-6);
max-width: 500px;
}
@media all and (max-width: 450px), all and (max-height: 500px) {
ha-md-dialog {
max-width: none;
}
div[slot="content"] {
margin-top: 0;
}
} }
button.link { button.link {