Commit 6d6143a7 authored by Scott Stern's avatar Scott Stern Committed by Nicolò Maria Mezzopera

Pagination when total items is not in the header response

parent ff9bcb08
...@@ -118,6 +118,29 @@ export default { ...@@ -118,6 +118,29 @@ export default {
baseUrl() { baseUrl() {
return window.location.href.replace(/(\?.*)?(#.*)?$/, ''); return window.location.href.replace(/(\?.*)?(#.*)?$/, '');
}, },
paginationNext() {
return this.page + 1;
},
paginationPrev() {
return this.page - 1;
},
paginationProps() {
const paginationProps = { value: this.page };
if (this.totalItems) {
return {
...paginationProps,
perPage: this.itemsPerPage,
totalItems: this.totalItems,
};
}
return {
...paginationProps,
prevPage: this.paginationPrev,
nextPage: this.paginationNext,
};
},
}, },
watch: { watch: {
selection() { selection() {
...@@ -272,11 +295,8 @@ export default { ...@@ -272,11 +295,8 @@ export default {
</ul> </ul>
<div class="mt-3"> <div class="mt-3">
<gl-pagination <gl-pagination
v-if="totalItems" v-bind="paginationProps"
:value="page" class="gl-justify-content-center"
:per-page="itemsPerPage"
:total-items="totalItems"
class="justify-content-center"
@input="onPaginate" @input="onPaginate"
/> />
</div> </div>
......
...@@ -454,6 +454,7 @@ describe('Issuables list component', () => { ...@@ -454,6 +454,7 @@ describe('Issuables list component', () => {
describe('when paginates', () => { describe('when paginates', () => {
const newPage = 3; const newPage = 3;
describe('when total-items is defined in response headers', () => {
beforeEach(() => { beforeEach(() => {
window.history.pushState = jest.fn(); window.history.pushState = jest.fn();
setupApiMock(() => [ setupApiMock(() => [
...@@ -493,4 +494,33 @@ describe('Issuables list component', () => { ...@@ -493,4 +494,33 @@ describe('Issuables list component', () => {
); );
}); });
}); });
describe('when total-items is not defined in the headers', () => {
const page = 2;
const prevPage = page - 1;
const nextPage = page + 1;
beforeEach(() => {
setupApiMock(() => [
200,
MOCK_ISSUES.slice(0, PAGE_SIZE),
{
'x-page': page,
},
]);
factory();
return waitForPromises();
});
it('finds the correct props applied to GlPagination', () => {
expect(wrapper.find(GlPagination).props()).toMatchObject({
nextPage,
prevPage,
value: page,
});
});
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment