From e1dc73e992a620d580cd321f40ffa9ca44b8cc2a Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 16 Nov 2023 18:55:09 +0100 Subject: [PATCH] Fix yaml editor lovelace (#18664) --- src/panels/lovelace/ha-panel-lovelace.ts | 27 ++++++++++++------------ src/panels/lovelace/hui-root.ts | 21 ++++++++++++------ 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/panels/lovelace/ha-panel-lovelace.ts b/src/panels/lovelace/ha-panel-lovelace.ts index 32032d1d58f9..a16d3e7eb894 100644 --- a/src/panels/lovelace/ha-panel-lovelace.ts +++ b/src/panels/lovelace/ha-panel-lovelace.ts @@ -343,26 +343,25 @@ export class LovelacePanel extends LitElement { this._panelState = "yaml-editor"; }, setEditMode: (editMode: boolean) => { - // If we use a strategy for dashboard, we cannot show the edit UI - // So go straight to the YAML editor - if ( - this.lovelace!.rawConfig && - this.lovelace!.rawConfig !== this.lovelace!.config - ) { - this.lovelace!.enableFullEditMode(); + // If the dashboard is generated (default dashboard) + // Propose to take control of it + if (this.lovelace!.mode === "generated" && editMode) { + showSaveDialog(this, { + lovelace: this.lovelace!, + mode: this.panel!.config.mode, + narrow: this.narrow!, + }); return; } - if (!editMode || this.lovelace!.mode !== "generated") { - this._updateLovelace({ editMode }); + // If we use a strategy for dashboard, we cannot show the edit UI + // So go straight to the YAML editor + if (isStrategyDashboard(this.lovelace!.rawConfig) && editMode) { + this.lovelace!.enableFullEditMode(); return; } - showSaveDialog(this, { - lovelace: this.lovelace!, - mode: this.panel!.config.mode, - narrow: this.narrow!, - }); + this._updateLovelace({ editMode }); }, saveConfig: async (newConfig: LovelaceRawConfig): Promise => { const { diff --git a/src/panels/lovelace/hui-root.ts b/src/panels/lovelace/hui-root.ts index f2dc50d40067..53ba6073a00f 100644 --- a/src/panels/lovelace/hui-root.ts +++ b/src/panels/lovelace/hui-root.ts @@ -558,19 +558,26 @@ class HUIRoot extends LitElement { view.visible.some((show) => show.user === this.hass!.user?.id)) ); + private _clearParam(param: string) { + window.history.replaceState( + null, + "", + constructUrlCurrentPath(removeSearchParam(param)) + ); + } + protected firstUpdated(changedProps: PropertyValues) { super.firstUpdated(changedProps); // Check for requested edit mode const searchParams = extractSearchParamsObject(); - if (searchParams.edit === "1" && this.hass!.user?.is_admin) { - this.lovelace!.setEditMode(true); + if (searchParams.edit === "1") { + this._clearParam("edit"); + if (this.hass!.user?.is_admin) { + this.lovelace!.setEditMode(true); + } } else if (searchParams.conversation === "1") { + this._clearParam("conversation"); this._showVoiceCommandDialog(); - window.history.replaceState( - null, - "", - constructUrlCurrentPath(removeSearchParam("conversation")) - ); } window.addEventListener("scroll", this._handleWindowScroll, { passive: true,