debian-mirror-gitlab/app/assets/javascripts/boards/components/boards_selector.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

342 lines
9.4 KiB
Vue
Raw Normal View History

2019-09-30 21:07:59 +05:30
<script>
import {
GlLoadingIcon,
GlSearchBoxByType,
2021-02-22 17:27:13 +05:30
GlDropdown,
GlDropdownDivider,
GlDropdownSectionHeader,
GlDropdownItem,
GlModalDirective,
2019-09-30 21:07:59 +05:30
} from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { throttle } from 'lodash';
2021-12-11 22:18:48 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2021-04-17 20:07:23 +05:30
import BoardForm from 'ee_else_ce/boards/components/board_form.vue';
2019-09-30 21:07:59 +05:30
2021-03-11 19:13:27 +05:30
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
2022-07-23 23:45:48 +05:30
import { isMetaKey } from '~/lib/utils/common_utils';
import { updateHistory } from '~/lib/utils/url_utility';
2021-12-11 22:18:48 +05:30
import { s__ } from '~/locale';
2020-04-08 14:13:33 +05:30
2021-03-11 19:13:27 +05:30
import eventHub from '../eventhub';
2021-12-11 22:18:48 +05:30
import groupBoardsQuery from '../graphql/group_boards.query.graphql';
import projectBoardsQuery from '../graphql/project_boards.query.graphql';
2022-04-04 11:22:00 +05:30
import groupRecentBoardsQuery from '../graphql/group_recent_boards.query.graphql';
import projectRecentBoardsQuery from '../graphql/project_recent_boards.query.graphql';
2022-07-23 23:45:48 +05:30
import { fullBoardId } from '../boards_util';
2020-04-08 14:13:33 +05:30
2019-09-30 21:07:59 +05:30
const MIN_BOARDS_TO_VIEW_RECENT = 10;
export default {
name: 'BoardsSelector',
components: {
BoardForm,
GlLoadingIcon,
GlSearchBoxByType,
2021-02-22 17:27:13 +05:30
GlDropdown,
GlDropdownDivider,
GlDropdownSectionHeader,
GlDropdownItem,
},
directives: {
GlModalDirective,
2019-09-30 21:07:59 +05:30
},
2022-06-21 17:19:12 +05:30
inject: [
'boardBaseUrl',
'fullPath',
'canAdminBoard',
'multipleIssueBoardsAvailable',
'hasMissingBoards',
'scopedIssueBoardFeatureEnabled',
'weights',
],
2019-09-30 21:07:59 +05:30
props: {
throttleDuration: {
type: Number,
default: 200,
2020-04-22 19:07:51 +05:30
required: false,
2019-09-30 21:07:59 +05:30
},
},
data() {
return {
hasScrollFade: false,
2020-04-08 14:13:33 +05:30
loadingBoards: 0,
loadingRecentBoards: false,
2019-09-30 21:07:59 +05:30
scrollFadeInitialized: false,
boards: [],
recentBoards: [],
throttledSetScrollFade: throttle(this.setScrollFade, this.throttleDuration),
contentClientHeight: 0,
maxPosition: 0,
filterTerm: '',
2021-03-11 19:13:27 +05:30
currentPage: '',
2019-09-30 21:07:59 +05:30
};
},
2022-07-23 23:45:48 +05:30
2019-09-30 21:07:59 +05:30
computed: {
2022-07-23 23:45:48 +05:30
...mapState(['boardType', 'board', 'isBoardLoading']),
2021-12-11 22:18:48 +05:30
...mapGetters(['isGroupBoard', 'isProjectBoard']),
2020-04-08 14:13:33 +05:30
parentType() {
2021-04-17 20:07:23 +05:30
return this.boardType;
2020-04-08 14:13:33 +05:30
},
loading() {
2021-02-22 17:27:13 +05:30
return this.loadingRecentBoards || Boolean(this.loadingBoards);
2020-04-08 14:13:33 +05:30
},
2019-09-30 21:07:59 +05:30
filteredBoards() {
2021-03-08 18:12:59 +05:30
return this.boards.filter((board) =>
2019-09-30 21:07:59 +05:30
board.name.toLowerCase().includes(this.filterTerm.toLowerCase()),
);
},
2021-04-17 20:07:23 +05:30
showCreate() {
return this.multipleIssueBoardsAvailable;
},
2019-09-30 21:07:59 +05:30
showDelete() {
return this.boards.length > 1;
},
scrollFadeClass() {
return {
'fade-out': !this.hasScrollFade,
};
},
showRecentSection() {
return (
this.recentBoards.length &&
this.boards.length > MIN_BOARDS_TO_VIEW_RECENT &&
!this.filterTerm.length
);
},
},
watch: {
filteredBoards() {
this.scrollFadeInitialized = false;
this.$nextTick(this.setScrollFade);
},
2022-04-04 11:22:00 +05:30
recentBoards() {
this.scrollFadeInitialized = false;
this.$nextTick(this.setScrollFade);
},
2022-07-23 23:45:48 +05:30
board(newBoard) {
document.title = newBoard.name;
},
2019-09-30 21:07:59 +05:30
},
created() {
2021-03-11 19:13:27 +05:30
eventHub.$on('showBoardModal', this.showPage);
},
beforeDestroy() {
eventHub.$off('showBoardModal', this.showPage);
2019-09-30 21:07:59 +05:30
},
methods: {
2022-07-23 23:45:48 +05:30
...mapActions(['setError', 'fetchBoard', 'unsetActiveId']),
2019-09-30 21:07:59 +05:30
showPage(page) {
2021-03-11 19:13:27 +05:30
this.currentPage = page;
},
cancel() {
this.showPage('');
2019-09-30 21:07:59 +05:30
},
2022-04-04 11:22:00 +05:30
boardUpdate(data, boardType) {
2021-04-17 20:07:23 +05:30
if (!data?.[this.parentType]) {
return [];
}
2022-04-04 11:22:00 +05:30
return data[this.parentType][boardType].edges.map(({ node }) => ({
2021-04-17 20:07:23 +05:30
id: getIdFromGraphQLId(node.id),
name: node.name,
}));
},
boardQuery() {
2021-12-11 22:18:48 +05:30
return this.isGroupBoard ? groupBoardsQuery : projectBoardsQuery;
2021-04-17 20:07:23 +05:30
},
2022-04-04 11:22:00 +05:30
recentBoardsQuery() {
return this.isGroupBoard ? groupRecentBoardsQuery : projectRecentBoardsQuery;
},
2019-09-30 21:07:59 +05:30
loadBoards(toggleDropdown = true) {
if (toggleDropdown && this.boards.length > 0) {
return;
}
2020-04-08 14:13:33 +05:30
this.$apollo.addSmartQuery('boards', {
variables() {
2021-03-11 19:13:27 +05:30
return { fullPath: this.fullPath };
2020-04-08 14:13:33 +05:30
},
2021-04-17 20:07:23 +05:30
query: this.boardQuery,
2020-04-08 14:13:33 +05:30
loadingKey: 'loadingBoards',
2022-04-04 11:22:00 +05:30
update: (data) => this.boardUpdate(data, 'boards'),
2020-04-08 14:13:33 +05:30
});
2019-09-30 21:07:59 +05:30
2021-04-17 20:07:23 +05:30
this.loadRecentBoards();
},
loadRecentBoards() {
2022-04-04 11:22:00 +05:30
this.$apollo.addSmartQuery('recentBoards', {
variables() {
return { fullPath: this.fullPath };
},
query: this.recentBoardsQuery,
loadingKey: 'loadingRecentBoards',
update: (data) => this.boardUpdate(data, 'recentIssueBoards'),
});
2019-09-30 21:07:59 +05:30
},
isScrolledUp() {
const { content } = this.$refs;
2020-04-08 14:13:33 +05:30
if (!content) {
return false;
}
2019-09-30 21:07:59 +05:30
const currentPosition = this.contentClientHeight + content.scrollTop;
2020-04-08 14:13:33 +05:30
return currentPosition < this.maxPosition;
2019-09-30 21:07:59 +05:30
},
initScrollFade() {
const { content } = this.$refs;
2020-04-08 14:13:33 +05:30
if (!content) {
return;
}
this.scrollFadeInitialized = true;
2019-09-30 21:07:59 +05:30
this.contentClientHeight = content.clientHeight;
this.maxPosition = content.scrollHeight;
},
setScrollFade() {
if (!this.scrollFadeInitialized) this.initScrollFade();
this.hasScrollFade = this.isScrolledUp();
},
2022-07-23 23:45:48 +05:30
fetchCurrentBoard(boardId) {
this.fetchBoard({
fullPath: this.fullPath,
fullBoardId: fullBoardId(boardId),
boardType: this.boardType,
});
},
async switchBoard(boardId, e) {
if (isMetaKey(e)) {
window.open(`${this.boardBaseUrl}/${boardId}`, '_blank');
} else {
this.unsetActiveId();
this.fetchCurrentBoard(boardId);
updateHistory({ url: `${this.boardBaseUrl}/${boardId}` });
}
},
2019-09-30 21:07:59 +05:30
},
2021-12-11 22:18:48 +05:30
i18n: {
errorFetchingBoard: s__('Board|An error occurred while fetching the board, please try again.'),
},
2019-09-30 21:07:59 +05:30
};
</script>
<template>
2022-06-21 17:19:12 +05:30
<div class="boards-switcher gl-mr-3" data-testid="boards-selector">
<span class="boards-selector-wrapper">
2021-02-22 17:27:13 +05:30
<gl-dropdown
2022-06-21 17:19:12 +05:30
data-testid="boards-dropdown"
2019-12-04 20:38:33 +05:30
data-qa-selector="boards_dropdown"
2022-06-21 17:19:12 +05:30
toggle-class="dropdown-menu-toggle"
2019-09-30 21:07:59 +05:30
menu-class="flex-column dropdown-extended-height"
2021-12-11 22:18:48 +05:30
:loading="isBoardLoading"
2019-09-30 21:07:59 +05:30
:text="board.name"
@show="loadBoards"
>
2021-02-22 17:27:13 +05:30
<p class="gl-new-dropdown-header-top" @mousedown.prevent>
{{ s__('IssueBoards|Switch board') }}
</p>
<gl-search-box-by-type ref="searchBox" v-model="filterTerm" class="m-2" />
2019-09-30 21:07:59 +05:30
<div
v-if="!loading"
ref="content"
2019-12-04 20:38:33 +05:30
data-qa-selector="boards_dropdown_content"
2019-09-30 21:07:59 +05:30
class="dropdown-content flex-fill"
@scroll.passive="throttledSetScrollFade"
>
2021-02-22 17:27:13 +05:30
<gl-dropdown-item
2019-09-30 21:07:59 +05:30
v-show="filteredBoards.length === 0"
2021-01-29 00:20:46 +05:30
class="gl-pointer-events-none text-secondary"
2019-09-30 21:07:59 +05:30
>
{{ s__('IssueBoards|No matching boards found') }}
2021-02-22 17:27:13 +05:30
</gl-dropdown-item>
2019-09-30 21:07:59 +05:30
2021-02-22 17:27:13 +05:30
<gl-dropdown-section-header v-if="showRecentSection">
2019-09-30 21:07:59 +05:30
{{ __('Recent') }}
2021-02-22 17:27:13 +05:30
</gl-dropdown-section-header>
2019-09-30 21:07:59 +05:30
<template v-if="showRecentSection">
2021-02-22 17:27:13 +05:30
<gl-dropdown-item
2019-09-30 21:07:59 +05:30
v-for="recentBoard in recentBoards"
:key="`recent-${recentBoard.id}`"
2022-06-21 17:19:12 +05:30
data-testid="dropdown-item"
2022-07-23 23:45:48 +05:30
@click.prevent="switchBoard(recentBoard.id, $event)"
2019-09-30 21:07:59 +05:30
>
{{ recentBoard.name }}
2021-02-22 17:27:13 +05:30
</gl-dropdown-item>
2019-09-30 21:07:59 +05:30
</template>
2021-02-22 17:27:13 +05:30
<gl-dropdown-divider v-if="showRecentSection" />
2019-09-30 21:07:59 +05:30
2021-02-22 17:27:13 +05:30
<gl-dropdown-section-header v-if="showRecentSection">
2019-09-30 21:07:59 +05:30
{{ __('All') }}
2021-02-22 17:27:13 +05:30
</gl-dropdown-section-header>
2019-09-30 21:07:59 +05:30
2021-02-22 17:27:13 +05:30
<gl-dropdown-item
2019-09-30 21:07:59 +05:30
v-for="otherBoard in filteredBoards"
:key="otherBoard.id"
2022-06-21 17:19:12 +05:30
data-testid="dropdown-item"
2022-07-23 23:45:48 +05:30
@click.prevent="switchBoard(otherBoard.id, $event)"
2019-09-30 21:07:59 +05:30
>
{{ otherBoard.name }}
2021-02-22 17:27:13 +05:30
</gl-dropdown-item>
<gl-dropdown-item v-if="hasMissingBoards" class="no-pointer-events">
2019-09-30 21:07:59 +05:30
{{
2022-05-07 20:08:51 +05:30
s__('IssueBoards|Some of your boards are hidden, add a license to see them again.')
2019-09-30 21:07:59 +05:30
}}
2021-02-22 17:27:13 +05:30
</gl-dropdown-item>
2019-09-30 21:07:59 +05:30
</div>
<div
v-show="filteredBoards.length > 0"
class="dropdown-content-faded-mask"
:class="scrollFadeClass"
></div>
2021-09-30 23:02:18 +05:30
<gl-loading-icon v-if="loading" size="sm" />
2019-09-30 21:07:59 +05:30
<div v-if="canAdminBoard">
2021-02-22 17:27:13 +05:30
<gl-dropdown-divider />
2019-09-30 21:07:59 +05:30
2021-02-22 17:27:13 +05:30
<gl-dropdown-item
2021-04-17 20:07:23 +05:30
v-if="showCreate"
2021-02-22 17:27:13 +05:30
v-gl-modal-directive="'board-config-modal'"
2019-12-21 20:55:43 +05:30
data-qa-selector="create_new_board_button"
2022-01-26 12:08:38 +05:30
data-track-action="click_button"
data-track-label="create_new_board"
data-track-property="dropdown"
2019-12-21 20:55:43 +05:30
@click.prevent="showPage('new')"
>
2019-09-30 21:07:59 +05:30
{{ s__('IssueBoards|Create new board') }}
2021-02-22 17:27:13 +05:30
</gl-dropdown-item>
2019-09-30 21:07:59 +05:30
2021-02-22 17:27:13 +05:30
<gl-dropdown-item
2019-09-30 21:07:59 +05:30
v-if="showDelete"
2021-02-22 17:27:13 +05:30
v-gl-modal-directive="'board-config-modal'"
2022-06-21 17:19:12 +05:30
class="text-danger"
2019-09-30 21:07:59 +05:30
@click.prevent="showPage('delete')"
>
{{ s__('IssueBoards|Delete board') }}
2021-02-22 17:27:13 +05:30
</gl-dropdown-item>
2019-09-30 21:07:59 +05:30
</div>
2021-02-22 17:27:13 +05:30
</gl-dropdown>
2019-09-30 21:07:59 +05:30
<board-form
v-if="currentPage"
:can-admin-board="canAdminBoard"
:scoped-issue-board-feature-enabled="scopedIssueBoardFeatureEnabled"
:weights="weights"
2021-12-11 22:18:48 +05:30
:current-board="board"
2021-03-11 19:13:27 +05:30
:current-page="currentPage"
@cancel="cancel"
2019-09-30 21:07:59 +05:30
/>
</span>
</div>
</template>