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

397 lines
12 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-03-11 19:13:27 +05:30
import AccessorUtilities from '../../lib/utils/accessor';
2021-01-03 14:25:43 +05:30
import { inactiveId, LIST, ListType } 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'),
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-09-04 01:27:46 +05:30
mixins: [Tracking.mixin()],
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: {
2021-01-03 14:25:43 +05:30
...mapState(['activeId']),
2021-04-17 20:07:23 +05:30
...mapGetters(['isEpicBoard']),
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
},
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() {
return this.listType === ListType.iteration && this.showListDetails;
},
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) {
return this.isNewIssueShown || this.isSettingsShown;
}
return false;
},
2021-04-17 20:07:23 +05:30
itemsCount() {
2021-03-08 18:12:59 +05:30
return this.list.issuesCount;
2020-11-24 15:15:51 +05:30
},
2021-04-17 20:07:23 +05:30
countIcon() {
return 'issues';
},
itemsTooltipLabel() {
return n__(`%d issue`, `%d issues`, this.itemsCount);
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
},
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);
},
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() {
eventHub.$emit(`toggle-issue-form-${this.list.id}`);
},
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() {
if (AccessorUtilities.isLocalStorageAccessSafe()) {
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
},
},
};
</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="{
2021-03-08 18:12:59 +05:30
'user-can-drag': userCanDrag,
'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 }}
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>
2020-07-28 23:09:34 +05:30
<div v-if="weightFeatureAvailable">
2021-03-08 18:12:59 +05:30
2020-07-28 23:09:34 +05:30
<gl-sprintf :message="__('%{totalWeight} total weight')">
<template #totalWeight>{{ list.totalWeight }}</template>
</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-03-08 18:12:59 +05:30
class="issue-count-badge gl-display-inline-flex gl-pr-0 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" />
<span ref="itemCount" class="issue-count-badge-count">
<gl-icon class="gl-mr-2" :name="countIcon" />
<item-count :items-size="itemsCount" :max-issue-count="list.maxIssueCount" />
2020-06-23 00:09:42 +05:30
</span>
2021-03-08 18:12:59 +05:30
<!-- EE start -->
2021-04-17 20:07:23 +05:30
<template v-if="weightFeatureAvailable && !isEpicBoard">
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" />
{{ list.totalWeight }}
</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"
2020-06-23 00:09:42 +05:30
class="issue-count-badge-add-button no-drag"
icon="plus"
@click="showNewIssueForm"
/>
<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>