Commit 86c794ea authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Simon Knox

Faster loading of issue lists

Reduce page size to 10 when loading issues on GraphQL boards
parent 4b489b16
<script> <script>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon, GlIntersectionObserver } from '@gitlab/ui';
import Draggable from 'vuedraggable'; import Draggable from 'vuedraggable';
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { sortableStart, sortableEnd } from '~/boards/mixins/sortable_default_options'; import { sortableStart, sortableEnd } from '~/boards/mixins/sortable_default_options';
...@@ -21,6 +21,7 @@ export default { ...@@ -21,6 +21,7 @@ export default {
BoardCard, BoardCard,
BoardNewIssue, BoardNewIssue,
GlLoadingIcon, GlLoadingIcon,
GlIntersectionObserver,
}, },
props: { props: {
disabled: { disabled: {
...@@ -65,7 +66,7 @@ export default { ...@@ -65,7 +66,7 @@ export default {
return this.list.maxIssueCount > 0 && this.listItemsCount > this.list.maxIssueCount; return this.list.maxIssueCount > 0 && this.listItemsCount > this.list.maxIssueCount;
}, },
hasNextPage() { hasNextPage() {
return this.pageInfoByListId[this.list.id].hasNextPage; return this.pageInfoByListId[this.list.id]?.hasNextPage;
}, },
loading() { loading() {
return this.listsFlags[this.list.id]?.isLoading; return this.listsFlags[this.list.id]?.isLoading;
...@@ -115,14 +116,9 @@ export default { ...@@ -115,14 +116,9 @@ export default {
eventHub.$on(`toggle-issue-form-${this.list.id}`, this.toggleForm); eventHub.$on(`toggle-issue-form-${this.list.id}`, this.toggleForm);
eventHub.$on(`scroll-board-list-${this.list.id}`, this.scrollToTop); eventHub.$on(`scroll-board-list-${this.list.id}`, this.scrollToTop);
}, },
mounted() {
// Scroll event on list to load more
this.listRef.addEventListener('scroll', this.onScroll);
},
beforeDestroy() { beforeDestroy() {
eventHub.$off(`toggle-issue-form-${this.list.id}`, this.toggleForm); eventHub.$off(`toggle-issue-form-${this.list.id}`, this.toggleForm);
eventHub.$off(`scroll-board-list-${this.list.id}`, this.scrollToTop); eventHub.$off(`scroll-board-list-${this.list.id}`, this.scrollToTop);
this.listRef.removeEventListener('scroll', this.onScroll);
}, },
methods: { methods: {
...mapActions(['fetchItemsForList', 'moveItem']), ...mapActions(['fetchItemsForList', 'moveItem']),
...@@ -144,16 +140,10 @@ export default { ...@@ -144,16 +140,10 @@ export default {
toggleForm() { toggleForm() {
this.showIssueForm = !this.showIssueForm; this.showIssueForm = !this.showIssueForm;
}, },
onScroll() { onReachingListBottom() {
window.requestAnimationFrame(() => { if (!this.loadingMore && this.hasNextPage) {
if ( this.loadNextPage();
!this.loadingMore && }
this.scrollTop() > this.scrollHeight() - this.scrollOffset &&
this.hasNextPage
) {
this.loadNextPage();
}
});
}, },
handleDragOnStart() { handleDragOnStart() {
sortableStart(); sortableStart();
...@@ -249,7 +239,9 @@ export default { ...@@ -249,7 +239,9 @@ export default {
data-testid="count-loading-icon" data-testid="count-loading-icon"
/> />
<span v-if="showingAllItems">{{ showingAllItemsText }}</span> <span v-if="showingAllItems">{{ showingAllItemsText }}</span>
<span v-else>{{ paginatedIssueText }}</span> <gl-intersection-observer v-else @update="onReachingListBottom">
<span>{{ paginatedIssueText }}</span>
</gl-intersection-observer>
</li> </li>
</component> </component>
</div> </div>
......
...@@ -298,7 +298,7 @@ export default { ...@@ -298,7 +298,7 @@ export default {
filters: filterParams, filters: filterParams,
isGroup: boardType === BoardType.group, isGroup: boardType === BoardType.group,
isProject: boardType === BoardType.project, isProject: boardType === BoardType.project,
first: 20, first: 10,
after: fetchNext ? state.pageInfoByListId[listId].endCursor : undefined, after: fetchNext ? state.pageInfoByListId[listId].endCursor : undefined,
}; };
......
...@@ -284,7 +284,7 @@ export default { ...@@ -284,7 +284,7 @@ export default {
? { ...filterParams, epicWildcardId: EpicFilterType.none.toUpperCase() } ? { ...filterParams, epicWildcardId: EpicFilterType.none.toUpperCase() }
: { ...filterParams, epicId }, : { ...filterParams, epicId },
after: fetchNext ? state.pageInfoByListId[listId].endCursor : undefined, after: fetchNext ? state.pageInfoByListId[listId].endCursor : undefined,
first: forSwimlanes ? undefined : 20, first: forSwimlanes ? undefined : 10,
}; };
if (getters.isEpicBoard) { if (getters.isEpicBoard) {
......
...@@ -181,12 +181,6 @@ describe('Board list component', () => { ...@@ -181,12 +181,6 @@ describe('Board list component', () => {
}); });
}); });
it('loads more issues after scrolling', () => {
wrapper.vm.listRef.dispatchEvent(new Event('scroll'));
expect(actions.fetchItemsForList).toHaveBeenCalled();
});
it('does not load issues if already loading', () => { it('does not load issues if already loading', () => {
wrapper = createComponent({ wrapper = createComponent({
state: { listsFlags: { 'gid://gitlab/List/1': { isLoadingMore: true } } }, state: { listsFlags: { 'gid://gitlab/List/1': { isLoadingMore: 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