1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-02 00:27:49 +01:00

Enhance delete entity confirmation dialog with detailed information (#30293)

This commit is contained in:
Jan-Philipp Benecke
2026-03-24 09:43:46 +01:00
committed by GitHub
parent c8f4c892f9
commit 9cbc44123e
2 changed files with 60 additions and 4 deletions

View File

@@ -1,7 +1,8 @@
import type { HassEntity } from "home-assistant-js-websocket";
import type { CSSResultGroup, PropertyValues } from "lit";
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { formatListWithAnds } from "../../../common/string/format-list";
import { fireEvent } from "../../../common/dom/fire_event";
import "../../../components/ha-alert";
import "../../../components/ha-button";
@@ -16,6 +17,7 @@ import {
removeEntityRegistryEntry,
updateEntityRegistryEntry,
} from "../../../data/entity/entity_registry";
import { findRelated } from "../../../data/search";
import { fetchIntegrationManifest } from "../../../data/integration";
import {
showAlertDialog,
@@ -27,6 +29,9 @@ import type { HomeAssistant } from "../../../types";
import { showDeviceRegistryDetailDialog } from "../devices/device-registry-detail/show-dialog-device-registry-detail";
import "./entity-registry-settings-editor";
import type { EntityRegistrySettingsEditor } from "./entity-registry-settings-editor";
import { computeEntityEntryName } from "../../../common/entity/compute_entity_name";
const RELATED_ENTITY_DOMAINS = ["automation", "script", "group", "scene"];
@customElement("entity-registry-settings")
export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
@@ -209,11 +214,14 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
}
private async _confirmDeleteEntry(): Promise<void> {
const confirmationText = await this._getDeleteConfirmationText();
if (
!(await showConfirmationDialog(this, {
text: this.hass.localize(
"ui.dialogs.entity_registry.editor.confirm_delete"
title: this.hass.localize(
"ui.dialogs.entity_registry.editor.confirm_delete_title"
),
text: confirmationText,
confirmText: this.hass.localize("ui.common.delete"),
dismissText: this.hass.localize("ui.common.cancel"),
destructive: true,
@@ -236,6 +244,46 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
}
}
private async _getDeleteConfirmationText(): Promise<string | TemplateResult> {
const mainText = this.hass.localize(
"ui.dialogs.entity_registry.editor.confirm_delete",
{ entity_name: computeEntityEntryName(this.entry) }
);
try {
const related = await findRelated(
this.hass,
"entity",
this.entry.entity_id
);
const relatedItems = RELATED_ENTITY_DOMAINS.map((domain) => {
const count = related[domain]?.length || 0;
if (count === 0) {
return undefined;
}
return this.hass.localize(
`ui.dialogs.entity_registry.editor.confirm_delete_count.${domain}`,
{ count }
);
}).filter((item): item is string => Boolean(item));
if (relatedItems.length === 0) {
return mainText;
}
return html`${mainText} <br /><br />
${this.hass.localize(
"ui.dialogs.entity_registry.editor.confirm_delete_related",
{
items: formatListWithAnds(this.hass.locale, relatedItems),
}
)}`;
} catch (_err) {
return mainText;
}
}
static get styles(): CSSResultGroup {
return [
haStyle,

View File

@@ -1825,7 +1825,15 @@
"enabled_restart_confirm": "Restart Home Assistant to finish enabling the entities",
"hidden_explanation": "Hidden entities will not be included in auto-populated dashboards or when their area, device or label is referenced. Their history is still tracked and you can still interact with them with actions.",
"delete": "Delete",
"confirm_delete": "Are you sure you want to delete this entity?",
"confirm_delete_title": "Delete entity",
"confirm_delete": "Deleting \"{entity_name}\" is an irreversible action. Are you sure you want to continue?",
"confirm_delete_related": "This entity is part of {items}. If you delete it, you will need to update those manually.",
"confirm_delete_count": {
"automation": "{count} {count, plural,\n one {automation}\n other {automations}\n}",
"script": "{count} {count, plural,\n one {script}\n other {scripts}\n}",
"group": "{count} {count, plural,\n one {group}\n other {groups}\n}",
"scene": "{count} {count, plural,\n one {scene}\n other {scenes}\n}"
},
"update": "Update",
"note": "Note: This might not work yet with all integrations.",
"use_device_area": "Use device area",