all files / src/explore/components/ RowCountLabel.jsx

100% Statements 18/18
100% Branches 6/6
100% Functions 1/1
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                                                      
import React from 'react';
import PropTypes from 'prop-types';
import { Label } from 'react-bootstrap';
 
import { t } from '../../locales';
import { defaultNumberFormatter } from '../../modules/utils';
import TooltipWrapper from '../../components/TooltipWrapper';
 
 
const propTypes = {
  rowcount: PropTypes.number,
  limit: PropTypes.number,
};
 
const defaultProps = {
};
 
export default function RowCountLabel({ rowcount, limit }) {
  const limitReached = rowcount === limit;
  const bsStyle = (limitReached || rowcount === 0) ? 'warning' : 'default';
  const formattedRowCount = defaultNumberFormatter(rowcount);
  const tooltip = (
    <span>
      {limitReached &&
        <div>{t('Limit reached')}</div>}
      {rowcount}
    </span>
  );
  return (
    <TooltipWrapper label="tt-rowcount" tooltip={tooltip}>
      <Label
        bsStyle={bsStyle}
        style={{ fontSize: '10px', marginRight: '5px', cursor: 'pointer' }}
      >
        {formattedRowCount} rows
      </Label>
    </TooltipWrapper>
  );
}
 
RowCountLabel.propTypes = propTypes;
RowCountLabel.defaultProps = defaultProps;