Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with Pager service when there are no items. #237

Merged
merged 2 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});
});