Commit f34c24a7 authored by Jose Vargas's avatar Jose Vargas Committed by Jose Ivan Vargas

Refactor showPagination function

parent cecccc88
export const GRAPHQL_PAGE_SIZE = 10; export const GRAPHQL_PAGE_SIZE = 30;
export const initialPaginationState = {
currentPage: 1,
prevPageCursor: '',
nextPageCursor: '',
first: GRAPHQL_PAGE_SIZE,
last: null,
};
<script> <script>
import { GlAlert, GlPagination, GlSkeletonLoader } from '@gitlab/ui'; import { GlAlert, GlPagination, GlSkeletonLoader } from '@gitlab/ui';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { GRAPHQL_PAGE_SIZE } from './constants'; import { GRAPHQL_PAGE_SIZE, initialPaginationState } from './constants';
import GetJobs from './graphql/queries/get_jobs.query.graphql'; import GetJobs from './graphql/queries/get_jobs.query.graphql';
import JobsTable from './jobs_table.vue'; import JobsTable from './jobs_table.vue';
import JobsTableEmptyState from './jobs_table_empty_state.vue'; import JobsTableEmptyState from './jobs_table_empty_state.vue';
import JobsTableTabs from './jobs_table_tabs.vue'; import JobsTableTabs from './jobs_table_tabs.vue';
const initialPaginationState = {
currentPage: 1,
prevPageCursor: '',
nextPageCursor: '',
first: GRAPHQL_PAGE_SIZE,
last: null,
};
export default { export default {
i18n: { i18n: {
errorMsg: __('There was an error fetching the jobs for your project.'), errorMsg: __('There was an error fetching the jobs for your project.'),
...@@ -79,7 +71,7 @@ export default { ...@@ -79,7 +71,7 @@ export default {
return this.jobs.pageInfo?.hasNextPage ? this.pagination.currentPage + 1 : null; return this.jobs.pageInfo?.hasNextPage ? this.pagination.currentPage + 1 : null;
}, },
showPaginationControls() { showPaginationControls() {
return Boolean(this.prevPage || this.nextPage); return Boolean(this.prevPage || this.nextPage) && !this.$apollo.loading;
}, },
}, },
methods: { methods: {
...@@ -99,8 +91,8 @@ export default { ...@@ -99,8 +91,8 @@ export default {
}; };
} else { } else {
this.pagination = { this.pagination = {
lastPageSize: GRAPHQL_PAGE_SIZE, last: GRAPHQL_PAGE_SIZE,
firstPageSize: null, first: null,
prevPageCursor: startCursor, prevPageCursor: startCursor,
currentPage: page, currentPage: page,
}; };
...@@ -147,7 +139,6 @@ export default { ...@@ -147,7 +139,6 @@ export default {
<gl-pagination <gl-pagination
v-if="showPaginationControls" v-if="showPaginationControls"
:disabled="$apollo.loading"
:value="pagination.currentPage" :value="pagination.currentPage"
:prev-page="prevPage" :prev-page="prevPage"
:next-page="nextPage" :next-page="nextPage"
......
...@@ -104,7 +104,6 @@ describe('Job table app', () => { ...@@ -104,7 +104,6 @@ describe('Job table app', () => {
}, },
jobs: { jobs: {
pageInfo: { pageInfo: {
hasNextPage: false,
hasPreviousPage: true, hasPreviousPage: true,
startCursor: 'abc', startCursor: 'abc',
endCursor: 'bcd', endCursor: 'bcd',
...@@ -113,12 +112,24 @@ describe('Job table app', () => { ...@@ -113,12 +112,24 @@ describe('Job table app', () => {
}, },
}); });
await wrapper.vm.$nextTick();
wrapper.setData({
jobs: {
pageInfo: {
hasNextPage: false,
},
},
});
await wrapper.vm.$nextTick();
expect(findPrevious().exists()).toBe(true); expect(findPrevious().exists()).toBe(true);
expect(findNext().exists()).toBe(true); expect(findNext().exists()).toBe(true);
expect(findNext().classes('disabled')).toBe(true); expect(findNext().classes('disabled')).toBe(true);
}); });
it('should disable the preivous page button on the first page', async () => { it('should disable the previous page button on the first page', async () => {
createComponent({ createComponent({
handler: successHandler, handler: successHandler,
mountFn: mount, mountFn: mount,
...@@ -137,6 +148,8 @@ describe('Job table app', () => { ...@@ -137,6 +148,8 @@ describe('Job table app', () => {
}, },
}); });
await wrapper.vm.$nextTick();
expect(findPrevious().exists()).toBe(true); expect(findPrevious().exists()).toBe(true);
expect(findPrevious().classes('disabled')).toBe(true); expect(findPrevious().classes('disabled')).toBe(true);
expect(findNext().exists()).toBe(true); expect(findNext().exists()).toBe(true);
......
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