Skip to content

Commit

Permalink
dont allow UI editor when templates are used in repeat (#19188)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Dec 29, 2023
1 parent 442cce1 commit cb568d0
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { css, CSSResultGroup, html, LitElement } from "lit";
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../../common/dom/fire_event";
Expand All @@ -12,6 +12,7 @@ import type { ActionElement } from "../ha-automation-action-row";
import type { LocalizeFunc } from "../../../../../common/translations/localize";
import "../../../../../components/ha-form/ha-form";
import type { SchemaUnion } from "../../../../../components/ha-form/types";
import { hasTemplate } from "../../../../../common/string/has-template";

const OPTIONS = ["count", "while", "until", "for_each"] as const;

Expand All @@ -31,6 +32,20 @@ export class HaRepeatAction extends LitElement implements ActionElement {
return { repeat: { count: 2, sequence: [] } };
}

public willUpdate(changedProperties: PropertyValues) {
if (!changedProperties.has("action")) {
return;
}
// Check for templates in action. If found, revert to YAML mode.
if (this.action && hasTemplate(this.action)) {
fireEvent(
this,
"ui-mode-not-available",
Error(this.hass.localize("ui.errors.config.no_template_editor_support"))
);
}
}

private _schema = memoizeOne(
(localize: LocalizeFunc, type: string, reOrderMode: boolean) =>
[
Expand Down Expand Up @@ -92,7 +107,7 @@ export class HaRepeatAction extends LitElement implements ActionElement {
this.reOrderMode
);
const data = { ...action, type };
return html` <ha-form
return html`<ha-form
.hass=${this.hass}
.data=${data}
.schema=${schema}
Expand Down

0 comments on commit cb568d0

Please sign in to comment.