mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-10 19:06:36 +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 = 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]
|
? [config.choose?.length || 0]
|
||||||
: [trace[0].result.choice]
|
: [trace[0].result.choice]
|
||||||
: [];
|
: [];
|
||||||
return html`
|
return html`
|
||||||
@ -167,7 +167,7 @@ class HatScriptGraph extends LitElement {
|
|||||||
nofocus
|
nofocus
|
||||||
></hat-graph-node>
|
></hat-graph-node>
|
||||||
|
|
||||||
${config.choose.map((branch, i) => {
|
${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;
|
||||||
@ -466,6 +466,10 @@ class HatScriptGraph extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (__DEV__) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log("Error creating script graph:", err);
|
||||||
|
}
|
||||||
return html`
|
return html`
|
||||||
<div class="error">
|
<div class="error">
|
||||||
Error rendering graph. Please download trace and share with the
|
Error rendering graph. Please download trace and share with the
|
||||||
|
@ -112,7 +112,7 @@ export interface ChooseActionChoice {
|
|||||||
|
|
||||||
export interface ChooseAction {
|
export interface ChooseAction {
|
||||||
alias?: string;
|
alias?: string;
|
||||||
choose: ChooseActionChoice[];
|
choose: ChooseActionChoice[] | null;
|
||||||
default?: Action | Action[];
|
default?: Action | Action[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,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 || []).map(
|
||||||
(option, idx) => html`<ha-card>
|
(option, idx) => html`<ha-card>
|
||||||
<mwc-icon-button
|
<mwc-icon-button
|
||||||
.idx=${idx}
|
.idx=${idx}
|
||||||
@ -101,7 +101,7 @@ 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];
|
const choose = this.action.choose ? [...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 +112,7 @@ 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];
|
const choose = this.action.choose ? [...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 +120,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _addOption() {
|
private _addOption() {
|
||||||
const choose = [...this.action.choose];
|
const choose = this.action.choose ? [...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 +129,7 @@ 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];
|
const choose = this.action.choose ? [...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