Expose history replace in action editor (#17740)

* Expose existing navigation history replace to the UI

* Remove navigation_replace from GUI editor

* Restore default value
This commit is contained in:
breakthestatic 2023-10-09 03:02:30 -07:00 committed by GitHub
parent a60a721ea5
commit d7760c4b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 18 deletions

View File

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

View File

@ -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(

View File

@ -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 {
</div>
${this.config?.action === "navigate"
? html`
<ha-navigation-picker
<ha-form
.hass=${this.hass}
.label=${this.hass!.localize(
"ui.panel.lovelace.editor.action-editor.navigation_path"
)}
.value=${this._navigation_path}
@value-changed=${this._navigateValueChanged}
></ha-navigation-picker>
.schema=${NAVIGATE_SCHEMA}
.data=${this.config}
.computeLabel=${this._computeFormLabel}
@value-changed=${this._formValueChanged}
>
</ha-form>
`
: 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 {

View File

@ -48,6 +48,7 @@ const actionConfigStructService = object({
const actionConfigStructNavigate = object({
action: literal("navigate"),
navigation_path: string(),
navigation_replace: optional(boolean()),
confirmation: optional(actionConfigStructConfirmation),
});