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 ? (
{t('Loaded data cached')}
{moment.utc(this.props.cachedTimestamp).fromNow()}
) :
t('Loaded from cache');
const tooltipContent = (
{cachedText}. {t('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;