1
|
|
|
import React from 'react'; |
2
|
|
|
import { Link } from 'react-router-dom'; |
3
|
|
|
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap'; |
4
|
|
|
import PropTypes from 'prop-types'; |
5
|
|
|
import { isPageDisabled, keyForPage, progressivePagination } from '../utils/helpers/pagination'; |
6
|
|
|
import './Paginator.scss'; |
7
|
|
|
|
8
|
2 |
|
const propTypes = { |
9
|
|
|
serverId: PropTypes.string.isRequired, |
10
|
|
|
paginator: PropTypes.shape({ |
11
|
|
|
currentPage: PropTypes.number, |
12
|
|
|
pagesCount: PropTypes.number, |
13
|
|
|
}), |
14
|
|
|
}; |
15
|
|
|
|
16
|
2 |
|
const Paginator = ({ paginator = {}, serverId }) => { |
17
|
2 |
|
const { currentPage, pagesCount = 0 } = paginator; |
18
|
|
|
|
19
|
2 |
|
if (pagesCount <= 1) { |
20
|
1 |
|
return null; |
21
|
|
|
} |
22
|
|
|
|
23
|
1 |
|
const renderPages = () => |
24
|
1 |
|
progressivePagination(currentPage, pagesCount).map((pageNumber, index) => ( |
25
|
5 |
|
<PaginationItem |
26
|
|
|
key={keyForPage(pageNumber, index)} |
27
|
|
|
disabled={isPageDisabled(pageNumber)} |
28
|
|
|
active={currentPage === pageNumber} |
29
|
|
|
> |
30
|
|
|
<PaginationLink |
31
|
|
|
tag={Link} |
32
|
|
|
to={`/server/${serverId}/list-short-urls/${pageNumber}`} |
33
|
|
|
> |
34
|
|
|
{pageNumber} |
35
|
|
|
</PaginationLink> |
36
|
|
|
</PaginationItem> |
37
|
|
|
)); |
38
|
|
|
|
39
|
1 |
|
return ( |
40
|
|
|
<Pagination className="short-urls-paginator" listClassName="flex-wrap justify-content-center mb-0"> |
41
|
|
|
<PaginationItem disabled={currentPage === 1}> |
42
|
|
|
<PaginationLink |
43
|
|
|
previous |
44
|
|
|
tag={Link} |
45
|
|
|
to={`/server/${serverId}/list-short-urls/${currentPage - 1}`} |
46
|
|
|
/> |
47
|
|
|
</PaginationItem> |
48
|
|
|
{renderPages()} |
49
|
|
|
<PaginationItem disabled={currentPage >= pagesCount}> |
50
|
|
|
<PaginationLink |
51
|
|
|
next |
52
|
|
|
tag={Link} |
53
|
|
|
to={`/server/${serverId}/list-short-urls/${currentPage + 1}`} |
54
|
|
|
/> |
55
|
|
|
</PaginationItem> |
56
|
|
|
</Pagination> |
57
|
|
|
); |
58
|
|
|
}; |
59
|
|
|
|
60
|
2 |
|
Paginator.propTypes = propTypes; |
61
|
|
|
|
62
|
|
|
export default Paginator; |
63
|
|
|
|