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

139 lines
4 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
2021-03-11 19:13:27 +05:30
import { GlAlert } from '@gitlab/ui';
import { sortBy } from 'lodash';
2021-02-22 17:27:13 +05:30
import Draggable from 'vuedraggable';
2020-11-24 15:15:51 +05:30
import { mapState, mapGetters, mapActions } from 'vuex';
2021-04-17 20:07:23 +05:30
import BoardAddNewColumn from 'ee_else_ce/boards/components/board_add_new_column.vue';
2021-03-11 19:13:27 +05:30
import defaultSortableConfig from '~/sortable/sortable_config';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import BoardColumn from './board_column.vue';
import BoardColumnDeprecated from './board_column_deprecated.vue';
2020-06-23 00:09:42 +05:30
export default {
components: {
2021-04-17 20:07:23 +05:30
BoardAddNewColumn,
BoardColumn:
gon.features?.graphqlBoardLists || gon.features?.epicBoards
? BoardColumn
: BoardColumnDeprecated,
2021-04-29 21:17:54 +05:30
BoardContentSidebar: () => import('~/boards/components/board_content_sidebar.vue'),
EpicBoardContentSidebar: () =>
import('ee_component/boards/components/epic_board_content_sidebar.vue'),
2020-11-24 15:15:51 +05:30
EpicsSwimlanes: () => import('ee_component/boards/components/epics_swimlanes.vue'),
GlAlert,
2020-06-23 00:09:42 +05:30
},
mixins: [glFeatureFlagMixin()],
2021-04-29 21:17:54 +05:30
inject: ['canAdminList'],
2020-06-23 00:09:42 +05:30
props: {
lists: {
type: Array,
2021-03-08 18:12:59 +05:30
required: false,
default: () => [],
2020-06-23 00:09:42 +05:30
},
disabled: {
type: Boolean,
required: true,
},
},
computed: {
2021-04-17 20:07:23 +05:30
...mapState(['boardLists', 'error', 'addColumnForm']),
...mapGetters(['isSwimlanesOn', 'isEpicBoard']),
addColumnFormVisible() {
return this.addColumnForm?.visible;
},
2020-11-24 15:15:51 +05:30
boardListsToUse() {
2021-04-17 20:07:23 +05:30
return this.glFeatures.graphqlBoardLists || this.isSwimlanesOn || this.isEpicBoard
2021-02-22 17:27:13 +05:30
? sortBy([...Object.values(this.boardLists)], 'position')
: this.lists;
},
canDragColumns() {
2021-06-08 01:23:25 +05:30
return (this.isEpicBoard || this.glFeatures.graphqlBoardLists) && this.canAdminList;
2021-02-22 17:27:13 +05:30
},
boardColumnWrapper() {
return this.canDragColumns ? Draggable : 'div';
},
draggableOptions() {
const options = {
...defaultSortableConfig,
disabled: this.disabled,
draggable: '.is-draggable',
fallbackOnBody: false,
group: 'boards-list',
tag: 'div',
2021-03-08 18:12:59 +05:30
value: this.boardListsToUse,
2021-02-22 17:27:13 +05:30
};
return this.canDragColumns ? options : {};
2020-06-23 00:09:42 +05:30
},
2020-11-24 15:15:51 +05:30
},
methods: {
2021-04-29 21:17:54 +05:30
...mapActions(['moveList', 'unsetError']),
2021-04-17 20:07:23 +05:30
afterFormEnters() {
const el = this.canDragColumns ? this.$refs.list.$el : this.$refs.list;
el.scrollTo({ left: el.scrollWidth, behavior: 'smooth' });
},
2021-02-22 17:27:13 +05:30
handleDragOnEnd(params) {
const { item, newIndex, oldIndex, to } = params;
const listId = item.dataset.id;
const replacedListId = to.children[newIndex].dataset.id;
this.moveList({
listId,
replacedListId,
newIndex,
adjustmentValue: newIndex < oldIndex ? 1 : -1,
});
},
2020-11-24 15:15:51 +05:30
},
2020-06-23 00:09:42 +05:30
};
</script>
<template>
2021-04-29 21:17:54 +05:30
<div v-cloak data-qa-selector="boards_list">
<gl-alert v-if="error" variant="danger" :dismissible="true" @dismiss="unsetError">
2020-11-24 15:15:51 +05:30
{{ error }}
</gl-alert>
2021-02-22 17:27:13 +05:30
<component
:is="boardColumnWrapper"
2020-06-23 00:09:42 +05:30
v-if="!isSwimlanesOn"
2021-02-22 17:27:13 +05:30
ref="list"
v-bind="draggableOptions"
2020-07-28 23:09:34 +05:30
class="boards-list gl-w-full gl-py-5 gl-px-3 gl-white-space-nowrap"
2021-02-22 17:27:13 +05:30
@end="handleDragOnEnd"
2020-06-23 00:09:42 +05:30
>
<board-column
2021-04-17 20:07:23 +05:30
v-for="(list, index) in boardListsToUse"
:key="index"
2020-06-23 00:09:42 +05:30
ref="board"
:list="list"
:disabled="disabled"
/>
2021-04-17 20:07:23 +05:30
<transition name="slide" @after-enter="afterFormEnters">
<board-add-new-column v-if="addColumnFormVisible" />
</transition>
2021-02-22 17:27:13 +05:30
</component>
2020-11-24 15:15:51 +05:30
2021-03-08 18:12:59 +05:30
<epics-swimlanes
2021-04-29 21:17:54 +05:30
v-else-if="boardListsToUse.length"
2021-03-08 18:12:59 +05:30
ref="swimlanes"
:lists="boardListsToUse"
:can-admin-list="canAdminList"
:disabled="disabled"
/>
2021-04-29 21:17:54 +05:30
<board-content-sidebar
v-if="isSwimlanesOn || glFeatures.graphqlBoardLists"
class="boards-sidebar"
data-testid="issue-boards-sidebar"
/>
<epic-board-content-sidebar
v-else-if="isEpicBoard"
class="boards-sidebar"
data-testid="epic-boards-sidebar"
/>
2020-06-23 00:09:42 +05:30
</div>
</template>