Fix yaml editor lovelace (#18664)

This commit is contained in:
Paul Bottein 2023-11-16 18:55:09 +01:00 committed by GitHub
parent ba8849ed4d
commit e1dc73e992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 21 deletions

View File

@ -343,26 +343,25 @@ export class LovelacePanel extends LitElement {
this._panelState = "yaml-editor"; this._panelState = "yaml-editor";
}, },
setEditMode: (editMode: boolean) => { setEditMode: (editMode: boolean) => {
// If we use a strategy for dashboard, we cannot show the edit UI // If the dashboard is generated (default dashboard)
// So go straight to the YAML editor // Propose to take control of it
if ( if (this.lovelace!.mode === "generated" && editMode) {
this.lovelace!.rawConfig &&
this.lovelace!.rawConfig !== this.lovelace!.config
) {
this.lovelace!.enableFullEditMode();
return;
}
if (!editMode || this.lovelace!.mode !== "generated") {
this._updateLovelace({ editMode });
return;
}
showSaveDialog(this, { showSaveDialog(this, {
lovelace: this.lovelace!, lovelace: this.lovelace!,
mode: this.panel!.config.mode, mode: this.panel!.config.mode,
narrow: this.narrow!, narrow: this.narrow!,
}); });
return;
}
// 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;
}
this._updateLovelace({ editMode });
}, },
saveConfig: async (newConfig: LovelaceRawConfig): Promise<void> => { saveConfig: async (newConfig: LovelaceRawConfig): Promise<void> => {
const { const {

View File

@ -558,19 +558,26 @@ class HUIRoot extends LitElement {
view.visible.some((show) => show.user === this.hass!.user?.id)) 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) { protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps); super.firstUpdated(changedProps);
// Check for requested edit mode // Check for requested edit mode
const searchParams = extractSearchParamsObject(); const searchParams = extractSearchParamsObject();
if (searchParams.edit === "1" && this.hass!.user?.is_admin) { if (searchParams.edit === "1") {
this._clearParam("edit");
if (this.hass!.user?.is_admin) {
this.lovelace!.setEditMode(true); this.lovelace!.setEditMode(true);
}
} else if (searchParams.conversation === "1") { } else if (searchParams.conversation === "1") {
this._clearParam("conversation");
this._showVoiceCommandDialog(); this._showVoiceCommandDialog();
window.history.replaceState(
null,
"",
constructUrlCurrentPath(removeSearchParam("conversation"))
);
} }
window.addEventListener("scroll", this._handleWindowScroll, { window.addEventListener("scroll", this._handleWindowScroll, {
passive: true, passive: true,