Template dev tools: Print the type of the response and stringify objects (#7439)

This commit is contained in:
Bram Kragten 2020-10-22 23:51:33 +02:00 committed by GitHub
parent 9fbc94e8d8
commit 174f8f5823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 9 deletions

View File

@ -82,6 +82,13 @@ class HaPanelDevTemplate extends LitElement {
}
protected render() {
const type = typeof this._templateResult?.result;
const resultType =
type === "object"
? Array.isArray(this._templateResult?.result)
? "list"
: "dict"
: type;
return html`
<div
class="content ${classMap({
@ -141,16 +148,28 @@ class HaPanelDevTemplate extends LitElement {
</div>
<div class="render-pane">
<ha-circular-progress
${this._rendering
? html`<ha-circular-progress
class="render-spinner"
.active=${this._rendering}
active
size="small"
></ha-circular-progress>
></ha-circular-progress>`
: ""}
${this._templateResult
? html`${this.hass.localize(
"ui.panel.developer-tools.tabs.templates.result_type"
)}:
${resultType}`
: ""}
<!-- prettier-ignore -->
<pre
class="rendered ${classMap({ error: Boolean(this._error) })}"
><!-- display: block -->${this._error}${this._templateResult
?.result}</pre>
class="rendered ${classMap({
error: Boolean(this._error),
[resultType]: resultType,
})}"
>${this._error}${type === "object"
? JSON.stringify(this._templateResult!.result, null, 2)
: this._templateResult?.result}</pre>
${this._templateResult?.listeners.time
? html`
<p>

View File

@ -2957,6 +2957,7 @@
"description": "Templates are rendered using the Jinja2 template engine with some Home Assistant specific extensions.",
"editor": "Template editor",
"reset": "Reset to demo template",
"result_type": "Result type",
"jinja_documentation": "Jinja2 template documentation",
"template_extensions": "Home Assistant template extensions",
"unknown_error_template": "Unknown error rendering template",