mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-09 10:26:35 +00:00
Handle choose being null (#8859)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
d69accd9a5
commit
7d801ff84c
@ -143,7 +143,7 @@ class HatScriptGraph extends LitElement {
|
||||
const trace = this.trace.trace[path] as ChooseActionTraceStep[] | undefined;
|
||||
const trace_path = trace?.[0].result
|
||||
? trace[0].result.choice === "default"
|
||||
? [config.choose.length]
|
||||
? [config.choose?.length || 0]
|
||||
: [trace[0].result.choice]
|
||||
: [];
|
||||
return html`
|
||||
@ -167,7 +167,7 @@ class HatScriptGraph extends LitElement {
|
||||
nofocus
|
||||
></hat-graph-node>
|
||||
|
||||
${config.choose.map((branch, i) => {
|
||||
${config.choose?.map((branch, i) => {
|
||||
const branch_path = `${path}/choose/${i}`;
|
||||
const track_this =
|
||||
trace !== undefined && trace[0].result?.choice === i;
|
||||
@ -466,6 +466,10 @@ class HatScriptGraph extends LitElement {
|
||||
</div>
|
||||
`;
|
||||
} catch (err) {
|
||||
if (__DEV__) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log("Error creating script graph:", err);
|
||||
}
|
||||
return html`
|
||||
<div class="error">
|
||||
Error rendering graph. Please download trace and share with the
|
||||
|
@ -112,7 +112,7 @@ export interface ChooseActionChoice {
|
||||
|
||||
export interface ChooseAction {
|
||||
alias?: string;
|
||||
choose: ChooseActionChoice[];
|
||||
choose: ChooseActionChoice[] | null;
|
||||
default?: Action | Action[];
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
||||
const action = this.action;
|
||||
|
||||
return html`
|
||||
${action.choose.map(
|
||||
${(action.choose || []).map(
|
||||
(option, idx) => html`<ha-card>
|
||||
<mwc-icon-button
|
||||
.idx=${idx}
|
||||
@ -101,7 +101,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
||||
ev.stopPropagation();
|
||||
const value = ev.detail.value as Condition[];
|
||||
const index = (ev.target as any).idx;
|
||||
const choose = [...this.action.choose];
|
||||
const choose = this.action.choose ? [...this.action.choose] : [];
|
||||
choose[index].conditions = value;
|
||||
fireEvent(this, "value-changed", {
|
||||
value: { ...this.action, choose },
|
||||
@ -112,7 +112,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
||||
ev.stopPropagation();
|
||||
const value = ev.detail.value as Action[];
|
||||
const index = (ev.target as any).idx;
|
||||
const choose = [...this.action.choose];
|
||||
const choose = this.action.choose ? [...this.action.choose] : [];
|
||||
choose[index].sequence = value;
|
||||
fireEvent(this, "value-changed", {
|
||||
value: { ...this.action, choose },
|
||||
@ -120,7 +120,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
||||
}
|
||||
|
||||
private _addOption() {
|
||||
const choose = [...this.action.choose];
|
||||
const choose = this.action.choose ? [...this.action.choose] : [];
|
||||
choose.push({ conditions: [], sequence: [] });
|
||||
fireEvent(this, "value-changed", {
|
||||
value: { ...this.action, choose },
|
||||
@ -129,7 +129,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
||||
|
||||
private _removeOption(ev: CustomEvent) {
|
||||
const index = (ev.currentTarget as any).idx;
|
||||
const choose = [...this.action.choose];
|
||||
const choose = this.action.choose ? [...this.action.choose] : [];
|
||||
choose.splice(index, 1);
|
||||
fireEvent(this, "value-changed", {
|
||||
value: { ...this.action, choose },
|
||||
|
Loading…
x
Reference in New Issue
Block a user