1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
<script>
import { GlIcon, GlLabel, GlTooltipDirective } from '@gitlab/ui';
import { sortBy } from 'lodash';
import { isScopedLabel } from '~/lib/utils/common_utils';
import { s__, sprintf } from '~/locale';
export default {
directives: {
GlTooltip: GlTooltipDirective,
},
components: {
GlIcon,
GlLabel,
},
inject: ['allowScopedLabels'],
props: {
disableLabels: {
type: Boolean,
required: false,
default: false,
},
selectedLabels: {
type: Array,
required: true,
},
allowLabelRemove: {
type: Boolean,
required: true,
},
labelsFilterBasePath: {
type: String,
required: true,
},
labelsFilterParam: {
type: String,
required: true,
},
},
computed: {
sortedSelectedLabels() {
return sortBy(this.selectedLabels, (label) => (isScopedLabel(label) ? 0 : 1));
},
labelsList() {
const labelsString = this.selectedLabels.length
? this.selectedLabels
.slice(0, 5)
.map((label) => label.title)
.join(', ')
: s__('LabelSelect|Labels');
if (this.selectedLabels.length > 5) {
return sprintf(s__('LabelSelect|%{labelsString}, and %{remainingLabelCount} more'), {
labelsString,
remainingLabelCount: this.selectedLabels.length - 5,
});
}
return labelsString;
},
},
methods: {
labelFilterUrl(label) {
return `${this.labelsFilterBasePath}?${this.labelsFilterParam}[]=${encodeURIComponent(
label.title,
)}`;
},
scopedLabel(label) {
return this.allowScopedLabels && isScopedLabel(label);
},
removeLabel(labelId) {
this.$emit('onLabelRemove', labelId);
},
handleCollapsedClick() {
this.$emit('onCollapsedValueClick');
},
},
};
</script>
<template>
<div
:class="{
'has-labels': selectedLabels.length,
}"
class="value issuable-show-labels js-value"
data-testid="value-wrapper"
>
<div
v-gl-tooltip.left.viewport
:title="labelsList"
class="sidebar-collapsed-icon"
@click="handleCollapsedClick"
>
<gl-icon name="labels" />
<span class="collapse-truncated-title gl-pt-2 gl-px-3 gl-font-sm">{{
selectedLabels.length
}}</span>
</div>
<span
v-if="!selectedLabels.length"
class="text-secondary hide-collapsed"
data-testid="empty-placeholder"
>
<slot></slot>
</span>
<template v-else>
<gl-label
v-for="label in sortedSelectedLabels"
:key="label.id"
class="hide-collapsed"
data-qa-selector="selected_label_content"
:data-qa-label-name="label.title"
:title="label.title"
:description="label.description"
:background-color="label.color"
:target="labelFilterUrl(label)"
:scoped="scopedLabel(label)"
:show-close-button="allowLabelRemove"
:disabled="disableLabels"
tooltip-placement="top"
@close="removeLabel(label.id)"
/>
</template>
</div>
</template>
|