Dashboard Performance: HtmlContent improvements (#4726)

* Dashboard Performance: Memoize HtmlContent

* Only render HtmlContent if there is a description
This commit is contained in:
Gabriel Dutra
2020-03-15 10:12:50 -03:00
committed by GitHub
parent f4b69d4495
commit f6750428cf
2 changed files with 9 additions and 5 deletions

View File

@@ -2,14 +2,14 @@ import React from "react";
import PropTypes from "prop-types";
import { sanitize } from "dompurify";
export default function HtmlContent({ children, ...props }) {
const HtmlContent = React.memo(function HtmlContent({ children, ...props }) {
return (
<div
{...props}
dangerouslySetInnerHTML={{ __html: sanitize(children) }} // eslint-disable-line react/no-danger
/>
);
}
});
HtmlContent.propTypes = {
children: PropTypes.string,
@@ -18,3 +18,5 @@ HtmlContent.propTypes = {
HtmlContent.defaultProps = {
children: "",
};
export default HtmlContent;

View File

@@ -94,9 +94,11 @@ function VisualizationWidgetHeader({ widget, refreshStartedAt, parameters, onPar
<p>
<QueryLink query={widget.getQuery()} visualization={widget.visualization} readOnly={!canViewQuery} />
</p>
<HtmlContent className="text-muted markdown query--description">
{markdown.toHTML(widget.getQuery().description || "")}
</HtmlContent>
{!isEmpty(widget.getQuery().description) && (
<HtmlContent className="text-muted markdown query--description">
{markdown.toHTML(widget.getQuery().description || "")}
</HtmlContent>
)}
</div>
</div>
{!isEmpty(parameters) && (