diff --git a/src/panels/config/areas/ha-config-areas-dashboard.ts b/src/panels/config/areas/ha-config-areas-dashboard.ts index 4468e294f1..02e96bc9c2 100644 --- a/src/panels/config/areas/ha-config-areas-dashboard.ts +++ b/src/panels/config/areas/ha-config-areas-dashboard.ts @@ -1,4 +1,10 @@ -import { mdiHelpCircle, mdiPencil, mdiPlus } from "@mdi/js"; +import { + mdiDelete, + mdiDotsVertical, + mdiHelpCircle, + mdiPencil, + mdiPlus, +} from "@mdi/js"; import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { CSSResultGroup, @@ -11,6 +17,7 @@ import { import { customElement, property, state } from "lit/decorators"; import { styleMap } from "lit/directives/style-map"; import memoizeOne from "memoize-one"; +import { ActionDetail } from "@material/mwc-list"; import { formatListWithAnds } from "../../../common/string/format-list"; import "../../../components/ha-fab"; import "../../../components/ha-icon-button"; @@ -22,11 +29,15 @@ import { import { FloorRegistryEntry, createFloorRegistryEntry, + deleteFloorRegistryEntry, getFloorAreaLookup, subscribeFloorRegistry, updateFloorRegistryEntry, } from "../../../data/floor_registry"; -import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box"; +import { + showAlertDialog, + showConfirmationDialog, +} from "../../../dialogs/generic/show-dialog-box"; import "../../../layouts/hass-tabs-subpage"; import { HomeAssistant, Route } from "../../../types"; import "../ha-config-section"; @@ -148,11 +159,34 @@ export class HaConfigAreasDashboard extends SubscribeMixin(LitElement) { : nothing} ${floor.name} - + @action=${this._handleFloorAction} + > + + ${this.hass.localize( + "ui.panel.config.areas.picker.floor.edit_floor" + )} + ${this.hass.localize( + "ui.panel.config.areas.picker.floor.delete_floor" + )} +
${floor.areas.map((area) => this._renderArea(area))} @@ -248,15 +282,43 @@ export class HaConfigAreasDashboard extends SubscribeMixin(LitElement) { loadAreaRegistryDetailDialog(); } + private _handleFloorAction(ev: CustomEvent) { + const floor = (ev.currentTarget as any).floor; + switch (ev.detail.index) { + case 0: + this._editFloor(floor); + break; + case 1: + this._deleteFloor(floor); + break; + } + } + private _createFloor() { this._openFloorDialog(); } - private _editFloor(ev) { - const floor = ev.currentTarget.floor; + private _editFloor(floor) { this._openFloorDialog(floor); } + private async _deleteFloor(floor) { + const confirm = await showConfirmationDialog(this, { + title: this.hass.localize( + "ui.panel.config.areas.picker.floor.confirm_delete" + ), + text: this.hass.localize( + "ui.panel.config.areas.picker.floor.confirm_delete_text" + ), + confirmText: this.hass.localize("ui.common.delete"), + destructive: true, + }); + if (!confirm) { + return; + } + await deleteFloorRegistryEntry(this.hass, floor.floor_id); + } + private _createArea() { this._openAreaDialog(); } @@ -365,6 +427,9 @@ export class HaConfigAreasDashboard extends SubscribeMixin(LitElement) { --primary-color: var(--secondary-text-color); margin-inline-end: 8px; } + .warning { + color: var(--error-color); + } `; } } diff --git a/src/translations/en.json b/src/translations/en.json index 30474d0c1b..208a42a2ce 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2008,7 +2008,13 @@ "no_areas": "Looks like you have no areas yet!", "unassigned_areas": "Unassigned areas", "create_area": "Create Area", - "create_floor": "Create floor" + "create_floor": "Create floor", + "floor": { + "edit_floor": "Edit floor", + "delete_floor": "Delete floor", + "confirm_delete": "Delete floor?", + "confirm_delete_text": "Removing the floor will unassign all areas from it." + } }, "editor": { "create_area": "Create area",