1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 02:38:53 +00:00

Migrate floor dialog to webawesome (#28606)

This commit is contained in:
Aidan Timson
2025-12-19 09:21:55 +00:00
committed by GitHub
parent a7a00228a2
commit c0a49b3d0b

View File

@@ -11,12 +11,13 @@ import "../../../components/ha-alert";
import "../../../components/ha-aliases-editor"; import "../../../components/ha-aliases-editor";
import "../../../components/ha-area-picker"; import "../../../components/ha-area-picker";
import "../../../components/ha-button"; import "../../../components/ha-button";
import { createCloseHeading } from "../../../components/ha-dialog"; import "../../../components/ha-dialog-footer";
import "../../../components/ha-floor-icon";
import "../../../components/ha-icon-picker"; import "../../../components/ha-icon-picker";
import "../../../components/ha-picture-upload";
import "../../../components/ha-settings-row"; import "../../../components/ha-settings-row";
import "../../../components/ha-svg-icon"; import "../../../components/ha-svg-icon";
import "../../../components/ha-textfield"; import "../../../components/ha-textfield";
import "../../../components/ha-wa-dialog";
import { updateAreaRegistryEntry } from "../../../data/area_registry"; import { updateAreaRegistryEntry } from "../../../data/area_registry";
import type { import type {
FloorRegistryEntry, FloorRegistryEntry,
@@ -49,6 +50,8 @@ class DialogFloorDetail extends LitElement {
@state() private _removedAreas = new Set<string>(); @state() private _removedAreas = new Set<string>();
@state() private _open = false;
public showDialog(params: FloorRegistryDetailDialogParams): void { public showDialog(params: FloorRegistryDetailDialogParams): void {
this._params = params; this._params = params;
this._error = undefined; this._error = undefined;
@@ -60,9 +63,14 @@ class DialogFloorDetail extends LitElement {
this._level = this._params.entry?.level ?? null; this._level = this._params.entry?.level ?? null;
this._addedAreas.clear(); this._addedAreas.clear();
this._removedAreas.clear(); this._removedAreas.clear();
this._open = true;
} }
public closeDialog(): void { public closeDialog(): void {
this._open = false;
}
private _dialogClosed(): void {
this._error = ""; this._error = "";
this._params = undefined; this._params = undefined;
this._addedAreas.clear(); this._addedAreas.clear();
@@ -96,18 +104,15 @@ class DialogFloorDetail extends LitElement {
return nothing; return nothing;
} }
const entry = this._params.entry; const entry = this._params.entry;
const nameInvalid = !this._isNameValid();
return html` return html`
<ha-dialog <ha-wa-dialog
open .hass=${this.hass}
@closed=${this.closeDialog} .open=${this._open}
.heading=${createCloseHeading( header-title=${entry
this.hass,
entry
? this.hass.localize("ui.panel.config.floors.editor.update_floor") ? this.hass.localize("ui.panel.config.floors.editor.update_floor")
: this.hass.localize("ui.panel.config.floors.editor.create_floor") : this.hass.localize("ui.panel.config.floors.editor.create_floor")}
)} @closed=${this._dialogClosed}
> >
<div> <div>
${this._error ${this._error
@@ -128,6 +133,7 @@ class DialogFloorDetail extends LitElement {
: nothing} : nothing}
<ha-textfield <ha-textfield
autofocus
.value=${this._name} .value=${this._name}
@input=${this._nameChanged} @input=${this._nameChanged}
.label=${this.hass.localize("ui.panel.config.floors.editor.name")} .label=${this.hass.localize("ui.panel.config.floors.editor.name")}
@@ -135,7 +141,6 @@ class DialogFloorDetail extends LitElement {
"ui.panel.config.floors.editor.name_required" "ui.panel.config.floors.editor.name_required"
)} )}
required required
dialogInitialFocus
></ha-textfield> ></ha-textfield>
<ha-textfield <ha-textfield
@@ -230,6 +235,7 @@ class DialogFloorDetail extends LitElement {
></ha-aliases-editor> ></ha-aliases-editor>
</div> </div>
</div> </div>
<ha-dialog-footer slot="footer">
<ha-button <ha-button
appearance="plain" appearance="plain"
slot="secondaryAction" slot="secondaryAction"
@@ -240,13 +246,14 @@ class DialogFloorDetail extends LitElement {
<ha-button <ha-button
slot="primaryAction" slot="primaryAction"
@click=${this._updateEntry} @click=${this._updateEntry}
.disabled=${nameInvalid || !!this._submitting} .disabled=${!!this._submitting}
> >
${entry ${entry
? this.hass.localize("ui.common.save") ? this.hass.localize("ui.common.save")
: this.hass.localize("ui.common.create")} : this.hass.localize("ui.common.create")}
</ha-button> </ha-button>
</ha-dialog> </ha-dialog-footer>
</ha-wa-dialog>
`; `;
} }
@@ -285,10 +292,6 @@ class DialogFloorDetail extends LitElement {
this._addedAreas = new Set(this._addedAreas); this._addedAreas = new Set(this._addedAreas);
} }
private _isNameValid() {
return this._name.trim() !== "";
}
private _nameChanged(ev) { private _nameChanged(ev) {
this._error = undefined; this._error = undefined;
this._name = ev.target.value; this._name = ev.target.value;
@@ -305,7 +308,16 @@ class DialogFloorDetail extends LitElement {
} }
private async _updateEntry() { private async _updateEntry() {
if (this._name.trim() === "") {
this._error = this.hass.localize(
"ui.panel.config.floors.editor.name_required"
);
return;
}
this._error = undefined;
this._submitting = true; this._submitting = true;
const create = !this._params!.entry; const create = !this._params!.entry;
try { try {
const values: FloorRegistryEntryMutableParams = { const values: FloorRegistryEntryMutableParams = {
@@ -344,13 +356,13 @@ class DialogFloorDetail extends LitElement {
css` css`
ha-textfield { ha-textfield {
display: block; display: block;
margin-bottom: 16px; margin-bottom: var(--ha-space-4);
} }
ha-floor-icon { ha-floor-icon {
color: var(--secondary-text-color); color: var(--secondary-text-color);
} }
ha-chip-set { ha-chip-set {
margin-bottom: 8px; margin-bottom: var(--ha-space-2);
} }
`, `,
]; ];