Skip to content

Commit

Permalink
fix bug where ellipses would unnecessarily display when third to last…
Browse files Browse the repository at this point in the history
… page is selected (#2015)
  • Loading branch information
mikerodonnell89 committed Feb 20, 2020
1 parent 97dcef8 commit 0fb061a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions libs/core/src/lib/pagination/pagination.service.spec.ts
Expand Up @@ -86,4 +86,16 @@ describe('PaginationService', () => {
expect(pages[1]).toEqual(service.MORE);
expect(pages[5]).toEqual(service.MORE);
});

it('should not have two dots sections if second to last page is currentPage', () => {
const pagination: Pagination = {
totalItems: 150,
itemsPerPage: 2,
currentPage: 73
};
const pages = service.getPages(pagination);
expect(pages[1]).toEqual(service.MORE);
expect(pages[5]).not.toEqual(service.MORE);
expect(pages[5]).toEqual(75);
})
});
2 changes: 1 addition & 1 deletion libs/core/src/lib/pagination/pagination.service.ts
Expand Up @@ -58,7 +58,7 @@ export class PaginationService {
for (let i = pagination.currentPage - buffer; i <= pagination.currentPage + buffer; i++) {
pages.push(i);
}
if (totalPages !== DISPLAY_NUM_PAGES + 1) {
if (totalPages !== DISPLAY_NUM_PAGES + 1 && pagination.currentPage !== totalPages - 2) {
pages.push(this.MORE);
}
pages.push(totalPages);
Expand Down

0 comments on commit 0fb061a

Please sign in to comment.