src/short-urls/helpers/ShortUrlVisitsCount.js   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 65
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 1
eloc 56
mnd 1
bc 1
fnc 0
dl 0
loc 65
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
ccs 10
cts 12
cp 0.8333
1
import React, { useRef } from 'react';
2
import PropTypes from 'prop-types';
3
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4
import { faInfoCircle as infoIcon } from '@fortawesome/free-solid-svg-icons';
5
import { UncontrolledTooltip } from 'reactstrap';
6
import classNames from 'classnames';
7
import { serverType } from '../../servers/prop-types';
8
import { prettify } from '../../utils/helpers/numbers';
9
import { shortUrlType } from '../reducers/shortUrlsList';
10
import VisitStatsLink from './VisitStatsLink';
11
import './ShortUrlVisitsCount.scss';
12
13 7
const propTypes = {
14
  visitsCount: PropTypes.number.isRequired,
15
  shortUrl: shortUrlType,
16
  selectedServer: serverType,
17
  active: PropTypes.bool,
18
};
19
20 7
const ShortUrlVisitsCount = ({ visitsCount, shortUrl, selectedServer, active = false }) => {
21 5
  const maxVisits = shortUrl && shortUrl.meta && shortUrl.meta.maxVisits;
22
  const visitsLink = (
23 5
    <VisitStatsLink selectedServer={selectedServer} shortUrl={shortUrl}>
24
      <strong
25
        className={classNames('short-url-visits-count__amount', { 'short-url-visits-count__amount--big': active })}
26
      >
27
        {prettify(visitsCount)}
28
      </strong>
29
    </VisitStatsLink>
30
  );
31
32 5
  if (!maxVisits) {
33 4
    return visitsLink;
34
  }
35
36 1
  const prettifiedMaxVisits = prettify(maxVisits);
37 1
  const tooltipRef = useRef();
38
39 1
  return (
40
    <React.Fragment>
41
      <span className="indivisible">
42
        {visitsLink}
43
        <small
44
          className="short-urls-visits-count__max-visits-control"
45
          ref={(el) => {
46
            tooltipRef.current = el;
47
          }}
48
        >
49
          {' '}/ {prettifiedMaxVisits}{' '}
50
          <sup>
51
            <FontAwesomeIcon icon={infoIcon} />
52
          </sup>
53
        </small>
54
      </span>
55
      <UncontrolledTooltip target={() => tooltipRef.current} placement="bottom">
56
        This short URL will not accept more than <b>{prettifiedMaxVisits}</b> visits.
57
      </UncontrolledTooltip>
58
    </React.Fragment>
59
  );
60
};
61
62 7
ShortUrlVisitsCount.propTypes = propTypes;
63
64
export default ShortUrlVisitsCount;
65