Skip to content

Commit

Permalink
Fix bug with Pager service when there are no items. (#237)
Browse files Browse the repository at this point in the history
* Fix bug with Pager service when there are no items.
  • Loading branch information
cjcenizal authored Dec 21, 2017
1 parent bb7bddb commit ce53c77
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- Updated `euiPopover` to propogate `panelPaddingSize` padding values to content only (title does inherit horizontal values) via CSS. [(#229)](https://github.com/elastic/eui/pull/229)

**Bug fixes**

- Fix bug in `Pager` service which occurred when there were no items. [(#237)[https://github.com/elastic/eui/pull/237]]

# [`0.0.9`](https://github.com/elastic/eui/tree/v0.0.9)

**Breaking changes**
Expand Down
8 changes: 8 additions & 0 deletions src/services/paging/pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export class Pager {
}

update = () => {
if (this.totalItems <= 0) {
this.totalPages = 0;
this.currentPageIndex = 0;
this.firstItemIndex = 0;
this.lastItemIndex = 0;
return;
}

this.totalPages = Math.ceil(this.totalItems / this.itemsPerPage);

// Ensure the current page falls within our range of total pages.
Expand Down
14 changes: 14 additions & 0 deletions src/services/paging/pager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,18 @@ describe('Pager', () => {
});
});
});

describe('behavior', () => {
describe('when there are no items', () => {
test('getFirstItemIndex defaults to 0', () => {
const pager = new Pager(0, 20);
expect(pager.getFirstItemIndex()).toBe(0);
});

test('getLastItemIndex defaults to 0', () => {
const pager = new Pager(0, 20);
expect(pager.getLastItemIndex()).toBe(0);
});
});
});
});

0 comments on commit ce53c77

Please sign in to comment.