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";
},
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();
return;
}
if (!editMode || this.lovelace!.mode !== "generated") {
this._updateLovelace({ editMode });
return;
}
// 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 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> => {
const {

View File

@ -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) {
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,