src/common/SimplePaginator.js   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 46
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 39
mnd 1
bc 1
fnc 0
dl 0
loc 46
ccs 8
cts 8
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 classNames from 'classnames';
4
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap';
5
import { isPageDisabled, keyForPage, progressivePagination } from '../utils/helpers/pagination';
6
import './SimplePaginator.scss';
7
8 4
const propTypes = {
9
  pagesCount: PropTypes.number.isRequired,
10
  currentPage: PropTypes.number.isRequired,
11
  setCurrentPage: PropTypes.func.isRequired,
12
  centered: PropTypes.bool,
13
};
14
15 4
const SimplePaginator = ({ pagesCount, currentPage, setCurrentPage, centered = true }) => {
16 7
  if (pagesCount < 2) {
17 4
    return null;
18
  }
19
20 28
  const onClick = (page) => () => setCurrentPage(page);
21
22 3
  return (
23
    <Pagination listClassName={classNames('flex-wrap mb-0 simple-paginator', { 'justify-content-center': centered })}>
24
      <PaginationItem disabled={currentPage <= 1}>
25
        <PaginationLink previous tag="span" onClick={onClick(currentPage - 1)} />
26
      </PaginationItem>
27
      {progressivePagination(currentPage, pagesCount).map((pageNumber, index) => (
28 22
        <PaginationItem
29
          key={keyForPage(pageNumber, index)}
30
          disabled={isPageDisabled(pageNumber)}
31
          active={currentPage === pageNumber}
32
        >
33
          <PaginationLink tag="span" onClick={onClick(pageNumber)}>{pageNumber}</PaginationLink>
34
        </PaginationItem>
35
      ))}
36
      <PaginationItem disabled={currentPage >= pagesCount}>
37
        <PaginationLink next tag="span" onClick={onClick(currentPage + 1)} />
38
      </PaginationItem>
39
    </Pagination>
40
  );
41
};
42
43 4
SimplePaginator.propTypes = propTypes;
44
45
export default SimplePaginator;
46