Completed
Pull Request — master (#268)
by Alejandro
16:58
created

src/visits/ShortUrlVisits.js

Complexity

Total Complexity 0
Complexity/F 0

Size

Lines of Code 81
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 0
eloc 59
mnd 0
bc 0
fnc 0
dl 0
loc 81
ccs 13
cts 14
cp 0.9286
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React, { useEffect } from 'react';
2
import PropTypes from 'prop-types';
3
import qs from 'qs';
4
import { MercureInfoType } from '../mercure/reducers/mercureInfo';
5
import { bindToMercureTopic } from '../mercure/helpers';
6
import { SettingsType } from '../settings/reducers/settings';
7
import { shortUrlVisitsType } from './reducers/shortUrlVisits';
8
import ShortUrlVisitsHeader from './ShortUrlVisitsHeader';
9
import { shortUrlDetailType } from './reducers/shortUrlDetail';
10
11 1
const propTypes = {
12
  history: PropTypes.shape({
13
    goBack: PropTypes.func,
14
  }),
15
  match: PropTypes.shape({
16
    params: PropTypes.object,
17
  }),
18
  location: PropTypes.shape({
19
    search: PropTypes.string,
20
  }),
21
  getShortUrlVisits: PropTypes.func,
22
  shortUrlVisits: shortUrlVisitsType,
23
  getShortUrlDetail: PropTypes.func,
24
  shortUrlDetail: shortUrlDetailType,
25
  cancelGetShortUrlVisits: PropTypes.func,
26
  createNewVisit: PropTypes.func,
27
  loadMercureInfo: PropTypes.func,
28
  mercureInfo: MercureInfoType,
29
  settings: SettingsType,
30
};
31
32 1
const ShortUrlVisits = (VisitsStats) => {
33 1
  const ShortUrlVisitsComp = ({
34
    history,
35
    match,
36
    location,
37
    shortUrlVisits,
38
    shortUrlDetail,
39
    getShortUrlVisits,
40
    getShortUrlDetail,
41
    cancelGetShortUrlVisits,
42
    createNewVisit,
43
    loadMercureInfo,
44
    mercureInfo,
45
    settings: { realTimeUpdates },
46
  }) => {
47 1
    const { params } = match;
48 1
    const { shortCode } = params;
49 1
    const { search } = location;
50 1
    const { domain } = qs.parse(search, { ignoreQueryPrefix: true });
51
52 1
    const loadVisits = (dates) => getShortUrlVisits(shortCode, { ...dates, domain });
53
54 1
    useEffect(() => {
55
      getShortUrlDetail(shortCode, domain);
56
    }, []);
57 1
    useEffect(
58
      bindToMercureTopic(
59
        mercureInfo,
60
        realTimeUpdates,
61
        `https://shlink.io/new-visit/${shortCode}`,
62
        createNewVisit,
63
        loadMercureInfo
64
      ),
65
      [ mercureInfo ],
66
    );
67
68 1
    return (
69
      <VisitsStats getVisits={loadVisits} cancelGetVisits={cancelGetShortUrlVisits} visitsInfo={shortUrlVisits}>
70
        <ShortUrlVisitsHeader shortUrlDetail={shortUrlDetail} shortUrlVisits={shortUrlVisits} goBack={history.goBack} />
71
      </VisitsStats>
72
    );
73
  };
74
75 1
  ShortUrlVisitsComp.propTypes = propTypes;
76
77 1
  return ShortUrlVisitsComp;
78
};
79
80
export default ShortUrlVisits;
81