Skip to content

Commit

Permalink
Fix yaml editor lovelace (#18664)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Nov 16, 2023
1 parent ba8849e commit e1dc73e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
27 changes: 13 additions & 14 deletions src/panels/lovelace/ha-panel-lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
const {
Expand Down
21 changes: 14 additions & 7 deletions src/panels/lovelace/hui-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e1dc73e

Please sign in to comment.