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:
@@ -1,13 +1,10 @@
|
|||||||
import { mdiClose } from "@mdi/js";
|
|
||||||
import type { CSSResultGroup } from "lit";
|
import type { CSSResultGroup } from "lit";
|
||||||
import { css, html, LitElement, nothing } 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 { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import "../../../../components/ha-button";
|
import "../../../../components/ha-button";
|
||||||
import "../../../../components/ha-dialog-header";
|
import "../../../../components/ha-dialog-footer";
|
||||||
import "../../../../components/ha-icon-button";
|
import "../../../../components/ha-wa-dialog";
|
||||||
import "../../../../components/ha-md-dialog";
|
|
||||||
import type { HaMdDialog } from "../../../../components/ha-md-dialog";
|
|
||||||
import "../../../../components/ha-md-select";
|
import "../../../../components/ha-md-select";
|
||||||
import "../../../../components/ha-md-select-option";
|
import "../../../../components/ha-md-select-option";
|
||||||
import "../../../../components/ha-spinner";
|
import "../../../../components/ha-spinner";
|
||||||
@@ -18,6 +15,7 @@ import { getDefaultPanelUrlPath } from "../../../../data/panel";
|
|||||||
import { haStyleDialog } from "../../../../resources/styles";
|
import { haStyleDialog } from "../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import type { SelectDashboardDialogParams } from "./show-select-dashboard-dialog";
|
import type { SelectDashboardDialogParams } from "./show-select-dashboard-dialog";
|
||||||
|
import { showAlertDialog } from "../../../../dialogs/generic/show-dialog-box";
|
||||||
|
|
||||||
@customElement("hui-dialog-select-dashboard")
|
@customElement("hui-dialog-select-dashboard")
|
||||||
export class HuiDialogSelectDashboard extends LitElement {
|
export class HuiDialogSelectDashboard extends LitElement {
|
||||||
@@ -35,25 +33,29 @@ export class HuiDialogSelectDashboard extends LitElement {
|
|||||||
|
|
||||||
@state() private _saving = false;
|
@state() private _saving = false;
|
||||||
|
|
||||||
@query("ha-md-dialog") private _dialog?: HaMdDialog;
|
@state() private _open = false;
|
||||||
|
|
||||||
public showDialog(params: SelectDashboardDialogParams): void {
|
public showDialog(params: SelectDashboardDialogParams): void {
|
||||||
this._config = params.lovelaceConfig;
|
this._config = params.lovelaceConfig;
|
||||||
this._fromUrlPath = params.urlPath;
|
this._fromUrlPath = params.urlPath;
|
||||||
this._params = params;
|
this._params = params;
|
||||||
|
this._open = true;
|
||||||
this._getDashboards();
|
this._getDashboards();
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
|
if (this._open) {
|
||||||
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
|
}
|
||||||
this._saving = false;
|
this._saving = false;
|
||||||
this._dashboards = undefined;
|
this._dashboards = undefined;
|
||||||
this._toUrlPath = undefined;
|
this._toUrlPath = undefined;
|
||||||
this._dialog?.close();
|
this._open = false;
|
||||||
|
this._params = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _dialogClosed(): void {
|
private _dialogClosed(): void {
|
||||||
this._params = undefined;
|
this.closeDialog();
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
@@ -66,23 +68,13 @@ export class HuiDialogSelectDashboard extends LitElement {
|
|||||||
this.hass.localize("ui.panel.lovelace.editor.select_dashboard.header");
|
this.hass.localize("ui.panel.lovelace.editor.select_dashboard.header");
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-md-dialog
|
<ha-wa-dialog
|
||||||
open
|
.hass=${this.hass}
|
||||||
|
.open=${this._open}
|
||||||
|
header-title=${dialogTitle}
|
||||||
|
.preventScrimClose=${this._saving}
|
||||||
@closed=${this._dialogClosed}
|
@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
|
${this._dashboards && !this._saving
|
||||||
? html`
|
? html`
|
||||||
<ha-md-select
|
<ha-md-select
|
||||||
@@ -109,9 +101,9 @@ export class HuiDialogSelectDashboard extends LitElement {
|
|||||||
: html`<div class="loading">
|
: html`<div class="loading">
|
||||||
<ha-spinner size="medium"></ha-spinner>
|
<ha-spinner size="medium"></ha-spinner>
|
||||||
</div>`}
|
</div>`}
|
||||||
</div>
|
<ha-dialog-footer slot="footer">
|
||||||
<div slot="actions">
|
|
||||||
<ha-button
|
<ha-button
|
||||||
|
slot="secondaryAction"
|
||||||
appearance="plain"
|
appearance="plain"
|
||||||
@click=${this.closeDialog}
|
@click=${this.closeDialog}
|
||||||
.disabled=${this._saving}
|
.disabled=${this._saving}
|
||||||
@@ -119,6 +111,7 @@ export class HuiDialogSelectDashboard extends LitElement {
|
|||||||
${this.hass!.localize("ui.common.cancel")}
|
${this.hass!.localize("ui.common.cancel")}
|
||||||
</ha-button>
|
</ha-button>
|
||||||
<ha-button
|
<ha-button
|
||||||
|
slot="primaryAction"
|
||||||
@click=${this._selectDashboard}
|
@click=${this._selectDashboard}
|
||||||
.disabled=${!this._config ||
|
.disabled=${!this._config ||
|
||||||
this._fromUrlPath === this._toUrlPath ||
|
this._fromUrlPath === this._toUrlPath ||
|
||||||
@@ -126,12 +119,31 @@ export class HuiDialogSelectDashboard extends LitElement {
|
|||||||
>
|
>
|
||||||
${this._params.actionLabel || this.hass!.localize("ui.common.move")}
|
${this._params.actionLabel || this.hass!.localize("ui.common.move")}
|
||||||
</ha-button>
|
</ha-button>
|
||||||
</div>
|
</ha-dialog-footer>
|
||||||
</ha-md-dialog>
|
</ha-wa-dialog>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getDashboards() {
|
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 = [
|
this._dashboards = [
|
||||||
{
|
{
|
||||||
id: "lovelace",
|
id: "lovelace",
|
||||||
@@ -141,7 +153,7 @@ export class HuiDialogSelectDashboard extends LitElement {
|
|||||||
title: this.hass.localize("ui.common.default"),
|
title: this.hass.localize("ui.common.default"),
|
||||||
mode: this.hass.panels.lovelace?.config?.mode,
|
mode: this.hass.panels.lovelace?.config?.mode,
|
||||||
},
|
},
|
||||||
...(this._params!.dashboards || (await fetchDashboards(this.hass))),
|
...(dashboards ?? []),
|
||||||
];
|
];
|
||||||
|
|
||||||
const defaultPanel = getDefaultPanelUrlPath(this.hass);
|
const defaultPanel = getDefaultPanelUrlPath(this.hass);
|
||||||
|
|||||||
@@ -7656,6 +7656,8 @@
|
|||||||
"strategy_type": "strategy"
|
"strategy_type": "strategy"
|
||||||
},
|
},
|
||||||
"select_dashboard": {
|
"select_dashboard": {
|
||||||
|
"error_title": "Error fetching dashboards",
|
||||||
|
"error_text": "Failed to fetch dashboards, please try again.",
|
||||||
"header": "Choose a dashboard",
|
"header": "Choose a dashboard",
|
||||||
"cannot_move_to_strategy": "The view cannot be moved because the selected dashboard is auto-generated.",
|
"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.",
|
"get_config_failed": "Failed to load selected dashboard config.",
|
||||||
|
|||||||
Reference in New Issue
Block a user