Fix more dialogs (#23273)

* Remove unneeded close dialog calls

* more
This commit is contained in:
Bram Kragten 2024-12-12 10:00:38 +01:00 committed by GitHub
parent 7e2217b542
commit 0a413cba03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 35 deletions

View File

@ -142,7 +142,7 @@ export class HaVoiceCommandDialog extends LitElement {
${this.hass.user?.is_admin ${this.hass.user?.is_admin
? html`<li divider role="separator"></li> ? html`<li divider role="separator"></li>
<a href="/config/voice-assistants/assistants" <a href="/config/voice-assistants/assistants"
><ha-list-item @click=${this.closeDialog} ><ha-list-item
>${this.hass.localize( >${this.hass.localize(
"ui.dialogs.voice_command.manage_assistants" "ui.dialogs.voice_command.manage_assistants"
)}</ha-list-item )}</ha-list-item

View File

@ -50,7 +50,7 @@ class DialogCalendarEventDetail extends LitElement {
} }
} }
private _closeDialog(): void { public closeDialog(): void {
this._calendarId = undefined; this._calendarId = undefined;
this._params = undefined; this._params = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
@ -64,7 +64,7 @@ class DialogCalendarEventDetail extends LitElement {
return html` return html`
<ha-dialog <ha-dialog
open open
@closed=${this._closeDialog} @closed=${this.closeDialog}
scrimClickAction scrimClickAction
escapeKeyAction escapeKeyAction
.heading=${createCloseHeading(this.hass, this._data!.summary)} .heading=${createCloseHeading(this.hass, this._data!.summary)}
@ -177,7 +177,7 @@ class DialogCalendarEventDetail extends LitElement {
private async _editEvent() { private async _editEvent() {
showCalendarEventEditDialog(this, this._params!); showCalendarEventEditDialog(this, this._params!);
this._closeDialog(); this.closeDialog();
} }
private async _deleteEvent() { private async _deleteEvent() {
@ -227,7 +227,7 @@ class DialogCalendarEventDetail extends LitElement {
this._submitting = false; this._submitting = false;
} }
await this._params!.updated(); await this._params!.updated();
this._closeDialog(); this.closeDialog();
} }
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {

View File

@ -33,6 +33,8 @@ import { documentationUrl } from "../../../util/documentation-url";
import { showAddUserDialog } from "../users/show-dialog-add-user"; import { showAddUserDialog } from "../users/show-dialog-add-user";
import { showAdminChangePasswordDialog } from "../users/show-dialog-admin-change-password"; import { showAdminChangePasswordDialog } from "../users/show-dialog-admin-change-password";
import type { PersonDetailDialogParams } from "./show-dialog-person-detail"; import type { PersonDetailDialogParams } from "./show-dialog-person-detail";
import { fireEvent } from "../../../common/dom/fire_event";
import type { HassDialog } from "../../../dialogs/make-dialog-manager";
const includeDomains = ["device_tracker"]; const includeDomains = ["device_tracker"];
@ -42,7 +44,7 @@ const cropOptions: CropOptions = {
aspectRatio: 1, aspectRatio: 1,
}; };
class DialogPersonDetail extends LitElement { class DialogPersonDetail extends LitElement implements HassDialog {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@state() private _name!: string; @state() private _name!: string;
@ -101,6 +103,20 @@ class DialogPersonDetail extends LitElement {
await this.updateComplete; await this.updateComplete;
} }
public closeDialog() {
// 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) {
const callback = this._params?.refreshUsers;
deleteUser(this.hass, this._userId).then(() => {
callback?.();
});
this._userId = undefined;
}
this._params = undefined;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}
protected render() { protected render() {
if (!this._params) { if (!this._params) {
return nothing; return nothing;
@ -109,7 +125,7 @@ class DialogPersonDetail extends LitElement {
return html` return html`
<ha-dialog <ha-dialog
open open
@closed=${this._close} @closed=${this.closeDialog}
scrimClickAction scrimClickAction
escapeKeyAction escapeKeyAction
.heading=${createCloseHeading( .heading=${createCloseHeading(
@ -163,7 +179,7 @@ class DialogPersonDetail extends LitElement {
</ha-settings-row> </ha-settings-row>
${this._renderUserFields()} ${this._renderUserFields()}
${this._deviceTrackersAvailable(this.hass) ${!this._deviceTrackersAvailable(this.hass)
? html` ? html`
<p> <p>
${this.hass.localize( ${this.hass.localize(
@ -205,10 +221,7 @@ class DialogPersonDetail extends LitElement {
> >
</li> </li>
<li> <li>
<a <a @click=${this.closeDialog} href="/config/integrations">
@click=${this._closeDialog}
href="/config/integrations"
>
${this.hass!.localize( ${this.hass!.localize(
"ui.panel.config.person.detail.link_integrations_page" "ui.panel.config.person.detail.link_integrations_page"
)}</a )}</a
@ -329,10 +342,6 @@ class DialogPersonDetail extends LitElement {
`; `;
} }
private _closeDialog() {
this._params = undefined;
}
private _nameChanged(ev) { private _nameChanged(ev) {
this._error = undefined; this._error = undefined;
this._name = ev.target.value; this._name = ev.target.value;
@ -496,7 +505,7 @@ class DialogPersonDetail extends LitElement {
await this._params!.createEntry(values); await this._params!.createEntry(values);
this._personExists = true; this._personExists = true;
} }
this._params = undefined; this.closeDialog();
} catch (err: any) { } catch (err: any) {
this._error = err ? err.message : "Unknown error"; this._error = err ? err.message : "Unknown error";
} finally { } finally {
@ -511,25 +520,13 @@ class DialogPersonDetail extends LitElement {
if (this._params!.entry!.user_id) { if (this._params!.entry!.user_id) {
deleteUser(this.hass, this._params!.entry!.user_id); deleteUser(this.hass, this._params!.entry!.user_id);
} }
this._params = undefined; this.closeDialog();
} }
} finally { } finally {
this._submitting = false; this._submitting = false;
} }
} }
private _close(): void {
// 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) {
deleteUser(this.hass, this._userId);
this._params?.refreshUsers();
this._userId = undefined;
}
this._params = undefined;
}
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
haStyleDialog, haStyleDialog,

View File

@ -181,11 +181,7 @@ export class DialogVoiceAssistantPipelineDetail extends LitElement {
${this.hass.localize( ${this.hass.localize(
"ui.panel.config.voice_assistants.assistants.pipeline.detail.no_cloud_message" "ui.panel.config.voice_assistants.assistants.pipeline.detail.no_cloud_message"
)} )}
<a <a href="/config/cloud" slot="action">
href="/config/cloud"
slot="action"
@click=${this.closeDialog}
>
<ha-button> <ha-button>
${this.hass.localize( ${this.hass.localize(
"ui.panel.config.voice_assistants.assistants.pipeline.detail.no_cloud_action" "ui.panel.config.voice_assistants.assistants.pipeline.detail.no_cloud_action"