Commit 5ceb3e6a authored by jerasmus's avatar jerasmus

Move constants into constants.js

Moved the repository constants into constants.js
parent 4dbcd621
...@@ -2,16 +2,13 @@ ...@@ -2,16 +2,13 @@
import filesQuery from 'shared_queries/repository/files.query.graphql'; import filesQuery from 'shared_queries/repository/files.query.graphql';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { __ } from '../../locale'; import { __ } from '../../locale';
import { TREE_PAGE_SIZE, TREE_INITIAL_FETCH_COUNT } from '../constants';
import getRefMixin from '../mixins/get_ref'; import getRefMixin from '../mixins/get_ref';
import projectPathQuery from '../queries/project_path.query.graphql'; import projectPathQuery from '../queries/project_path.query.graphql';
import { readmeFile } from '../utils/readme'; import { readmeFile } from '../utils/readme';
import FilePreview from './preview/index.vue'; import FilePreview from './preview/index.vue';
import FileTable from './table/index.vue'; import FileTable from './table/index.vue';
const LIMIT = 1000;
const PAGE_SIZE = 100;
export const INITIAL_FETCH_COUNT = LIMIT / PAGE_SIZE;
export default { export default {
components: { components: {
FileTable, FileTable,
...@@ -47,7 +44,7 @@ export default { ...@@ -47,7 +44,7 @@ export default {
isLoadingFiles: false, isLoadingFiles: false,
isOverLimit: false, isOverLimit: false,
clickedShowMore: false, clickedShowMore: false,
pageSize: PAGE_SIZE, pageSize: TREE_PAGE_SIZE,
fetchCounter: 0, fetchCounter: 0,
}; };
}, },
...@@ -56,7 +53,7 @@ export default { ...@@ -56,7 +53,7 @@ export default {
return readmeFile(this.entries.blobs); return readmeFile(this.entries.blobs);
}, },
hasShowMore() { hasShowMore() {
return !this.clickedShowMore && this.fetchCounter === INITIAL_FETCH_COUNT; return !this.clickedShowMore && this.fetchCounter === TREE_INITIAL_FETCH_COUNT;
}, },
}, },
...@@ -107,7 +104,7 @@ export default { ...@@ -107,7 +104,7 @@ export default {
if (pageInfo?.hasNextPage) { if (pageInfo?.hasNextPage) {
this.nextPageCursor = pageInfo.endCursor; this.nextPageCursor = pageInfo.endCursor;
this.fetchCounter += 1; this.fetchCounter += 1;
if (this.fetchCounter < INITIAL_FETCH_COUNT || this.clickedShowMore) { if (this.fetchCounter < TREE_INITIAL_FETCH_COUNT || this.clickedShowMore) {
this.fetchFiles(); this.fetchFiles();
this.clickedShowMore = false; this.clickedShowMore = false;
} }
......
const TREE_PAGE_LIMIT = 1000; // the maximum amount of items per page
export const TREE_PAGE_SIZE = 100; // the amount of items to be fetched per (batch) request
export const TREE_INITIAL_FETCH_COUNT = TREE_PAGE_LIMIT / TREE_PAGE_SIZE; // the amount of (batch) requests to make
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import FilePreview from '~/repository/components/preview/index.vue'; import FilePreview from '~/repository/components/preview/index.vue';
import FileTable from '~/repository/components/table/index.vue'; import FileTable from '~/repository/components/table/index.vue';
import TreeContent, { INITIAL_FETCH_COUNT } from '~/repository/components/tree_content.vue'; import TreeContent from '~/repository/components/tree_content.vue';
import { TREE_INITIAL_FETCH_COUNT } from '~/repository/constants';
let vm; let vm;
let $apollo; let $apollo;
...@@ -128,7 +129,7 @@ describe('Repository table component', () => { ...@@ -128,7 +129,7 @@ describe('Repository table component', () => {
it('has limit of 1000 files on initial load', () => { it('has limit of 1000 files on initial load', () => {
factory('/'); factory('/');
expect(INITIAL_FETCH_COUNT * vm.vm.pageSize).toBe(1000); expect(TREE_INITIAL_FETCH_COUNT * vm.vm.pageSize).toBe(1000);
}); });
}); });
}); });
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