Completed
Push — master ( 6ac893...01672b )
by Alejandro
22s queued 10s
created

src/short-urls/ShortUrls.js

Complexity

Total Complexity 0
Complexity/F 0

Size

Lines of Code 40
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 0
eloc 32
mnd 0
bc 0
fnc 0
dl 0
loc 40
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
ccs 11
cts 12
cp 0.9167
1
import React, { useEffect, useState } from 'react';
2
import PropTypes from 'prop-types';
3
import Paginator from './Paginator';
4
5 1
const ShortUrls = (SearchBar, ShortUrlsList) => {
6 1
  const propTypes = {
7
    match: PropTypes.shape({
8
      params: PropTypes.object,
9
    }),
10
    shortUrlsList: PropTypes.object,
11
  };
12
13 1
  const ShortUrlsComponent = (props) => {
14 1
    const { match: { params }, shortUrlsList } = props;
15 1
    const { page, serverId } = params;
16 1
    const { data = [], pagination } = shortUrlsList;
17 1
    const [ urlsListKey, setUrlsListKey ] = useState(`${serverId}_${page}`);
18
19
    // Using a key on a component makes react to create a new instance every time the key changes
20
    // Without it, pagination on the URL will not make the component to be refreshed
21 1
    useEffect(() => {
22
      setUrlsListKey(`${serverId}_${page}`);
23
    }, [ serverId, page ]);
24
25 1
    return (
26
      <React.Fragment>
27
        <div className="form-group"><SearchBar /></div>
28
        <ShortUrlsList {...props} shortUrlsList={data} key={urlsListKey} />
29
        <Paginator paginator={pagination} serverId={serverId} />
30
      </React.Fragment>
31
    );
32
  };
33
34 1
  ShortUrlsComponent.propTypes = propTypes;
35
36 1
  return ShortUrlsComponent;
37
};
38
39
export default ShortUrls;
40