Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove settooltip #9332

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 17 additions & 57 deletions superset-frontend/src/chart/ChartRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { snakeCase } from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
import { SuperChart } from '@superset-ui/chart';
import { Tooltip } from 'react-bootstrap';
import { Logger, LOG_ACTIONS_RENDER_CHART } from '../logger/LogUtils';

const propTypes = {
Expand Down Expand Up @@ -62,11 +61,8 @@ const defaultProps = {
class ChartRenderer extends React.Component {
constructor(props) {
super(props);
this.state = {};

this.hasQueryResponseChange = false;

this.setTooltip = this.setTooltip.bind(this);
this.handleAddFilter = this.handleAddFilter.bind(this);
this.handleRenderSuccess = this.handleRenderSuccess.bind(this);
this.handleRenderFailure = this.handleRenderFailure.bind(this);
Expand All @@ -76,13 +72,12 @@ class ChartRenderer extends React.Component {
onAddFilter: this.handleAddFilter,
onError: this.handleRenderFailure,
setControlValue: this.handleSetControlValue,
setTooltip: this.setTooltip,
onFilterMenuOpen: this.props.onFilterMenuOpen,
onFilterMenuClose: this.props.onFilterMenuClose,
};
}

shouldComponentUpdate(nextProps, nextState) {
shouldComponentUpdate(nextProps) {
const resultsReady =
nextProps.queryResponse &&
['success', 'rendered'].indexOf(nextProps.chartStatus) > -1 &&
Expand All @@ -98,7 +93,6 @@ class ChartRenderer extends React.Component {
nextProps.annotationData !== this.props.annotationData ||
nextProps.height !== this.props.height ||
nextProps.width !== this.props.width ||
nextState.tooltip !== this.state.tooltip ||
nextProps.triggerRender ||
nextProps.formData.color_scheme !== this.props.formData.color_scheme
) {
Expand All @@ -108,10 +102,6 @@ class ChartRenderer extends React.Component {
return false;
}

setTooltip(tooltip) {
this.setState({ tooltip });
}

handleAddFilter(col, vals, merge = true, refresh = true) {
this.props.addFilter(col, vals, merge, refresh);
}
Expand Down Expand Up @@ -164,33 +154,6 @@ class ChartRenderer extends React.Component {
}
}

renderTooltip() {
const { tooltip } = this.state;
if (tooltip && tooltip.content) {
return (
<Tooltip
className="chart-tooltip"
id="chart-tooltip"
placement="right"
positionTop={tooltip.y + 30}
positionLeft={tooltip.x + 30}
arrowOffsetTop={10}
>
{typeof tooltip.content === 'string' ? (
<div // eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: dompurify.sanitize(tooltip.content),
}}
/>
) : (
tooltip.content
)}
</Tooltip>
);
}
return null;
}

render() {
const {
chartAlert,
Expand Down Expand Up @@ -233,25 +196,22 @@ class ChartRenderer extends React.Component {
: snakeCaseVizType;

return (
<>
{this.renderTooltip()}
<SuperChart
disableErrorBoundary
id={`chart-id-${chartId}`}
className={chartClassName}
chartType={vizType}
width={width}
height={height}
annotationData={annotationData}
datasource={datasource}
initialValues={initialValues}
formData={formData}
hooks={this.hooks}
queryData={queryResponse}
onRenderSuccess={this.handleRenderSuccess}
onRenderFailure={this.handleRenderFailure}
/>
</>
<SuperChart
disableErrorBoundary
id={`chart-id-${chartId}`}
className={chartClassName}
chartType={vizType}
width={width}
height={height}
annotationData={annotationData}
datasource={datasource}
initialValues={initialValues}
formData={formData}
hooks={this.hooks}
queryData={queryResponse}
onRenderSuccess={this.handleRenderSuccess}
onRenderFailure={this.handleRenderFailure}
/>
);
}
}
Expand Down