From b125cd5f3ed32f87b316fc4f8c9d75fb1be76b19 Mon Sep 17 00:00:00 2001 From: Aidan Timson Date: Tue, 16 Dec 2025 12:47:50 +0000 Subject: [PATCH] Migrate hui-dialog-select-dashboard to ha-wa-dialog (#28456) --- .../hui-dialog-select-dashboard.ts | 124 ++++++++++-------- src/translations/en.json | 2 + 2 files changed, 70 insertions(+), 56 deletions(-) diff --git a/src/panels/lovelace/editor/select-dashboard/hui-dialog-select-dashboard.ts b/src/panels/lovelace/editor/select-dashboard/hui-dialog-select-dashboard.ts index 7ba6ff95b3..d08aa45dc3 100644 --- a/src/panels/lovelace/editor/select-dashboard/hui-dialog-select-dashboard.ts +++ b/src/panels/lovelace/editor/select-dashboard/hui-dialog-select-dashboard.ts @@ -1,13 +1,10 @@ -import { mdiClose } from "@mdi/js"; import type { CSSResultGroup } from "lit"; import { css, html, LitElement, nothing } from "lit"; -import { customElement, query, state } from "lit/decorators"; +import { customElement, state } from "lit/decorators"; import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-button"; -import "../../../../components/ha-dialog-header"; -import "../../../../components/ha-icon-button"; -import "../../../../components/ha-md-dialog"; -import type { HaMdDialog } from "../../../../components/ha-md-dialog"; +import "../../../../components/ha-dialog-footer"; +import "../../../../components/ha-wa-dialog"; import "../../../../components/ha-md-select"; import "../../../../components/ha-md-select-option"; import "../../../../components/ha-spinner"; @@ -18,6 +15,7 @@ import { getDefaultPanelUrlPath } from "../../../../data/panel"; import { haStyleDialog } from "../../../../resources/styles"; import type { HomeAssistant } from "../../../../types"; import type { SelectDashboardDialogParams } from "./show-select-dashboard-dialog"; +import { showAlertDialog } from "../../../../dialogs/generic/show-dialog-box"; @customElement("hui-dialog-select-dashboard") export class HuiDialogSelectDashboard extends LitElement { @@ -35,25 +33,29 @@ export class HuiDialogSelectDashboard extends LitElement { @state() private _saving = false; - @query("ha-md-dialog") private _dialog?: HaMdDialog; + @state() private _open = false; public showDialog(params: SelectDashboardDialogParams): void { this._config = params.lovelaceConfig; this._fromUrlPath = params.urlPath; this._params = params; + this._open = true; this._getDashboards(); } public closeDialog(): void { + if (this._open) { + fireEvent(this, "dialog-closed", { dialog: this.localName }); + } this._saving = false; this._dashboards = undefined; this._toUrlPath = undefined; - this._dialog?.close(); + this._open = false; + this._params = undefined; } private _dialogClosed(): void { - this._params = undefined; - fireEvent(this, "dialog-closed", { dialog: this.localName }); + this.closeDialog(); } protected render() { @@ -66,52 +68,42 @@ export class HuiDialogSelectDashboard extends LitElement { this.hass.localize("ui.panel.lovelace.editor.select_dashboard.header"); return html` - - - - ${dialogTitle} - -
- ${this._dashboards && !this._saving - ? html` - - ${this._dashboards.map( - (dashboard) => html` - ${dashboard.title} - ` - )} - - ` - : html`
- -
`} -
-
+ ${this._dashboards && !this._saving + ? html` + + ${this._dashboards.map( + (dashboard) => html` + ${dashboard.title} + ` + )} + + ` + : html`
+ +
`} + ${this._params.actionLabel || this.hass!.localize("ui.common.move")} -
-
+ + `; } private async _getDashboards() { + let dashboards: LovelaceDashboard[] | undefined = this._params!.dashboards; + if (!dashboards) { + try { + dashboards = await fetchDashboards(this.hass); + } catch (error) { + // eslint-disable-next-line no-console + console.error("Error fetching dashboards:", error); + + showAlertDialog(this, { + title: this.hass.localize( + "ui.panel.lovelace.editor.select_dashboard.error_title" + ), + text: this.hass.localize( + "ui.panel.lovelace.editor.select_dashboard.error_text" + ), + }); + } + } + this._dashboards = [ { id: "lovelace", @@ -141,7 +153,7 @@ export class HuiDialogSelectDashboard extends LitElement { title: this.hass.localize("ui.common.default"), mode: this.hass.panels.lovelace?.config?.mode, }, - ...(this._params!.dashboards || (await fetchDashboards(this.hass))), + ...(dashboards ?? []), ]; const defaultPanel = getDefaultPanelUrlPath(this.hass); diff --git a/src/translations/en.json b/src/translations/en.json index 05a1383dbc..b0b039e0a5 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -7656,6 +7656,8 @@ "strategy_type": "strategy" }, "select_dashboard": { + "error_title": "Error fetching dashboards", + "error_text": "Failed to fetch dashboards, please try again.", "header": "Choose a dashboard", "cannot_move_to_strategy": "The view cannot be moved because the selected dashboard is auto-generated.", "get_config_failed": "Failed to load selected dashboard config.",