From d7760c4b7a9e62bea2e0ba1782e161f515842a83 Mon Sep 17 00:00:00 2001 From: breakthestatic Date: Mon, 9 Oct 2023 03:02:30 -0700 Subject: [PATCH] Expose history replace in action editor (#17740) * Expose existing navigation history replace to the UI * Remove navigation_replace from GUI editor * Restore default value --- src/data/lovelace.ts | 1 + src/panels/lovelace/common/handle-action.ts | 4 ++- .../lovelace/components/hui-action-editor.ts | 33 +++++++++---------- .../lovelace/editor/structs/action-struct.ts | 1 + 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/data/lovelace.ts b/src/data/lovelace.ts index 76a2e401e3..b8d13b2004 100644 --- a/src/data/lovelace.ts +++ b/src/data/lovelace.ts @@ -140,6 +140,7 @@ export interface CallServiceActionConfig extends BaseActionConfig { export interface NavigateActionConfig extends BaseActionConfig { action: "navigate"; navigation_path: string; + navigation_replace?: boolean; } export interface UrlActionConfig extends BaseActionConfig { diff --git a/src/panels/lovelace/common/handle-action.ts b/src/panels/lovelace/common/handle-action.ts index bd849bd428..05f6b2b270 100644 --- a/src/panels/lovelace/common/handle-action.ts +++ b/src/panels/lovelace/common/handle-action.ts @@ -109,7 +109,9 @@ export const handleAction = async ( } case "navigate": if (actionConfig.navigation_path) { - navigate(actionConfig.navigation_path); + navigate(actionConfig.navigation_path, { + replace: actionConfig.navigation_replace, + }); } else { showToast(node, { message: hass.localize( diff --git a/src/panels/lovelace/components/hui-action-editor.ts b/src/panels/lovelace/components/hui-action-editor.ts index 6ae48d59f1..972d79b173 100644 --- a/src/panels/lovelace/components/hui-action-editor.ts +++ b/src/panels/lovelace/components/hui-action-editor.ts @@ -30,6 +30,15 @@ const DEFAULT_ACTIONS: UiAction[] = [ "none", ]; +const NAVIGATE_SCHEMA = [ + { + name: "navigation_path", + selector: { + navigation: {}, + }, + }, +] as const satisfies readonly HaFormSchema[]; + const ASSIST_SCHEMA = [ { type: "grid", @@ -131,14 +140,14 @@ export class HuiActionEditor extends LitElement { ${this.config?.action === "navigate" ? html` - + .schema=${NAVIGATE_SCHEMA} + .data=${this.config} + .computeLabel=${this._computeFormLabel} + @value-changed=${this._formValueChanged} + > + ` : nothing} ${this.config?.action === "url" @@ -265,16 +274,6 @@ export class HuiActionEditor extends LitElement { fireEvent(this, "value-changed", { value }); } - private _navigateValueChanged(ev: CustomEvent) { - ev.stopPropagation(); - const value = { - ...this.config!, - navigation_path: ev.detail.value, - }; - - fireEvent(this, "value-changed", { value }); - } - static get styles(): CSSResultGroup { return css` .dropdown { diff --git a/src/panels/lovelace/editor/structs/action-struct.ts b/src/panels/lovelace/editor/structs/action-struct.ts index 512e45aa84..aa94eca774 100644 --- a/src/panels/lovelace/editor/structs/action-struct.ts +++ b/src/panels/lovelace/editor/structs/action-struct.ts @@ -48,6 +48,7 @@ const actionConfigStructService = object({ const actionConfigStructNavigate = object({ action: literal("navigate"), navigation_path: string(), + navigation_replace: optional(boolean()), confirmation: optional(actionConfigStructConfirmation), });