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

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 30
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 25
mnd 2
bc 2
fnc 0
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React from 'react';
2
import PropTypes from 'prop-types';
3
import { Link } from 'react-router-dom';
4
import { serverType } from '../../servers/prop-types';
5
import { shortUrlType } from '../reducers/shortUrlsList';
6
7 9
const propTypes = {
8
  shortUrl: shortUrlType,
9
  selectedServer: serverType,
10
  children: PropTypes.node.isRequired,
11
};
12
13 9
const buildVisitsUrl = ({ id }, { shortCode, domain }) => {
14 2
  const query = domain ? `?domain=${domain}` : '';
15
16 2
  return `/server/${id}/short-code/${shortCode}/visits${query}`;
17
};
18
19 9
const VisitStatsLink = ({ selectedServer, shortUrl, children, ...rest }) => {
20 13
  if (!selectedServer || !shortUrl) {
21 11
    return <span {...rest}>{children}</span>;
22
  }
23
24 2
  return <Link to={buildVisitsUrl(selectedServer, shortUrl)} {...rest}>{children}</Link>;
25
};
26
27 9
VisitStatsLink.propTypes = propTypes;
28
29
export default VisitStatsLink;
30