@@ -4,18 +4,20 @@ import { customElement, property, state } from "lit/decorators";
44import memoizeOne from "memoize-one" ;
55import { fireEvent } from "../../../../common/dom/fire_event" ;
66import { slugify } from "../../../../common/string/slugify" ;
7+ import "../../../../components/ha-button" ;
78import { createCloseHeading } from "../../../../components/ha-dialog" ;
89import "../../../../components/ha-form/ha-form" ;
9- import "../../../../components/ha-button" ;
1010import type { SchemaUnion } from "../../../../components/ha-form/types" ;
11+ import { saveFrontendSystemData } from "../../../../data/frontend" ;
1112import type {
1213 LovelaceDashboard ,
1314 LovelaceDashboardCreateParams ,
1415 LovelaceDashboardMutableParams ,
1516} from "../../../../data/lovelace/dashboard" ;
16- import { DEFAULT_PANEL , setDefaultPanel } from "../../../../data/panel" ;
17+ import { DEFAULT_PANEL } from "../../../../data/panel" ;
1718import { haStyleDialog } from "../../../../resources/styles" ;
1819import type { HomeAssistant } from "../../../../types" ;
20+ import { showConfirmationDialog } from "../../../lovelace/custom-card-helpers" ;
1921import type { LovelaceDashboardDetailsDialogParams } from "./show-dialog-lovelace-dashboard-detail" ;
2022
2123@customElement ( "dialog-lovelace-dashboard-detail" )
@@ -59,7 +61,8 @@ export class DialogLovelaceDashboardDetail extends LitElement {
5961 if ( ! this . _params || ! this . _data ) {
6062 return nothing ;
6163 }
62- const defaultPanelUrlPath = this . hass . defaultPanel ;
64+ const defaultPanelUrlPath =
65+ this . hass . systemData ?. defaultPanel || DEFAULT_PANEL ;
6366 const titleInvalid = ! this . _data . title || ! this . _data . title . trim ( ) ;
6467
6568 return html `
@@ -251,15 +254,38 @@ export class DialogLovelaceDashboardDetail extends LitElement {
251254 } ;
252255 }
253256
254- private _toggleDefault ( ) {
257+ private async _toggleDefault ( ) {
255258 const urlPath = this . _params ?. urlPath ;
256259 if ( ! urlPath ) {
257260 return ;
258261 }
259- setDefaultPanel (
260- this ,
261- urlPath === this . hass . defaultPanel ? DEFAULT_PANEL : urlPath
262- ) ;
262+
263+ const defaultPanel = this . hass . systemData ?. defaultPanel || DEFAULT_PANEL ;
264+ // Add warning dialog to saying that this will change the default dashboard for all users
265+ const confirm = await showConfirmationDialog ( this , {
266+ title : this . hass . localize (
267+ urlPath === defaultPanel
268+ ? "ui.panel.config.lovelace.dashboards.detail.remove_default_confirm_title"
269+ : "ui.panel.config.lovelace.dashboards.detail.set_default_confirm_title"
270+ ) ,
271+ text : this . hass . localize (
272+ urlPath === defaultPanel
273+ ? "ui.panel.config.lovelace.dashboards.detail.remove_default_confirm_text"
274+ : "ui.panel.config.lovelace.dashboards.detail.set_default_confirm_text"
275+ ) ,
276+ confirmText : this . hass . localize ( "ui.common.ok" ) ,
277+ dismissText : this . hass . localize ( "ui.common.cancel" ) ,
278+ destructive : false ,
279+ } ) ;
280+
281+ if ( ! confirm ) {
282+ return ;
283+ }
284+
285+ saveFrontendSystemData ( this . hass . connection , "core" , {
286+ ...this . hass . systemData ,
287+ defaultPanel : urlPath === defaultPanel ? undefined : urlPath ,
288+ } ) ;
263289 }
264290
265291 private async _updateDashboard ( ) {
0 commit comments