From 236e5e0b255b3dc7582476fedbf8963a85322335 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 28 Apr 2021 10:23:30 -0700 Subject: [PATCH] Show subtrace steps when selecting a node (#9023) * Show subtrace steps when selecting a node * Limit logic to just child conditions --- .../trace/ha-automation-trace-path-details.ts | 80 +++++++++++++------ 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/src/panels/config/automation/trace/ha-automation-trace-path-details.ts b/src/panels/config/automation/trace/ha-automation-trace-path-details.ts index 2416ea2ad6..51ebbdab7f 100644 --- a/src/panels/config/automation/trace/ha-automation-trace-path-details.ts +++ b/src/panels/config/automation/trace/ha-automation-trace-path-details.ts @@ -99,33 +99,63 @@ export class HaAutomationTracePathDetails extends LitElement { return "This node was not executed and so no further trace information is available."; } - const data: ActionTraceStep[] = paths[this.selected.path]; + const parts: TemplateResult[][] = []; - return data.map((trace, idx) => { - const { - path, - timestamp, - result, - error, - changed_variables, - ...rest - } = trace as any; + let active = false; + const childConditionsPrefix = `${this.selected.path}/conditions/`; - return html` - ${data.length === 1 ? "" : html`

Iteration ${idx + 1}

`} - Executed: - ${formatDateTimeWithSeconds(new Date(timestamp), this.hass.locale)}
- ${result - ? html`Result: -
${safeDump(result)}
` - : error - ? html`
Error: ${error}
` - : ""} - ${Object.keys(rest).length === 0 - ? "" - : html`
${safeDump(rest)}
`} - `; - }); + for (const curPath of Object.keys(this.trace.trace)) { + // Include all child conditions too + if (active) { + if (!curPath.startsWith(childConditionsPrefix)) { + break; + } + } else if (curPath === this.selected.path) { + active = true; + } else { + continue; + } + + const data: ActionTraceStep[] = paths[curPath]; + + parts.push( + data.map((trace, idx) => { + const { + path, + timestamp, + result, + error, + changed_variables, + ...rest + } = trace as any; + + return html` + ${curPath === this.selected.path + ? "" + : html`

+ Condition ${curPath.substr(childConditionsPrefix.length)} +

`} + ${data.length === 1 ? "" : html`

Iteration ${idx + 1}

`} + Executed: + ${formatDateTimeWithSeconds( + new Date(timestamp), + this.hass.locale + )}
+ ${result + ? html`Result: +
${safeDump(result)}
` + : error + ? html`
Error: ${error}
` + : ""} + ${Object.keys(rest).length === 0 + ? "" + : html`
${safeDump(rest)}
`} + `; + }) + ); + } + + return parts; } private _renderSelectedConfig() {