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

470 lines
14 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
import {
GlButton,
GlButtonGroup,
GlLabel,
GlTooltip,
GlIcon,
2020-07-28 23:09:34 +05:30
GlSprintf,
2020-06-23 00:09:42 +05:30
GlTooltipDirective,
} from '@gitlab/ui';
2021-04-17 20:07:23 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2021-03-11 19:13:27 +05:30
import { isListDraggable } from '~/boards/boards_util';
2021-04-17 20:07:23 +05:30
import { isScopedLabel, parseBoolean } from '~/lib/utils/common_utils';
2021-03-11 19:13:27 +05:30
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
2021-03-08 18:12:59 +05:30
import { n__, s__, __ } from '~/locale';
2021-01-03 14:25:43 +05:30
import sidebarEventHub from '~/sidebar/event_hub';
2021-09-04 01:27:46 +05:30
import Tracking from '~/tracking';
2021-12-11 22:18:48 +05:30
import { formatDate } from '~/lib/utils/datetime_utility';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
2022-01-26 12:08:38 +05:30
import listQuery from 'ee_else_ce/boards/graphql/board_lists_deferred.query.graphql';
2021-03-11 19:13:27 +05:30
import AccessorUtilities from '../../lib/utils/accessor';
2021-09-30 23:02:18 +05:30
import { inactiveId, LIST, ListType, toggleFormEventPrefix } from '../constants';
2021-03-11 19:13:27 +05:30
import eventHub from '../eventhub';
2021-04-17 20:07:23 +05:30
import ItemCount from './item_count.vue';
2020-06-23 00:09:42 +05:30
export default {
2021-03-08 18:12:59 +05:30
i18n: {
newIssue: __('New issue'),
2021-09-30 23:02:18 +05:30
newEpic: s__('Boards|New epic'),
2021-03-08 18:12:59 +05:30
listSettings: __('List settings'),
expand: s__('Boards|Expand'),
collapse: s__('Boards|Collapse'),
},
2020-06-23 00:09:42 +05:30
components: {
GlButtonGroup,
GlButton,
GlLabel,
GlTooltip,
GlIcon,
2020-07-28 23:09:34 +05:30
GlSprintf,
2021-04-17 20:07:23 +05:30
ItemCount,
2020-06-23 00:09:42 +05:30
},
directives: {
GlTooltip: GlTooltipDirective,
},
2021-12-11 22:18:48 +05:30
mixins: [Tracking.mixin(), glFeatureFlagMixin()],
2021-03-08 18:12:59 +05:30
inject: {
boardId: {
default: '',
},
weightFeatureAvailable: {
default: false,
},
scopedLabelsAvailable: {
default: false,
},
currentUserId: {
default: null,
},
},
2020-06-23 00:09:42 +05:30
props: {
list: {
type: Object,
default: () => ({}),
required: false,
},
disabled: {
type: Boolean,
required: true,
},
isSwimlanesHeader: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
2022-01-26 12:08:38 +05:30
...mapState(['activeId', 'filterParams']),
2021-09-30 23:02:18 +05:30
...mapGetters(['isEpicBoard', 'isSwimlanesOn']),
2020-06-23 00:09:42 +05:30
isLoggedIn() {
2021-03-08 18:12:59 +05:30
return Boolean(this.currentUserId);
2020-06-23 00:09:42 +05:30
},
listType() {
2021-03-08 18:12:59 +05:30
return this.list.listType;
2020-06-23 00:09:42 +05:30
},
listAssignee() {
return this.list?.assignee?.username || '';
},
listTitle() {
2021-03-08 18:12:59 +05:30
return this.list?.label?.description || this.list?.assignee?.name || this.list.title || '';
2020-06-23 00:09:42 +05:30
},
2021-12-11 22:18:48 +05:30
listIterationPeriod() {
const iteration = this.list?.iteration;
return iteration ? this.getIterationPeriod(iteration) : '';
},
isIterationList() {
return this.listType === ListType.iteration;
},
2020-06-23 00:09:42 +05:30
showListHeaderButton() {
2021-02-22 17:27:13 +05:30
return !this.disabled && this.listType !== ListType.closed;
2020-06-23 00:09:42 +05:30
},
2020-07-28 23:09:34 +05:30
showMilestoneListDetails() {
2021-03-11 19:13:27 +05:30
return this.listType === ListType.milestone && this.list.milestone && this.showListDetails;
2020-07-28 23:09:34 +05:30
},
showAssigneeListDetails() {
2021-03-11 19:13:27 +05:30
return this.listType === ListType.assignee && this.showListDetails;
},
showIterationListDetails() {
2021-12-11 22:18:48 +05:30
return this.isIterationList && this.showListDetails;
},
iterationCadencesAvailable() {
return this.isIterationList && this.glFeatures.iterationCadences;
2021-03-11 19:13:27 +05:30
},
showListDetails() {
return !this.list.collapsed || !this.isSwimlanesHeader;
2020-07-28 23:09:34 +05:30
},
2021-09-04 01:27:46 +05:30
showListHeaderActions() {
if (this.isLoggedIn) {
2021-09-30 23:02:18 +05:30
return this.isNewIssueShown || this.isNewEpicShown || this.isSettingsShown;
2021-09-04 01:27:46 +05:30
}
return false;
},
2021-04-17 20:07:23 +05:30
countIcon() {
return 'issues';
},
itemsTooltipLabel() {
2022-01-26 12:08:38 +05:30
return n__(`%d issue`, `%d issues`, this.boardLists?.issuesCount);
2020-06-23 00:09:42 +05:30
},
chevronTooltip() {
2021-03-08 18:12:59 +05:30
return this.list.collapsed ? this.$options.i18n.expand : this.$options.i18n.collapse;
2020-06-23 00:09:42 +05:30
},
chevronIcon() {
2021-03-08 18:12:59 +05:30
return this.list.collapsed ? 'chevron-down' : 'chevron-right';
2020-06-23 00:09:42 +05:30
},
isNewIssueShown() {
2021-04-17 20:07:23 +05:30
return (this.listType === ListType.backlog || this.showListHeaderButton) && !this.isEpicBoard;
2020-06-23 00:09:42 +05:30
},
2021-09-30 23:02:18 +05:30
isNewEpicShown() {
return this.isEpicBoard && this.listType !== ListType.closed;
},
2020-06-23 00:09:42 +05:30
isSettingsShown() {
return (
2021-03-08 18:12:59 +05:30
this.listType !== ListType.backlog && this.showListHeaderButton && !this.list.collapsed
2020-06-23 00:09:42 +05:30
);
},
uniqueKey() {
// eslint-disable-next-line @gitlab/require-i18n-strings
return `boards.${this.boardId}.${this.listType}.${this.list.id}`;
},
2020-07-28 23:09:34 +05:30
collapsedTooltipTitle() {
return this.listTitle || this.listAssignee;
},
2021-03-08 18:12:59 +05:30
headerStyle() {
return { borderTopColor: this.list?.label?.color };
},
userCanDrag() {
return !this.disabled && isListDraggable(this.list);
},
2022-01-26 12:08:38 +05:30
isLoading() {
return this.$apollo.queries.boardList.loading;
},
},
apollo: {
boardList: {
query: listQuery,
variables() {
return {
id: this.list.id,
filters: this.filterParams,
};
},
skip() {
return this.isEpicBoard;
},
},
2020-06-23 00:09:42 +05:30
},
2021-04-17 20:07:23 +05:30
created() {
const localCollapsed = parseBoolean(localStorage.getItem(`${this.uniqueKey}.collapsed`));
if ((!this.isLoggedIn || this.isEpicBoard) && localCollapsed) {
this.toggleListCollapsed({ listId: this.list.id, collapsed: true });
}
},
2020-06-23 00:09:42 +05:30
methods: {
2021-04-17 20:07:23 +05:30
...mapActions(['updateList', 'setActiveId', 'toggleListCollapsed']),
2021-01-03 14:25:43 +05:30
openSidebarSettings() {
if (this.activeId === inactiveId) {
sidebarEventHub.$emit('sidebar.closeAll');
}
this.setActiveId({ id: this.list.id, sidebarType: LIST });
2021-09-04 01:27:46 +05:30
this.track('click_button', { label: 'list_settings' });
2021-01-03 14:25:43 +05:30
},
2020-06-23 00:09:42 +05:30
showScopedLabels(label) {
2021-03-08 18:12:59 +05:30
return this.scopedLabelsAvailable && isScopedLabel(label);
2020-06-23 00:09:42 +05:30
},
showNewIssueForm() {
2021-09-30 23:02:18 +05:30
if (this.isSwimlanesOn) {
eventHub.$emit('open-unassigned-lane');
this.$nextTick(() => {
eventHub.$emit(`${toggleFormEventPrefix.issue}${this.list.id}`);
});
} else {
eventHub.$emit(`${toggleFormEventPrefix.issue}${this.list.id}`);
}
},
showNewEpicForm() {
eventHub.$emit(`${toggleFormEventPrefix.epic}${this.list.id}`);
2020-06-23 00:09:42 +05:30
},
toggleExpanded() {
2021-04-17 20:07:23 +05:30
const collapsed = !this.list.collapsed;
this.toggleListCollapsed({ listId: this.list.id, collapsed });
2020-06-23 00:09:42 +05:30
2021-06-08 01:23:25 +05:30
if (!this.isLoggedIn) {
2020-11-24 15:15:51 +05:30
this.addToLocalStorage();
} else {
this.updateListFunction();
}
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
// When expanding/collapsing, the tooltip on the caret button sometimes stays open.
// Close all tooltips manually to prevent dangling tooltips.
2021-03-11 19:13:27 +05:30
this.$root.$emit(BV_HIDE_TOOLTIP);
2021-09-04 01:27:46 +05:30
this.track('click_toggle_button', {
label: 'toggle_list',
property: collapsed ? 'closed' : 'open',
});
2020-11-24 15:15:51 +05:30
},
addToLocalStorage() {
2021-11-11 11:23:49 +05:30
if (AccessorUtilities.canUseLocalStorage()) {
2021-04-17 20:07:23 +05:30
localStorage.setItem(`${this.uniqueKey}.collapsed`, this.list.collapsed);
2020-11-24 15:15:51 +05:30
}
},
updateListFunction() {
2021-03-08 18:12:59 +05:30
this.updateList({ listId: this.list.id, collapsed: this.list.collapsed });
2020-06-23 00:09:42 +05:30
},
2021-12-11 22:18:48 +05:30
/**
* TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/344619
* This method also exists as a utility function in ee/../iterations/utils.js
* Remove the duplication when the EE code is separated from this compoment.
*/
getIterationPeriod({ startDate, dueDate }) {
const start = formatDate(startDate, 'mmm d, yyyy', true);
const due = formatDate(dueDate, 'mmm d, yyyy', true);
return `${start} - ${due}`;
},
2020-06-23 00:09:42 +05:30
},
};
</script>
<template>
<header
:class="{
'has-border': list.label && list.label.color,
2021-03-08 18:12:59 +05:30
'gl-h-full': list.collapsed,
2020-07-28 23:09:34 +05:30
'board-inner gl-rounded-top-left-base gl-rounded-top-right-base': isSwimlanesHeader,
2020-06-23 00:09:42 +05:30
}"
2021-03-08 18:12:59 +05:30
:style="headerStyle"
2020-06-23 00:09:42 +05:30
class="board-header gl-relative"
data-qa-selector="board_list_header"
data-testid="board-list-header"
>
<h3
:class="{
2022-03-02 08:16:31 +05:30
'gl-cursor-grab': userCanDrag,
2021-03-08 18:12:59 +05:30
'gl-py-3 gl-h-full': list.collapsed && !isSwimlanesHeader,
'gl-border-b-0': list.collapsed || isSwimlanesHeader,
'gl-py-2': list.collapsed && isSwimlanesHeader,
'gl-flex-direction-column': list.collapsed,
2020-06-23 00:09:42 +05:30
}"
2021-01-29 00:20:46 +05:30
class="board-title gl-m-0 gl-display-flex gl-align-items-center gl-font-base gl-px-3 js-board-handle"
2020-06-23 00:09:42 +05:30
>
<gl-button
v-gl-tooltip.hover
:aria-label="chevronTooltip"
:title="chevronTooltip"
:icon="chevronIcon"
2020-07-28 23:09:34 +05:30
class="board-title-caret no-drag gl-cursor-pointer"
2021-02-22 17:27:13 +05:30
category="tertiary"
size="small"
2021-04-17 20:07:23 +05:30
data-testid="board-title-caret"
2020-06-23 00:09:42 +05:30
@click="toggleExpanded"
/>
2021-03-08 18:12:59 +05:30
<!-- EE start -->
2021-01-29 00:20:46 +05:30
<span
v-if="showMilestoneListDetails"
aria-hidden="true"
class="milestone-icon"
:class="{
2021-03-08 18:12:59 +05:30
'gl-mt-3 gl-rotate-90': list.collapsed,
'gl-mr-2': !list.collapsed,
2021-01-29 00:20:46 +05:30
}"
>
2020-06-23 00:09:42 +05:30
<gl-icon name="timer" />
</span>
2021-03-11 19:13:27 +05:30
<span
v-if="showIterationListDetails"
aria-hidden="true"
:class="{
'gl-mt-3 gl-rotate-90': list.collapsed,
'gl-mr-2': !list.collapsed,
}"
>
<gl-icon name="iteration" />
</span>
2020-06-23 00:09:42 +05:30
<a
2020-07-28 23:09:34 +05:30
v-if="showAssigneeListDetails"
2021-03-08 18:12:59 +05:30
:href="list.assignee.webUrl"
2020-06-23 00:09:42 +05:30
class="user-avatar-link js-no-trigger"
2021-01-29 00:20:46 +05:30
:class="{
2021-03-08 18:12:59 +05:30
'gl-mt-3 gl-rotate-90': list.collapsed,
2021-01-29 00:20:46 +05:30
}"
2020-06-23 00:09:42 +05:30
>
<img
v-gl-tooltip.hover.bottom
:title="listAssignee"
:alt="list.assignee.name"
2021-03-08 18:12:59 +05:30
:src="list.assignee.avatarUrl"
2020-06-23 00:09:42 +05:30
class="avatar s20"
height="20"
width="20"
/>
</a>
2021-03-08 18:12:59 +05:30
<!-- EE end -->
2020-07-28 23:09:34 +05:30
<div
class="board-title-text"
2021-01-29 00:20:46 +05:30
:class="{
2021-03-08 18:12:59 +05:30
'gl-display-none': list.collapsed && isSwimlanesHeader,
'gl-flex-grow-0 gl-my-3 gl-mx-0': list.collapsed,
'gl-flex-grow-1': !list.collapsed,
2021-01-29 00:20:46 +05:30
}"
2020-07-28 23:09:34 +05:30
>
2021-03-08 18:12:59 +05:30
<!-- EE start -->
2020-06-23 00:09:42 +05:30
<span
2021-03-08 18:12:59 +05:30
v-if="listType !== 'label'"
2020-06-23 00:09:42 +05:30
v-gl-tooltip.hover
:class="{
2021-03-08 18:12:59 +05:30
'gl-display-block': list.collapsed || listType === 'milestone',
2020-06-23 00:09:42 +05:30
}"
:title="listTitle"
2021-01-29 00:20:46 +05:30
class="board-title-main-text gl-text-truncate"
2020-06-23 00:09:42 +05:30
>
2021-03-08 18:12:59 +05:30
{{ listTitle }}
2021-12-11 22:18:48 +05:30
<span
v-if="iterationCadencesAvailable"
class="gl-display-inline-block gl-text-gray-400"
data-testid="board-list-iteration-period"
>
{{ listIterationPeriod }}</span
>
2020-06-23 00:09:42 +05:30
</span>
2021-01-29 00:20:46 +05:30
<span
2021-03-08 18:12:59 +05:30
v-if="listType === 'assignee'"
v-show="!list.collapsed"
2021-01-29 00:20:46 +05:30
class="gl-ml-2 gl-font-weight-normal gl-text-gray-500"
>
2020-07-28 23:09:34 +05:30
@{{ listAssignee }}
2020-06-23 00:09:42 +05:30
</span>
2021-03-08 18:12:59 +05:30
<!-- EE end -->
2020-06-23 00:09:42 +05:30
<gl-label
2021-03-08 18:12:59 +05:30
v-if="listType === 'label'"
2020-06-23 00:09:42 +05:30
v-gl-tooltip.hover.bottom
:background-color="list.label.color"
:description="list.label.description"
:scoped="showScopedLabels(list.label)"
2021-03-08 18:12:59 +05:30
:size="list.collapsed ? 'sm' : ''"
2020-06-23 00:09:42 +05:30
:title="list.label.title"
/>
</div>
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
<!-- EE start -->
2020-07-28 23:09:34 +05:30
<span
2021-03-08 18:12:59 +05:30
v-if="isSwimlanesHeader && list.collapsed"
2020-07-28 23:09:34 +05:30
ref="collapsedInfo"
aria-hidden="true"
2021-03-08 18:12:59 +05:30
class="board-header-collapsed-info-icon gl-cursor-pointer gl-text-gray-500"
2020-07-28 23:09:34 +05:30
>
<gl-icon name="information" />
</span>
2021-03-08 18:12:59 +05:30
<gl-tooltip v-if="isSwimlanesHeader && list.collapsed" :target="() => $refs.collapsedInfo">
2020-07-28 23:09:34 +05:30
<div class="gl-font-weight-bold gl-pb-2">{{ collapsedTooltipTitle }}</div>
<div v-if="list.maxIssueCount !== 0">
2021-03-08 18:12:59 +05:30
2020-07-28 23:09:34 +05:30
<gl-sprintf :message="__('%{issuesSize} with a limit of %{maxIssueCount}')">
2021-04-17 20:07:23 +05:30
<template #issuesSize>{{ itemsTooltipLabel }}</template>
2020-07-28 23:09:34 +05:30
<template #maxIssueCount>{{ list.maxIssueCount }}</template>
</gl-sprintf>
</div>
2021-04-17 20:07:23 +05:30
<div v-else> {{ itemsTooltipLabel }}</div>
2022-01-26 12:08:38 +05:30
<div v-if="weightFeatureAvailable && !isLoading">
2021-03-08 18:12:59 +05:30
2020-07-28 23:09:34 +05:30
<gl-sprintf :message="__('%{totalWeight} total weight')">
2022-01-26 12:08:38 +05:30
<template #totalWeight>{{ boardList.totalWeight }}</template>
2020-07-28 23:09:34 +05:30
</gl-sprintf>
</div>
</gl-tooltip>
2021-03-08 18:12:59 +05:30
<!-- EE end -->
2020-07-28 23:09:34 +05:30
2020-06-23 00:09:42 +05:30
<div
2021-09-30 23:02:18 +05:30
class="issue-count-badge gl-display-inline-flex gl-pr-2 no-drag gl-text-gray-500"
2021-04-29 21:17:54 +05:30
data-testid="issue-count-badge"
2021-01-29 00:20:46 +05:30
:class="{
2021-03-08 18:12:59 +05:30
'gl-display-none!': list.collapsed && isSwimlanesHeader,
'gl-p-0': list.collapsed,
2021-01-29 00:20:46 +05:30
}"
2020-06-23 00:09:42 +05:30
>
<span class="gl-display-inline-flex">
2021-04-17 20:07:23 +05:30
<gl-tooltip :target="() => $refs.itemCount" :title="itemsTooltipLabel" />
2021-11-18 22:05:49 +05:30
<span ref="itemCount" class="gl-display-inline-flex gl-align-items-center">
2021-04-17 20:07:23 +05:30
<gl-icon class="gl-mr-2" :name="countIcon" />
2022-01-26 12:08:38 +05:30
<item-count
v-if="!isLoading"
:items-size="isEpicBoard ? list.epicsCount : boardList.issuesCount"
:max-issue-count="list.maxIssueCount"
/>
2020-06-23 00:09:42 +05:30
</span>
2021-03-08 18:12:59 +05:30
<!-- EE start -->
2022-01-26 12:08:38 +05:30
<template v-if="weightFeatureAvailable && !isEpicBoard && !isLoading">
2020-06-23 00:09:42 +05:30
<gl-tooltip :target="() => $refs.weightTooltip" :title="weightCountToolTip" />
<span ref="weightTooltip" class="gl-display-inline-flex gl-ml-3">
<gl-icon class="gl-mr-2" name="weight" />
2022-01-26 12:08:38 +05:30
{{ boardList.totalWeight }}
2020-06-23 00:09:42 +05:30
</span>
</template>
2021-03-08 18:12:59 +05:30
<!-- EE end -->
2020-06-23 00:09:42 +05:30
</span>
</div>
2021-09-04 01:27:46 +05:30
<gl-button-group v-if="showListHeaderActions" class="board-list-button-group gl-pl-2">
2020-06-23 00:09:42 +05:30
<gl-button
v-if="isNewIssueShown"
2021-03-08 18:12:59 +05:30
v-show="!list.collapsed"
2020-06-23 00:09:42 +05:30
ref="newIssueBtn"
v-gl-tooltip.hover
2021-03-08 18:12:59 +05:30
:aria-label="$options.i18n.newIssue"
:title="$options.i18n.newIssue"
2021-11-18 22:05:49 +05:30
class="no-drag"
2020-06-23 00:09:42 +05:30
icon="plus"
@click="showNewIssueForm"
/>
2021-09-30 23:02:18 +05:30
<gl-button
v-if="isNewEpicShown"
v-show="!list.collapsed"
v-gl-tooltip.hover
:aria-label="$options.i18n.newEpic"
:title="$options.i18n.newEpic"
class="no-drag"
icon="plus"
@click="showNewEpicForm"
/>
2020-06-23 00:09:42 +05:30
<gl-button
v-if="isSettingsShown"
ref="settingsBtn"
v-gl-tooltip.hover
2021-03-08 18:12:59 +05:30
:aria-label="$options.i18n.listSettings"
2020-06-23 00:09:42 +05:30
class="no-drag js-board-settings-button"
2021-03-08 18:12:59 +05:30
:title="$options.i18n.listSettings"
2020-06-23 00:09:42 +05:30
icon="settings"
@click="openSidebarSettings"
/>
2021-03-08 18:12:59 +05:30
<gl-tooltip :target="() => $refs.settingsBtn">{{ $options.i18n.listSettings }}</gl-tooltip>
2020-06-23 00:09:42 +05:30
</gl-button-group>
</h3>
</header>
</template>