mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-01 13:16:42 +00:00
Used progressive pagination for the short URLs list
This commit is contained in:
@@ -10,9 +10,9 @@ const propTypes = {
|
||||
setCurrentPage: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export const ellipsis = '...';
|
||||
export const ELLIPSIS = '...';
|
||||
|
||||
const pagination = (currentPage, pageCount) => {
|
||||
export const progressivePagination = (currentPage, pageCount) => {
|
||||
const delta = 2;
|
||||
const pages = range(
|
||||
max(delta, currentPage - delta),
|
||||
@@ -20,10 +20,10 @@ const pagination = (currentPage, pageCount) => {
|
||||
);
|
||||
|
||||
if (currentPage - delta > delta) {
|
||||
pages.unshift(ellipsis);
|
||||
pages.unshift(ELLIPSIS);
|
||||
}
|
||||
if (currentPage + delta < pageCount - 1) {
|
||||
pages.push(ellipsis);
|
||||
pages.push(ELLIPSIS);
|
||||
}
|
||||
|
||||
pages.unshift(1);
|
||||
@@ -44,11 +44,11 @@ const SimplePaginator = ({ pagesCount, currentPage, setCurrentPage }) => {
|
||||
<PaginationItem disabled={currentPage <= 1}>
|
||||
<PaginationLink previous tag="span" onClick={onClick(currentPage - 1)} />
|
||||
</PaginationItem>
|
||||
{pagination(currentPage, pagesCount).map((page, index) => (
|
||||
{progressivePagination(currentPage, pagesCount).map((page, index) => (
|
||||
<PaginationItem
|
||||
key={page !== ellipsis ? page : `${page}_${index}`}
|
||||
key={page !== ELLIPSIS ? page : `${page}_${index}`}
|
||||
active={page === currentPage}
|
||||
disabled={page === ellipsis}
|
||||
disabled={page === ELLIPSIS}
|
||||
>
|
||||
<PaginationLink tag="span" onClick={onClick(page)}>{page}</PaginationLink>
|
||||
</PaginationItem>
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap';
|
||||
import PropTypes from 'prop-types';
|
||||
import { rangeOf } from '../utils/utils';
|
||||
import { ELLIPSIS, progressivePagination } from '../common/SimplePaginator';
|
||||
|
||||
const propTypes = {
|
||||
serverId: PropTypes.string.isRequired,
|
||||
@@ -12,7 +12,7 @@ const propTypes = {
|
||||
}),
|
||||
};
|
||||
|
||||
export default function Paginator({ paginator = {}, serverId }) {
|
||||
const Paginator = ({ paginator = {}, serverId }) => {
|
||||
const { currentPage, pagesCount = 0 } = paginator;
|
||||
|
||||
if (pagesCount <= 1) {
|
||||
@@ -20,8 +20,12 @@ export default function Paginator({ paginator = {}, serverId }) {
|
||||
}
|
||||
|
||||
const renderPages = () =>
|
||||
rangeOf(pagesCount, (pageNumber) => (
|
||||
<PaginationItem key={pageNumber} active={currentPage === pageNumber}>
|
||||
progressivePagination(currentPage, pagesCount).map((pageNumber, index) => (
|
||||
<PaginationItem
|
||||
key={pageNumber !== ELLIPSIS ? pageNumber : `${pageNumber}_${index}`}
|
||||
active={currentPage === pageNumber}
|
||||
disabled={pageNumber === ELLIPSIS}
|
||||
>
|
||||
<PaginationLink
|
||||
tag={Link}
|
||||
to={`/server/${serverId}/list-short-urls/${pageNumber}`}
|
||||
@@ -50,6 +54,8 @@ export default function Paginator({ paginator = {}, serverId }) {
|
||||
</PaginationItem>
|
||||
</Pagination>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Paginator.propTypes = propTypes;
|
||||
|
||||
export default Paginator;
|
||||
|
||||
Reference in New Issue
Block a user