<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { Label } from 'react-bootstrap';
import moment from 'moment';
import TooltipWrapper from './TooltipWrapper';
import { t } from '../locales';

const propTypes = {
  onClick: PropTypes.func,
  cachedTimestamp: PropTypes.string,
  className: PropTypes.string,
};

class CacheLabel extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      tooltipContent: '',
      hovered: false,
    };
  }

  updateTooltipContent() {
    const cachedText = this.props.cachedTimestamp ? (
      <span>
        t('Loaded data cached') <b>{moment.utc(this.props.cachedTimestamp).fromNow()}</b>
      </span>) :
      t('Loaded from cache');

    const tooltipContent = (
      <span>
        {cachedText}.
        {t('Click to force-refresh')}
      </span>
    );
    this.setState({ tooltipContent });
  }

  mouseOver() {
    this.updateTooltipContent();
    this.setState({ hovered: true });
  }

  mouseOut() {
    this.setState({ hovered: false });
  }

  render() {
    const labelStyle = this.state.hovered ? 'primary' : 'default';
    return (
      <TooltipWrapper
        tooltip={this.state.tooltipContent}
        label="cache-desc"
      >
        <Label
          className={this.props.className}
          bsStyle={labelStyle}
          style={{ fontSize: '10px', marginRight: '5px', cursor: 'pointer' }}
          onClick={this.props.onClick}
          onMouseOver={this.mouseOver.bind(this)}
          onMouseOut={this.mouseOut.bind(this)}
        >
          cached <i className="fa fa-refresh" />
        </Label>
      </TooltipWrapper>);
  }
}
CacheLabel.propTypes = propTypes;

export default CacheLabel;
<commit_msg>[explore] fix cached tooltip (#3526)<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { Label } from 'react-bootstrap';
import moment from 'moment';
import TooltipWrapper from './TooltipWrapper';
import { t } from '../locales';

const propTypes = {
  onClick: PropTypes.func,
  cachedTimestamp: PropTypes.string,
  className: PropTypes.string,
};

class CacheLabel extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      tooltipContent: '',
      hovered: false,
    };
  }

  updateTooltipContent() {
    const cachedText = this.props.cachedTimestamp ? (
      <span>
        {t('Loaded data cached')}
        <b> {moment.utc(this.props.cachedTimestamp).fromNow()}</b>
      </span>) :
      t('Loaded from cache');

    const tooltipContent = (
      <span>
        {cachedText}. {t('Click to force-refresh')}
      </span>
    );
    this.setState({ tooltipContent });
  }

  mouseOver() {
    this.updateTooltipContent();
    this.setState({ hovered: true });
  }

  mouseOut() {
    this.setState({ hovered: false });
  }

  render() {
    const labelStyle = this.state.hovered ? 'primary' : 'default';
    return (
      <TooltipWrapper
        tooltip={this.state.tooltipContent}
        label="cache-desc"
      >
        <Label
          className={this.props.className}
          bsStyle={labelStyle}
          style={{ fontSize: '10px', marginRight: '5px', cursor: 'pointer' }}
          onClick={this.props.onClick}
          onMouseOver={this.mouseOver.bind(this)}
          onMouseOut={this.mouseOut.bind(this)}
        >
          cached <i className="fa fa-refresh" />
        </Label>
      </TooltipWrapper>);
  }
}
CacheLabel.propTypes = propTypes;

export default CacheLabel;

{'fraction_non_alphanumeric': 0.14257256687535572, 'fraction_numerical': 0.0028457598178713715, 'mean_word_length': 2.707805907172996, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7554491', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1060, 'n_words': 221}