2018-06-17 19:13:55 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap';
|
2018-08-26 00:39:27 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2018-06-17 19:13:55 +03:00
|
|
|
|
2018-08-26 00:39:27 +03:00
|
|
|
const propTypes = {
|
|
|
|
serverId: PropTypes.string.isRequired,
|
|
|
|
paginator: PropTypes.shape({
|
|
|
|
currentPage: PropTypes.number,
|
|
|
|
pagesCount: PropTypes.number,
|
|
|
|
}),
|
|
|
|
};
|
2018-06-17 19:13:55 +03:00
|
|
|
|
2018-08-26 00:39:27 +03:00
|
|
|
export default function Paginator({ paginator = {}, serverId }) {
|
|
|
|
const { currentPage, pagesCount = 0 } = paginator;
|
|
|
|
|
|
|
|
if (pagesCount <= 1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const renderPages = () => {
|
|
|
|
const pages = [];
|
|
|
|
|
|
|
|
for (let i = 1; i <= pagesCount; i++) {
|
|
|
|
pages.push(
|
|
|
|
<PaginationItem key={i} active={currentPage === i}>
|
2018-07-16 19:48:50 +03:00
|
|
|
<PaginationLink
|
|
|
|
tag={Link}
|
2018-08-26 00:39:27 +03:00
|
|
|
to={`/server/${serverId}/list-short-urls/${i}`}
|
|
|
|
>
|
|
|
|
{i}
|
|
|
|
</PaginationLink>
|
2018-06-17 19:13:55 +03:00
|
|
|
</PaginationItem>
|
2018-08-26 00:39:27 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pages;
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Pagination listClassName="flex-wrap">
|
|
|
|
<PaginationItem disabled={currentPage === 1}>
|
|
|
|
<PaginationLink
|
|
|
|
previous
|
|
|
|
tag={Link}
|
|
|
|
to={`/server/${serverId}/list-short-urls/${currentPage - 1}`}
|
|
|
|
/>
|
|
|
|
</PaginationItem>
|
|
|
|
{renderPages()}
|
|
|
|
<PaginationItem disabled={currentPage >= pagesCount}>
|
|
|
|
<PaginationLink
|
|
|
|
next
|
|
|
|
tag={Link}
|
|
|
|
to={`/server/${serverId}/list-short-urls/${currentPage + 1}`}
|
|
|
|
/>
|
|
|
|
</PaginationItem>
|
|
|
|
</Pagination>
|
|
|
|
);
|
2018-06-17 19:13:55 +03:00
|
|
|
}
|
2018-08-26 00:39:27 +03:00
|
|
|
|
|
|
|
Paginator.propTypes = propTypes;
|