import React from 'react'; import PropTypes from 'prop-types'; import { Label } from 'react-bootstrap'; import moment from 'moment'; import TooltipWrapper from './TooltipWrapper'; 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 ? ( Loaded data cached {moment.utc(this.props.cachedTimestamp).fromNow()} ) : 'Loaded from cache'; const tooltipContent = ( {cachedText}. Click to force-refresh ); this.setState({ tooltipContent }); } mouseOver() { this.updateTooltipContent(); this.setState({ hovered: true }); } mouseOut() { this.setState({ hovered: false }); } render() { const labelStyle = this.state.hovered ? 'primary' : 'default'; return ( ); } } CacheLabel.propTypes = propTypes; export default CacheLabel;