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-07-28 11:41:05 +03:00
|
|
|
export default class Paginator extends React.Component {
|
2018-06-17 19:13:55 +03:00
|
|
|
render() {
|
|
|
|
const { paginator = {}, serverId } = this.props;
|
|
|
|
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}>
|
|
|
|
<PaginationLink
|
|
|
|
tag={Link}
|
|
|
|
to={`/server/${serverId}/list-short-urls/${i}`}
|
|
|
|
>
|
|
|
|
{i}
|
|
|
|
</PaginationLink>
|
|
|
|
</PaginationItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pages;
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2018-08-05 11:12:49 +03:00
|
|
|
<Pagination listClassName="flex-wrap">
|
2018-06-17 19:13:55 +03:00
|
|
|
<PaginationItem disabled={currentPage === 1}>
|
2018-07-16 19:48:50 +03:00
|
|
|
<PaginationLink
|
|
|
|
previous
|
|
|
|
tag={Link}
|
|
|
|
to={`/server/${serverId}/list-short-urls/${currentPage - 1}`}
|
|
|
|
/>
|
2018-06-17 19:13:55 +03:00
|
|
|
</PaginationItem>
|
|
|
|
{renderPages()}
|
|
|
|
<PaginationItem disabled={currentPage >= pagesCount}>
|
2018-07-16 19:48:50 +03:00
|
|
|
<PaginationLink
|
|
|
|
next
|
|
|
|
tag={Link}
|
|
|
|
to={`/server/${serverId}/list-short-urls/${currentPage + 1}`}
|
|
|
|
/>
|
2018-06-17 19:13:55 +03:00
|
|
|
</PaginationItem>
|
|
|
|
</Pagination>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|