mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Template dev tools: Print the type of the response and stringify objects (#7439)
This commit is contained in:
parent
9fbc94e8d8
commit
174f8f5823
@ -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
|
||||
class="render-spinner"
|
||||
.active=${this._rendering}
|
||||
size="small"
|
||||
></ha-circular-progress>
|
||||
|
||||
${this._rendering
|
||||
? html`<ha-circular-progress
|
||||
class="render-spinner"
|
||||
active
|
||||
size="small"
|
||||
></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>
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user