From 82fa8a3d1e8466ef36b58604d20fcc145ea12118 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 10 Mar 2020 09:08:10 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../boards/components/boards_selector.vue | 90 +++++++++++++++------- 1 file changed, 62 insertions(+), 28 deletions(-) (limited to 'app/assets/javascripts/boards/components') diff --git a/app/assets/javascripts/boards/components/boards_selector.vue b/app/assets/javascripts/boards/components/boards_selector.vue index 5e8b80cd959..8b44ccfd276 100644 --- a/app/assets/javascripts/boards/components/boards_selector.vue +++ b/app/assets/javascripts/boards/components/boards_selector.vue @@ -10,6 +10,11 @@ import { } from '@gitlab/ui'; import httpStatusCodes from '~/lib/utils/http_status'; + +import { getIdFromGraphQLId } from '~/graphql_shared/utils'; +import projectQuery from '../queries/project_boards.query.graphql'; +import groupQuery from '../queries/group_boards.query.graphql'; + import boardsStore from '../stores/boards_store'; import BoardForm from './board_form.vue'; @@ -88,8 +93,9 @@ export default { }, data() { return { - loading: true, hasScrollFade: false, + loadingBoards: 0, + loadingRecentBoards: false, scrollFadeInitialized: false, boards: [], recentBoards: [], @@ -102,6 +108,12 @@ export default { }; }, computed: { + parentType() { + return this.groupId ? 'group' : 'project'; + }, + loading() { + return this.loadingRecentBoards && this.loadingBoards; + }, currentPage() { return this.state.currentPage; }, @@ -147,49 +159,71 @@ export default { return; } - const recentBoardsPromise = new Promise((resolve, reject) => - boardsStore - .recentBoards() - .then(resolve) - .catch(err => { - /** - * If user is unauthorized we'd still want to resolve the - * request to display all boards. - */ - if (err.response.status === httpStatusCodes.UNAUTHORIZED) { - resolve({ data: [] }); // recent boards are empty - return; - } - reject(err); - }), - ); + this.$apollo.addSmartQuery('boards', { + variables() { + return { fullPath: this.state.endpoints.fullPath }; + }, + query() { + return this.groupId ? groupQuery : projectQuery; + }, + loadingKey: 'loadingBoards', + update(data) { + if (!data?.[this.parentType]) { + return []; + } + return data[this.parentType].boards.edges.map(({ node }) => ({ + id: getIdFromGraphQLId(node.id), + name: node.name, + })); + }, + }); - Promise.all([boardsStore.allBoards(), recentBoardsPromise]) - .then(([allBoards, recentBoards]) => [allBoards.data, recentBoards.data]) - .then(([allBoardsJson, recentBoardsJson]) => { - this.loading = false; - this.boards = allBoardsJson; - this.recentBoards = recentBoardsJson; + this.loadingRecentBoards = true; + boardsStore + .recentBoards() + .then(res => { + this.recentBoards = res.data; + }) + .catch(err => { + /** + * If user is unauthorized we'd still want to resolve the + * request to display all boards. + */ + if (err?.response?.status === httpStatusCodes.UNAUTHORIZED) { + this.recentBoards = []; // recent boards are empty + return; + } + throw err; }) .then(() => this.$nextTick()) // Wait for boards list in DOM .then(() => { this.setScrollFade(); }) - .catch(() => { - this.loading = false; + .catch(() => {}) + .finally(() => { + this.loadingRecentBoards = false; }); }, isScrolledUp() { const { content } = this.$refs; + + if (!content) { + return false; + } + const currentPosition = this.contentClientHeight + content.scrollTop; - return content && currentPosition < this.maxPosition; + return currentPosition < this.maxPosition; }, initScrollFade() { - this.scrollFadeInitialized = true; - const { content } = this.$refs; + if (!content) { + return; + } + + this.scrollFadeInitialized = true; + this.contentClientHeight = content.clientHeight; this.maxPosition = content.scrollHeight; }, -- cgit v1.2.1