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

Migrate hui-dialog-select-dashboard to ha-wa-dialog (#28456)

This commit is contained in:
Aidan Timson
2025-12-16 12:47:50 +00:00
committed by GitHub
parent 3425837de3
commit b125cd5f3e
2 changed files with 70 additions and 56 deletions

View File

@@ -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,23 +68,13 @@ export class HuiDialogSelectDashboard extends LitElement {
this.hass.localize("ui.panel.lovelace.editor.select_dashboard.header");
return html`
<ha-md-dialog
open
<ha-wa-dialog
.hass=${this.hass}
.open=${this._open}
header-title=${dialogTitle}
.preventScrimClose=${this._saving}
@closed=${this._dialogClosed}
.ariaLabel=${dialogTitle}
.disableCancelAction=${this._saving}
>
<ha-dialog-header slot="headline">
<ha-icon-button
slot="navigationIcon"
.label=${this.hass.localize("ui.common.close")}
.path=${mdiClose}
@click=${this.closeDialog}
.disabled=${this._saving}
></ha-icon-button>
<span slot="title" .title=${dialogTitle}>${dialogTitle}</span>
</ha-dialog-header>
<div slot="content">
${this._dashboards && !this._saving
? html`
<ha-md-select
@@ -109,9 +101,9 @@ export class HuiDialogSelectDashboard extends LitElement {
: html`<div class="loading">
<ha-spinner size="medium"></ha-spinner>
</div>`}
</div>
<div slot="actions">
<ha-dialog-footer slot="footer">
<ha-button
slot="secondaryAction"
appearance="plain"
@click=${this.closeDialog}
.disabled=${this._saving}
@@ -119,6 +111,7 @@ export class HuiDialogSelectDashboard extends LitElement {
${this.hass!.localize("ui.common.cancel")}
</ha-button>
<ha-button
slot="primaryAction"
@click=${this._selectDashboard}
.disabled=${!this._config ||
this._fromUrlPath === this._toUrlPath ||
@@ -126,12 +119,31 @@ export class HuiDialogSelectDashboard extends LitElement {
>
${this._params.actionLabel || this.hass!.localize("ui.common.move")}
</ha-button>
</div>
</ha-md-dialog>
</ha-dialog-footer>
</ha-wa-dialog>
`;
}
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);

View File

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