diff --git a/src/panels/config/areas/dialog-area-registry-detail.ts b/src/panels/config/areas/dialog-area-registry-detail.ts index 98367f9a0c..2fdfefeb88 100644 --- a/src/panels/config/areas/dialog-area-registry-detail.ts +++ b/src/panels/config/areas/dialog-area-registry-detail.ts @@ -1,5 +1,3 @@ -import "@material/mwc-button"; -import "@material/mwc-list/mwc-list"; import type { CSSResultGroup } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { property, state } from "lit/decorators"; @@ -7,7 +5,6 @@ import type { HassEntity } from "home-assistant-js-websocket"; import { fireEvent } from "../../../common/dom/fire_event"; import "../../../components/ha-alert"; import "../../../components/ha-aliases-editor"; -import { createCloseHeading } from "../../../components/ha-dialog"; import "../../../components/ha-picture-upload"; import type { HaPictureUpload } from "../../../components/ha-picture-upload"; import "../../../components/ha-settings-row"; @@ -17,7 +14,11 @@ import "../../../components/entity/ha-entity-picker"; import type { HaEntityPicker } from "../../../components/entity/ha-entity-picker"; import "../../../components/ha-textfield"; import "../../../components/ha-labels-picker"; -import type { AreaRegistryEntryMutableParams } from "../../../data/area_registry"; +import type { + AreaRegistryEntry, + AreaRegistryEntryMutableParams, +} from "../../../data/area_registry"; +import { deleteAreaRegistryEntry } from "../../../data/area_registry"; import type { CropOptions } from "../../../dialogs/image-cropper-dialog/show-image-cropper-dialog"; import { haStyleDialog } from "../../../resources/styles"; import type { HomeAssistant, ValueChangedEvent } from "../../../types"; @@ -26,6 +27,8 @@ import { SENSOR_DEVICE_CLASS_HUMIDITY, SENSOR_DEVICE_CLASS_TEMPERATURE, } from "../../../data/sensor"; +import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; +import { createCloseHeading } from "../../../components/ha-dialog"; const cropOptions: CropOptions = { round: false, @@ -97,6 +100,130 @@ class DialogAreaDetail extends LitElement { fireEvent(this, "dialog-closed", { dialog: this.localName }); } + private _renderSettings(entry: AreaRegistryEntry | undefined) { + return html` + ${entry + ? html` + + + ${this.hass.localize("ui.panel.config.areas.editor.area_id")} + + ${entry.area_id} + + ` + : nothing} + + + + + + + + + + + `; + } + + private _renderAliasExpansion() { + return html` + +
+

+ ${this.hass.localize( + "ui.panel.config.areas.editor.aliases_description" + )} +

+ +
+
+ `; + } + + private _renderRelatedEntitiesExpansion() { + return html` + +
+ + + +
+
+ `; + } + protected render() { if (!this._params) { return nothing; @@ -104,6 +231,7 @@ class DialogAreaDetail extends LitElement { const entry = this._params.entry; const nameInvalid = !this._isNameValid(); const isNew = !entry; + return html` ${this._error}` : ""}
- ${entry - ? html` - - - ${this.hass.localize( - "ui.panel.config.areas.editor.area_id" - )} - - ${entry.area_id} - - ` - : nothing} - - - - - - - - - - - -

- ${this.hass.localize( - "ui.panel.config.areas.editor.aliases_section" - )} -

- -

- ${this.hass.localize( - "ui.panel.config.areas.editor.aliases_description" - )} -

- - - ${!isNew - ? html` - - - - ` - : ""} + ${this._renderSettings(entry)} ${this._renderAliasExpansion()} + ${!isNew ? this._renderRelatedEntitiesExpansion() : nothing}
- - ${this.hass.localize("ui.common.cancel")} - - - ${entry - ? this.hass.localize("ui.common.save") - : this.hass.localize("ui.common.create")} - + ${!isNew + ? html` + ${this.hass.localize("ui.common.delete")} + ` + : nothing} +
+ + ${this.hass.localize("ui.common.cancel")} + + + ${entry + ? this.hass.localize("ui.common.save") + : this.hass.localize("ui.common.create")} + +
`; } @@ -325,6 +362,31 @@ class DialogAreaDetail extends LitElement { } } + private async _deleteArea() { + if (!this._params?.entry) { + return; + } + + const confirmed = await showConfirmationDialog(this, { + title: this.hass.localize( + "ui.panel.config.areas.delete.confirmation_title", + { name: this._params.entry.name } + ), + text: this.hass.localize( + "ui.panel.config.areas.delete.confirmation_text" + ), + dismissText: this.hass.localize("ui.common.cancel"), + confirmText: this.hass.localize("ui.common.delete"), + destructive: true, + }); + if (!confirmed) { + return; + } + + await deleteAreaRegistryEntry(this.hass!, this._params!.entry!.area_id); + this.closeDialog(); + } + static get styles(): CSSResultGroup { return [ haStyleDialog, @@ -332,15 +394,28 @@ class DialogAreaDetail extends LitElement { ha-textfield { display: block; } + ha-expansion-panel { + --expansion-panel-content-padding: 0; + } ha-aliases-editor, ha-entity-picker, ha-floor-picker, ha-icon-picker, ha-labels-picker, - ha-picture-upload { + ha-picture-upload, + ha-expansion-panel { display: block; margin-bottom: 16px; } + ha-dialog { + --mdc-dialog-min-width: min(600px, 100vw); + } + .content { + padding: 12px; + } + .description { + margin: 0 0 16px 0; + } `, ]; } diff --git a/src/translations/en.json b/src/translations/en.json index 1b8b05b1e0..45e3653060 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2211,7 +2211,8 @@ "temperature_entity": "Temperature sensor", "temperature_entity_description": "Sensor that represents the area temperature.", "humidity_entity": "Humidity sensor", - "humidity_entity_description": "Sensor that represents the area humidity." + "humidity_entity_description": "Sensor that represents the area humidity.", + "related_entities_section": "Related sensors" }, "delete": { "confirmation_title": "Delete {name}?",