Remove unneeded close dialog calls

fix-navigate-dialog-close-timing
Bram Kragten 2024-12-12 09:46:12 +01:00
parent a8b8fb4c30
commit 9a6e48a82b
3 changed files with 22 additions and 30 deletions

View File

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

View File

@ -33,6 +33,7 @@ import { documentationUrl } from "../../../util/documentation-url";
import { showAddUserDialog } from "../users/show-dialog-add-user";
import { showAdminChangePasswordDialog } from "../users/show-dialog-admin-change-password";
import type { PersonDetailDialogParams } from "./show-dialog-person-detail";
import { fireEvent } from "../../../common/dom/fire_event";
const includeDomains = ["device_tracker"];
@ -101,6 +102,20 @@ class DialogPersonDetail extends LitElement {
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() {
if (!this._params) {
return nothing;
@ -109,7 +124,7 @@ class DialogPersonDetail extends LitElement {
return html`
<ha-dialog
open
@closed=${this._close}
@closed=${this.closeDialog}
scrimClickAction
escapeKeyAction
.heading=${createCloseHeading(
@ -163,7 +178,7 @@ class DialogPersonDetail extends LitElement {
</ha-settings-row>
${this._renderUserFields()}
${this._deviceTrackersAvailable(this.hass)
${!this._deviceTrackersAvailable(this.hass)
? html`
<p>
${this.hass.localize(
@ -205,10 +220,7 @@ class DialogPersonDetail extends LitElement {
>
</li>
<li>
<a
@click=${this._closeDialog}
href="/config/integrations"
>
<a @click=${this.closeDialog} href="/config/integrations">
${this.hass!.localize(
"ui.panel.config.person.detail.link_integrations_page"
)}</a
@ -329,10 +341,6 @@ class DialogPersonDetail extends LitElement {
`;
}
private _closeDialog() {
this._params = undefined;
}
private _nameChanged(ev) {
this._error = undefined;
this._name = ev.target.value;
@ -496,7 +504,7 @@ class DialogPersonDetail extends LitElement {
await this._params!.createEntry(values);
this._personExists = true;
}
this._params = undefined;
this.closeDialog();
} catch (err: any) {
this._error = err ? err.message : "Unknown error";
} finally {
@ -511,25 +519,13 @@ class DialogPersonDetail extends LitElement {
if (this._params!.entry!.user_id) {
deleteUser(this.hass, this._params!.entry!.user_id);
}
this._params = undefined;
this.closeDialog();
}
} finally {
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 {
return [
haStyleDialog,

View File

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