| Total Complexity | 2 |
| Complexity/F | 0 |
| Lines of Code | 30 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 100% |
| Changes | 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 | 6 | const propTypes = { |
|
| 8 | shortUrl: shortUrlType, |
||
| 9 | selectedServer: serverType, |
||
| 10 | children: PropTypes.node.isRequired, |
||
| 11 | }; |
||
| 12 | |||
| 13 | 6 | 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 | 6 | 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 | 6 | VisitStatsLink.propTypes = propTypes; |
|
| 28 | |||
| 29 | export default VisitStatsLink; |
||
| 30 |