mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 17:56:46 +00:00
Handle when choose is not an array (#9028)
This commit is contained in:
parent
0562242043
commit
2e51da32f0
@ -143,7 +143,7 @@ class HatScriptGraph extends LitElement {
|
|||||||
const trace = this.trace.trace[path] as ChooseActionTraceStep[] | undefined;
|
const trace = this.trace.trace[path] as ChooseActionTraceStep[] | undefined;
|
||||||
const trace_path = trace?.[0].result
|
const trace_path = trace?.[0].result
|
||||||
? trace[0].result.choice === "default"
|
? trace[0].result.choice === "default"
|
||||||
? [config.choose?.length || 0]
|
? [Array.isArray(config.choose) ? config.choose.length : 0]
|
||||||
: [trace[0].result.choice]
|
: [trace[0].result.choice]
|
||||||
: [];
|
: [];
|
||||||
return html`
|
return html`
|
||||||
@ -167,7 +167,8 @@ class HatScriptGraph extends LitElement {
|
|||||||
nofocus
|
nofocus
|
||||||
></hat-graph-node>
|
></hat-graph-node>
|
||||||
|
|
||||||
${config.choose?.map((branch, i) => {
|
${config.choose
|
||||||
|
? ensureArray(config.choose)?.map((branch, i) => {
|
||||||
const branch_path = `${path}/choose/${i}`;
|
const branch_path = `${path}/choose/${i}`;
|
||||||
const track_this =
|
const track_this =
|
||||||
trace !== undefined && trace[0].result?.choice === i;
|
trace !== undefined && trace[0].result?.choice === i;
|
||||||
@ -191,7 +192,8 @@ class HatScriptGraph extends LitElement {
|
|||||||
)}
|
)}
|
||||||
</hat-graph>
|
</hat-graph>
|
||||||
`;
|
`;
|
||||||
})}
|
})
|
||||||
|
: ""}
|
||||||
<hat-graph>
|
<hat-graph>
|
||||||
<hat-graph-spacer
|
<hat-graph-spacer
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
|
@ -112,7 +112,7 @@ export interface ChooseActionChoice {
|
|||||||
|
|
||||||
export interface ChooseAction {
|
export interface ChooseAction {
|
||||||
alias?: string;
|
alias?: string;
|
||||||
choose: ChooseActionChoice[] | null;
|
choose: ChooseActionChoice | ChooseActionChoice[] | null;
|
||||||
default?: Action | Action[];
|
default?: Action | Action[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import { html } from "lit-html";
|
import { html } from "lit-html";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
|
import { ensureArray } from "../../../../../common/ensure-array";
|
||||||
import { Condition } from "../../../../../data/automation";
|
import { Condition } from "../../../../../data/automation";
|
||||||
import { Action, ChooseAction } from "../../../../../data/script";
|
import { Action, ChooseAction } from "../../../../../data/script";
|
||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
@ -31,7 +32,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
const action = this.action;
|
const action = this.action;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${(action.choose || []).map(
|
${(action.choose ? ensureArray(action.choose) : []).map(
|
||||||
(option, idx) => html`<ha-card>
|
(option, idx) => html`<ha-card>
|
||||||
<mwc-icon-button
|
<mwc-icon-button
|
||||||
.idx=${idx}
|
.idx=${idx}
|
||||||
@ -101,7 +102,9 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const value = ev.detail.value as Condition[];
|
const value = ev.detail.value as Condition[];
|
||||||
const index = (ev.target as any).idx;
|
const index = (ev.target as any).idx;
|
||||||
const choose = this.action.choose ? [...this.action.choose] : [];
|
const choose = this.action.choose
|
||||||
|
? [...ensureArray(this.action.choose)]
|
||||||
|
: [];
|
||||||
choose[index].conditions = value;
|
choose[index].conditions = value;
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: { ...this.action, choose },
|
value: { ...this.action, choose },
|
||||||
@ -112,7 +115,9 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const value = ev.detail.value as Action[];
|
const value = ev.detail.value as Action[];
|
||||||
const index = (ev.target as any).idx;
|
const index = (ev.target as any).idx;
|
||||||
const choose = this.action.choose ? [...this.action.choose] : [];
|
const choose = this.action.choose
|
||||||
|
? [...ensureArray(this.action.choose)]
|
||||||
|
: [];
|
||||||
choose[index].sequence = value;
|
choose[index].sequence = value;
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: { ...this.action, choose },
|
value: { ...this.action, choose },
|
||||||
@ -120,7 +125,9 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _addOption() {
|
private _addOption() {
|
||||||
const choose = this.action.choose ? [...this.action.choose] : [];
|
const choose = this.action.choose
|
||||||
|
? [...ensureArray(this.action.choose)]
|
||||||
|
: [];
|
||||||
choose.push({ conditions: [], sequence: [] });
|
choose.push({ conditions: [], sequence: [] });
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: { ...this.action, choose },
|
value: { ...this.action, choose },
|
||||||
@ -129,7 +136,9 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
private _removeOption(ev: CustomEvent) {
|
private _removeOption(ev: CustomEvent) {
|
||||||
const index = (ev.currentTarget as any).idx;
|
const index = (ev.currentTarget as any).idx;
|
||||||
const choose = this.action.choose ? [...this.action.choose] : [];
|
const choose = this.action.choose
|
||||||
|
? [...ensureArray(this.action.choose)]
|
||||||
|
: [];
|
||||||
choose.splice(index, 1);
|
choose.splice(index, 1);
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: { ...this.action, choose },
|
value: { ...this.action, choose },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user