@@ -39,6 +39,7 @@ import { fetchResources } from "../../../../data/lovelace/resource";
3939import type {
4040 LovelaceDashboard ,
4141 LovelaceDashboardCreateParams ,
42+ LovelaceDashboardSuggestions ,
4243} from "../../../../data/lovelace/dashboard" ;
4344import {
4445 createDashboard ,
@@ -61,7 +62,8 @@ import "../../../../layouts/hass-loading-screen";
6162import "../../../../layouts/hass-tabs-subpage-data-table" ;
6263import type { HomeAssistant , Route } from "../../../../types" ;
6364import { loadLovelaceResources } from "../../../lovelace/common/load-resources" ;
64- import { getLovelaceStrategy } from "../../../lovelace/strategies/get-strategy" ;
65+ import { loadDashboardStrategyWithCreateSuggestions } from "../../../lovelace/strategies/get-strategy" ;
66+ import type { NewDashboardSelection } from "../../dashboard/show-dialog-new-dashboard" ;
6567import { showNewDashboardDialog } from "../../dashboard/show-dialog-new-dashboard" ;
6668import { lovelaceTabs } from "../ha-config-lovelace" ;
6769import { showDashboardConfigureStrategyDialog } from "./show-dialog-lovelace-dashboard-configure-strategy" ;
@@ -565,40 +567,58 @@ export class HaConfigLovelaceDashboards extends LitElement {
565567
566568 private async _addDashboard ( ) {
567569 showNewDashboardDialog ( this , {
568- selectConfig : async ( config ) => {
570+ selectConfig : async ( { config } : NewDashboardSelection ) => {
571+ let fieldSuggestions : LovelaceDashboardSuggestions | undefined ;
572+
569573 if ( config && isStrategyDashboard ( config ) ) {
570- const strategyType = config . strategy . type ;
571- const strategyClass = await getLovelaceStrategy (
572- "dashboard" ,
573- strategyType
574- ) ;
574+ const { strategyClass, fieldSuggestions : suggested } =
575+ await loadDashboardStrategyWithCreateSuggestions (
576+ this . hass ,
577+ config . strategy . type
578+ ) ;
579+ fieldSuggestions = suggested ;
575580
576581 if ( strategyClass . configRequired ) {
577582 showDashboardConfigureStrategyDialog ( this , {
578583 config : config ,
579584 saveConfig : async ( updatedConfig ) => {
580- this . _openDetailDialog ( undefined , undefined , updatedConfig ) ;
585+ const { fieldSuggestions : afterConfigure } =
586+ await loadDashboardStrategyWithCreateSuggestions (
587+ this . hass ,
588+ updatedConfig . strategy . type
589+ ) ;
590+ this . _openDetailDialog (
591+ undefined ,
592+ undefined ,
593+ updatedConfig ,
594+ afterConfigure
595+ ) ;
581596 } ,
582597 } ) ;
583598 return ;
584599 }
585600 }
586601
587- this . _openDetailDialog ( undefined , undefined , config ) ;
602+ this . _openDetailDialog ( undefined , undefined , config , fieldSuggestions ) ;
588603 } ,
589604 } ) ;
590605 }
591606
592607 private async _openDetailDialog (
593608 dashboard ?: LovelaceDashboard ,
594609 urlPath ?: string ,
595- defaultConfig ?: LovelaceRawConfig
610+ defaultConfig ?: LovelaceRawConfig ,
611+ fieldSuggestions ?: LovelaceDashboardSuggestions
596612 ) : Promise < void > {
597613 const defaultPanel = this . hass . systemData ?. default_panel || DEFAULT_PANEL ;
598614 showDashboardDetailDialog ( this , {
599615 dashboard,
600616 urlPath,
601617 isDefault : dashboard ?. url_path === defaultPanel ,
618+ suggestions : fieldSuggestions ,
619+ takenUrlPaths : dashboard
620+ ? undefined
621+ : this . _collectTakenDashboardUrlPaths ( ) ,
602622 createDashboard : async ( values : LovelaceDashboardCreateParams ) => {
603623 const created = await createDashboard ( this . hass ! , values ) ;
604624 this . _dashboards = this . _dashboards ! . concat ( created ) . sort (
@@ -632,6 +652,18 @@ export class HaConfigLovelaceDashboards extends LitElement {
632652 } ) ;
633653 }
634654
655+ private _collectTakenDashboardUrlPaths ( ) : ReadonlySet < string > {
656+ const taken = new Set < string > ( ) ;
657+ for ( const d of this . _dashboards ?? [ ] ) {
658+ taken . add ( d . url_path ) ;
659+ }
660+ for ( const path of Object . keys ( this . hass . panels ) ) {
661+ taken . add ( path ) ;
662+ }
663+ taken . add ( "lovelace" ) ;
664+ return taken ;
665+ }
666+
635667 private async _deleteDashboard (
636668 dashboard : LovelaceDashboard
637669 ) : Promise < boolean > {
0 commit comments