Allow delete floor (#20208)

* Allow delete floor

* Update src/translations/en.json

Co-authored-by: Paul Bottein <paul.bottein@gmail.com>

---------

Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
This commit is contained in:
Bram Kragten 2024-03-27 17:35:29 +01:00 committed by GitHub
parent 7427e17926
commit 705c0e58fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 80 additions and 9 deletions

View File

@ -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}
</h2>
<ha-icon-button
.path=${mdiPencil}
@click=${this._editFloor}
<ha-button-menu
.floor=${floor}
></ha-icon-button>
@action=${this._handleFloorAction}
>
<ha-icon-button
slot="trigger"
.path=${mdiDotsVertical}
></ha-icon-button>
<ha-list-item graphic="icon"
><ha-svg-icon
.path=${mdiPencil}
slot="graphic"
></ha-svg-icon
>${this.hass.localize(
"ui.panel.config.areas.picker.floor.edit_floor"
)}</ha-list-item
>
<ha-list-item class="warning" graphic="icon"
><ha-svg-icon
class="warning"
.path=${mdiDelete}
slot="graphic"
></ha-svg-icon
>${this.hass.localize(
"ui.panel.config.areas.picker.floor.delete_floor"
)}</ha-list-item
>
</ha-button-menu>
</div>
<div class="areas">
${floor.areas.map((area) => this._renderArea(area))}
@ -248,15 +282,43 @@ export class HaConfigAreasDashboard extends SubscribeMixin(LitElement) {
loadAreaRegistryDetailDialog();
}
private _handleFloorAction(ev: CustomEvent<ActionDetail>) {
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);
}
`;
}
}

View File

@ -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",