From 7beadb8108a24545b12abaebcb6f1aebdd37afc1 Mon Sep 17 00:00:00 2001 From: Aidan Timson Date: Wed, 11 Feb 2026 11:07:55 +0000 Subject: [PATCH] Migrate person and user dialogs to wa (#29569) --- .../config/person/dialog-person-detail.ts | 95 ++++++++++--------- src/panels/config/users/dialog-add-user.ts | 77 ++++++++------- .../users/dialog-admin-change-password.ts | 74 +++++++++------ src/panels/config/users/dialog-user-detail.ts | 88 +++++++++-------- 4 files changed, 190 insertions(+), 144 deletions(-) diff --git a/src/panels/config/person/dialog-person-detail.ts b/src/panels/config/person/dialog-person-detail.ts index a3f60e21c9..779b998366 100644 --- a/src/panels/config/person/dialog-person-detail.ts +++ b/src/panels/config/person/dialog-person-detail.ts @@ -6,12 +6,13 @@ import memoizeOne from "memoize-one"; import { fireEvent } from "../../../common/dom/fire_event"; import "../../../components/entity/ha-entities-picker"; import "../../../components/ha-button"; -import { createCloseHeading } from "../../../components/ha-dialog"; +import "../../../components/ha-dialog-footer"; import "../../../components/ha-icon-button"; import "../../../components/ha-picture-upload"; import type { HaPictureUpload } from "../../../components/ha-picture-upload"; import "../../../components/ha-settings-row"; import "../../../components/ha-textfield"; +import "../../../components/ha-wa-dialog"; import { adminChangeUsername } from "../../../data/auth"; import type { PersonMutableParams } from "../../../data/person"; import type { User } from "../../../data/user"; @@ -69,6 +70,8 @@ class DialogPersonDetail extends LitElement implements HassDialog { @state() private _personExists = false; + @state() private _open = false; + private _deviceTrackersAvailable = memoizeOne((hass) => Object.keys(hass.states).some( (entityId) => @@ -100,10 +103,16 @@ class DialogPersonDetail extends LitElement implements HassDialog { this._deviceTrackers = []; this._picture = null; } + this._open = true; await this.updateComplete; } public closeDialog() { + this._open = false; + return true; + } + + private _dialogClosed() { // If we do not have a person ID yet (= person creation dialog was just cancelled), but // we already created a user ID for it, delete it now to not have it "free floating". if (!this._personExists && this._userId) { @@ -115,7 +124,6 @@ class DialogPersonDetail extends LitElement implements HassDialog { } this._params = undefined; fireEvent(this, "dialog-closed", { dialog: this.localName }); - return true; } protected render() { @@ -124,23 +132,20 @@ class DialogPersonDetail extends LitElement implements HassDialog { } const nameInvalid = this._name.trim() === ""; return html` -
${this._error ? html`
${this._error}
` : ""}
- ${this._params.entry - ? html` - - ${this.hass!.localize("ui.panel.config.person.detail.delete")} - - ` - : nothing} - - ${this.hass!.localize("ui.common.cancel")} - - + ${this._params.entry - ? this.hass!.localize("ui.common.save") - : this.hass!.localize("ui.common.add")} - - + ? html` + + ${this.hass!.localize("ui.panel.config.person.detail.delete")} + + ` + : nothing} + + ${this.hass!.localize("ui.common.cancel")} + + + ${this._params.entry + ? this.hass!.localize("ui.common.save") + : this.hass!.localize("ui.common.add")} + + + `; } diff --git a/src/panels/config/users/dialog-add-user.ts b/src/panels/config/users/dialog-add-user.ts index 831f96631e..f13d32180d 100644 --- a/src/panels/config/users/dialog-add-user.ts +++ b/src/panels/config/users/dialog-add-user.ts @@ -1,16 +1,17 @@ import type { CSSResultGroup, PropertyValues } from "lit"; import { LitElement, css, html, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; +import { fireEvent } from "../../../common/dom/fire_event"; import "../../../components/ha-alert"; import "../../../components/ha-button"; -import "../../../components/ha-spinner"; -import { createCloseHeading } from "../../../components/ha-dialog"; +import "../../../components/ha-dialog-footer"; import "../../../components/ha-icon-button"; import "../../../components/ha-settings-row"; import "../../../components/ha-switch"; import type { HaSwitch } from "../../../components/ha-switch"; import "../../../components/ha-textfield"; import type { HaTextField } from "../../../components/ha-textfield"; +import "../../../components/ha-wa-dialog"; import { createAuthForUser } from "../../../data/auth"; import type { User } from "../../../data/user"; import { @@ -35,6 +36,8 @@ export class DialogAddUser extends LitElement { @state() private _params?: AddUserDialogParams; + @state() private _open = false; + @state() private _name?: string; @state() private _username?: string; @@ -66,6 +69,8 @@ export class DialogAddUser extends LitElement { } else { this._allowChangeName = true; } + + this._open = true; } protected firstUpdated(changedProperties: PropertyValues) { @@ -83,15 +88,15 @@ export class DialogAddUser extends LitElement { } return html` -
${this._error ? html`
${this._error}
` : ""} @@ -109,7 +114,7 @@ export class DialogAddUser extends LitElement { )} @input=${this._handleValueChanged} @blur=${this._maybePopulateUsername} - dialogInitialFocus + autofocus >` : ""} - - ${this.hass!.localize("ui.common.cancel")} - - - ${this.hass.localize("ui.panel.config.users.add_user.create")} - - + + + ${this.hass!.localize("ui.common.cancel")} + + + ${this.hass.localize("ui.panel.config.users.add_user.create")} + + + `; } private _close() { + this._open = false; + } + + private _dialogClosed(): void { this._params = undefined; + fireEvent(this, "dialog-closed", { dialog: this.localName }); } private _maybePopulateUsername() { @@ -297,8 +309,7 @@ export class DialogAddUser extends LitElement { return [ haStyleDialog, css` - ha-dialog { - --mdc-dialog-max-width: 500px; + ha-wa-dialog { --dialog-z-index: 10; } .row { diff --git a/src/panels/config/users/dialog-admin-change-password.ts b/src/panels/config/users/dialog-admin-change-password.ts index 67d43cd769..329c5b193f 100644 --- a/src/panels/config/users/dialog-admin-change-password.ts +++ b/src/panels/config/users/dialog-admin-change-password.ts @@ -3,11 +3,12 @@ import { css, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../common/dom/fire_event"; -import { createCloseHeading } from "../../../components/ha-dialog"; +import "../../../components/ha-dialog-footer"; import "../../../components/ha-form/ha-form"; import type { SchemaUnion } from "../../../components/ha-form/types"; import "../../../components/ha-textfield"; import "../../../components/ha-button"; +import "../../../components/ha-wa-dialog"; import { adminChangePassword } from "../../../data/auth"; import { haStyleDialog } from "../../../resources/styles"; import type { HomeAssistant } from "../../../types"; @@ -48,6 +49,8 @@ class DialogAdminChangePassword extends LitElement { @state() private _params?: AdminChangePasswordDialogParams; + @state() private _open = false; + @state() private _userId?: string; @state() private _data?: FormData; @@ -61,11 +64,20 @@ class DialogAdminChangePassword extends LitElement { public showDialog(params: AdminChangePasswordDialogParams): void { this._params = params; this._userId = params.userId; + this._data = undefined; + this._error = undefined; + this._open = true; } public closeDialog(): void { + this._open = false; + } + + private _dialogClosed(): void { this._params = undefined; + this._userId = undefined; this._data = undefined; + this._error = undefined; this._submitting = false; this._success = false; fireEvent(this, "dialog-closed", { dialog: this.localName }); @@ -104,15 +116,14 @@ class DialogAdminChangePassword extends LitElement { ); return html` - ${this._success ? html` @@ -121,12 +132,15 @@ class DialogAdminChangePassword extends LitElement { "ui.panel.config.users.change_password.password_changed" )}

- - ${this.hass.localize("ui.common.ok")} - + + + ${this.hass.localize("ui.common.ok")} + + ` : html` - - ${this.hass.localize("ui.common.cancel")} - - - ${this.hass.localize( - "ui.panel.config.users.change_password.change" - )} - + + + ${this.hass.localize("ui.common.cancel")} + + + ${this.hass.localize( + "ui.panel.config.users.change_password.change" + )} + + `} -
+ `; } diff --git a/src/panels/config/users/dialog-user-detail.ts b/src/panels/config/users/dialog-user-detail.ts index 67374d2c73..1247add47f 100644 --- a/src/panels/config/users/dialog-user-detail.ts +++ b/src/panels/config/users/dialog-user-detail.ts @@ -2,15 +2,17 @@ import { mdiPencil } from "@mdi/js"; import type { CSSResultGroup } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; +import { fireEvent } from "../../../common/dom/fire_event"; import "../../../components/ha-alert"; import "../../../components/ha-button"; -import { createCloseHeading } from "../../../components/ha-dialog"; +import "../../../components/ha-dialog-footer"; import "../../../components/ha-icon-button"; import "../../../components/ha-label"; import "../../../components/ha-settings-row"; import "../../../components/ha-svg-icon"; import "../../../components/ha-switch"; import "../../../components/ha-textfield"; +import "../../../components/ha-wa-dialog"; import { adminChangeUsername } from "../../../data/auth"; import { computeUserBadges, @@ -42,6 +44,8 @@ class DialogUserDetail extends LitElement { @state() private _params?: UserDetailDialogParams; + @state() private _open = false; + @state() private _submitting = false; public async showDialog(params: UserDetailDialogParams): Promise { @@ -51,6 +55,7 @@ class DialogUserDetail extends LitElement { this._isAdmin = params.entry.group_ids.includes(SYSTEM_GROUP_ID_ADMIN); this._localOnly = params.entry.local_only; this._isActive = params.entry.is_active; + this._open = true; await this.updateComplete; } @@ -61,12 +66,13 @@ class DialogUserDetail extends LitElement { const user = this._params.entry; const badges = computeUserBadges(this.hass, user, true); return html` -
${this._error @@ -94,7 +100,7 @@ class DialogUserDetail extends LitElement { ${!user.system_generated ? html` - - ${this.hass!.localize("ui.panel.config.users.editor.delete_user")} - - - ${this.hass!.localize("ui.common.cancel")} - - - ${this.hass!.localize("ui.common.save")} - - + + + ${this.hass!.localize("ui.panel.config.users.editor.delete_user")} + + + ${this.hass!.localize("ui.common.cancel")} + + + ${this.hass!.localize("ui.common.save")} + + + `; } @@ -288,7 +298,7 @@ class DialogUserDetail extends LitElement { this._submitting = true; try { if (await this._params!.removeEntry()) { - this._params = undefined; + this._close(); } } finally { this._submitting = false; @@ -360,16 +370,18 @@ class DialogUserDetail extends LitElement { } private _close(): void { + this._open = false; + } + + private _dialogClosed(): void { this._params = undefined; + fireEvent(this, "dialog-closed", { dialog: this.localName }); } static get styles(): CSSResultGroup { return [ haStyleDialog, css` - ha-dialog { - --mdc-dialog-max-width: 500px; - } .form { padding-top: 16px; }