diff --git a/src/data-table/data-cell.jsx b/src/data-table/data-cell.jsx index 571a299..4266827 100644 --- a/src/data-table/data-cell.jsx +++ b/src/data-table/data-cell.jsx @@ -61,25 +61,12 @@ function getSemaphoreColors (measurement, semaphoreColors) { } return semaphoreColors.statusColors.normal; } -class DataCell extends React.Component { +class DataCell extends React.PureComponent { constructor (props) { super(props); - this.state = { - showTooltip: false - }; - this.handleEnter = this.handleEnter.bind(this); - this.handleLeave = this.handleLeave.bind(this); this.handleSelect = this.handleSelect.bind(this); } - shouldComponentUpdate (nextProps, nextState) { - const { showTooltip } = this.state; - if (showTooltip === nextState.showTooltip) { - return false; - } - return true; - } - handleSelect () { const { data: { meta: { dimensionCount } }, general: { allowFilteringByClick }, measurement, qlik } = this.props; const hasSecondDimension = dimensionCount > 1; @@ -94,16 +81,7 @@ class DataCell extends React.Component { } } - handleEnter () { - this.setState({ showTooltip: true }); - } - - handleLeave () { - this.setState({ showTooltip: false }); - } - render () { - const { showTooltip } = this.state; const { data, general, @@ -157,16 +135,14 @@ class DataCell extends React.Component { - {formattedMeasurementValue} - {showTooltip && !inEditState && formattedMeasurementValue !== '.' - ? - - {formattedMeasurementValue} - : null} + + {formattedMeasurementValue} + ); } diff --git a/src/headers-table/column-header.jsx b/src/headers-table/column-header.jsx index da9120c..e698a82 100644 --- a/src/headers-table/column-header.jsx +++ b/src/headers-table/column-header.jsx @@ -2,41 +2,19 @@ import React from 'react'; import PropTypes from 'prop-types'; import Tooltip from '../tooltip/index.jsx'; -class ColumnHeader extends React.Component { +class ColumnHeader extends React.PureComponent { constructor (props) { super(props); - this.state = { - showTooltip: false - }; - this.handleEnter = this.handleEnter.bind(this); - this.handleLeave = this.handleLeave.bind(this); this.handleSelect = this.handleSelect.bind(this); } - shouldComponentUpdate (nextProps, nextState) { - const { showTooltip } = this.state; - if (showTooltip === nextState.showTooltip) { - return false; - } - return true; - } - handleSelect () { const { entry, qlik } = this.props; qlik.backendApi.selectValues(1, [entry.elementNumber], true); } - handleEnter () { - this.setState({ showTooltip: true }); - } - - handleLeave () { - this.setState({ showTooltip: false }); - } - render () { const { baseCSS, cellSuffix, colSpan, entry, styling, qlik } = this.props; - const { showTooltip } = this.state; const inEditState = qlik.inEditState(); const style = { @@ -51,16 +29,14 @@ class ColumnHeader extends React.Component { className={`grid-cells2${cellSuffix}`} colSpan={colSpan} onClick={this.handleSelect} - onMouseOut={this.handleLeave} - onMouseOver={this.handleEnter} style={style} > - {entry.displayValue} - {showTooltip && !inEditState - ? - - {entry.displayValue} - : null} + + {entry.displayValue} + ); } diff --git a/src/tooltip/index.jsx b/src/tooltip/index.jsx index 1d920e5..060cabe 100644 --- a/src/tooltip/index.jsx +++ b/src/tooltip/index.jsx @@ -1,22 +1,66 @@ import React from 'react'; import PropTypes from 'prop-types'; +class Tooltip extends React.Component { + constructor (props) { + super(props); + this.state = { + showTooltip: false, + xPosition: 0, + yPosition: 0 + }; + this.handleRenderTooltip = this.handleRenderTooltip.bind(this); + } -const Tooltip = ({ children }) => { - const xPosition = event.clientX; - const yPosition = event.clientY; - return ( -
-

+ shouldComponentUpdate (nextProps, nextState) { + const { showTooltip } = this.state; + if (nextState.showTooltip === showTooltip) { + return false; + } + return true; + } + + handleRenderTooltip (event) { + const { showTooltip } = this.state; + const xPosition = event.clientX; + const yPosition = event.clientY; + this.setState({ showTooltip: !showTooltip, + xPosition, + yPosition }); + } + + render () { + const { children, tooltipText, isTooltipActive } = this.props; + const { showTooltip, xPosition, yPosition } = this.state; + + const xPositionOffset = 20; + const yPositionOffset = 75; + return ( +

{children} -

-
- ); -}; + + {showTooltip && isTooltipActive + ? ( +
+

+ {tooltipText} +

+
+ ) : null} +
+ ); + } +} + Tooltip.propTypes = { - children: PropTypes.string.isRequired + children: PropTypes.string.isRequired, + isTooltipActive: PropTypes.bool.isRequired, + tooltipText: PropTypes.string.isRequired }; export default Tooltip;