Handle if in repeat (#12544)

This commit is contained in:
Bram Kragten 2022-05-02 23:48:28 +02:00 committed by GitHub
parent e99143139e
commit 3a305a44b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -215,7 +215,19 @@ export class HatScriptGraph extends LitElement {
private render_if_node(config: IfAction, path: string, graphStart = false) { private render_if_node(config: IfAction, path: string, graphStart = false) {
const trace = this.trace.trace[path] as IfActionTraceStep[] | undefined; const trace = this.trace.trace[path] as IfActionTraceStep[] | undefined;
const result = trace?.[0].result?.choice; let trackThen = false;
let trackElse = false;
for (const trc of trace || []) {
if (!trackThen && trc.result?.choice === "then") {
trackThen = true;
}
if ((!trackElse && trc.result?.choice === "else") || !trc.result) {
trackElse = true;
}
if (trackElse && trackThen) {
break;
}
}
return html` return html`
<hat-graph-branch <hat-graph-branch
tabindex=${trace === undefined ? "-1" : "0"} tabindex=${trace === undefined ? "-1" : "0"}
@ -232,10 +244,10 @@ export class HatScriptGraph extends LitElement {
nofocus nofocus
></hat-graph-node> ></hat-graph-node>
${config.else ${config.else
? html`<div class="graph-container" ?track=${result === "else"}> ? html`<div class="graph-container" ?track=${trackElse}>
<hat-graph-node <hat-graph-node
.iconPath=${mdiCallMissed} .iconPath=${mdiCallMissed}
?track=${result === "else"} ?track=${trackElse}
?active=${this.selected === path} ?active=${this.selected === path}
nofocus nofocus
></hat-graph-node ></hat-graph-node
@ -243,13 +255,11 @@ export class HatScriptGraph extends LitElement {
this.render_action_node(action, `${path}/else/${j}`) this.render_action_node(action, `${path}/else/${j}`)
)} )}
</div>` </div>`
: html`<hat-graph-spacer : html`<hat-graph-spacer ?track=${trackElse}></hat-graph-spacer>`}
?track=${result === "else" || result === undefined} <div class="graph-container" ?track=${trackThen}>
></hat-graph-spacer>`}
<div class="graph-container" ?track=${result === "then"}>
<hat-graph-node <hat-graph-node
.iconPath=${mdiCallReceived} .iconPath=${mdiCallReceived}
?track=${result === "then"} ?track=${trackThen}
?active=${this.selected === path} ?active=${this.selected === path}
nofocus nofocus
></hat-graph-node> ></hat-graph-node>