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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
<script>
import { GlLabel, GlLink, GlIcon, GlTooltipDirective, GlButton } from '@gitlab/ui';
import { __, s__ } from '~/locale';
import { isScopedLabel } from '~/lib/utils/common_utils';
import RichTimestampTooltip from '~/vue_shared/components/rich_timestamp_tooltip.vue';
import WorkItemLinkChildMetadata from 'ee_else_ce/work_items/components/shared/work_item_link_child_metadata.vue';
import {
STATE_OPEN,
TASK_TYPE_NAME,
WIDGET_TYPE_PROGRESS,
WIDGET_TYPE_HIERARCHY,
WIDGET_TYPE_HEALTH_STATUS,
WIDGET_TYPE_MILESTONE,
WIDGET_TYPE_ASSIGNEES,
WIDGET_TYPE_LABELS,
WORK_ITEM_NAME_TO_ICON_MAP,
} from '../../constants';
export default {
i18n: {
confidential: __('Confidential'),
created: __('Created'),
closed: __('Closed'),
remove: s__('WorkItem|Remove'),
},
components: {
GlLabel,
GlLink,
GlIcon,
GlButton,
RichTimestampTooltip,
WorkItemLinkChildMetadata,
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
childItem: {
type: Object,
required: true,
},
canUpdate: {
type: Boolean,
required: true,
},
/*
This flag is added to manage between two different work items; Task and Objective/Key result.
Status icon is shown on the task while the actual task icon is shown on any Objective/Key result.
*/
showTaskIcon: {
type: Boolean,
required: false,
default: false,
},
showLabels: {
type: Boolean,
required: false,
default: true,
},
},
data() {
return {
isFocused: false,
};
},
computed: {
labels() {
return this.metadataWidgets[WIDGET_TYPE_LABELS]?.labels?.nodes || [];
},
metadataWidgets() {
return this.childItem.widgets?.reduce((metadataWidgets, widget) => {
// Skip Hierarchy widget as it is not part of metadata.
if (widget.type && widget.type !== WIDGET_TYPE_HIERARCHY) {
// eslint-disable-next-line no-param-reassign
metadataWidgets[widget.type] = widget;
}
return metadataWidgets;
}, {});
},
allowsScopedLabels() {
return this.metadataWidgets[WIDGET_TYPE_LABELS]?.allowsScopedLabels;
},
isChildItemOpen() {
return this.childItem.state === STATE_OPEN;
},
iconName() {
if (this.childItemType === TASK_TYPE_NAME && !this.showTaskIcon) {
return this.isChildItemOpen ? 'issue-open-m' : 'issue-close';
}
return WORK_ITEM_NAME_TO_ICON_MAP[this.childItemType];
},
childItemType() {
return this.childItem.workItemType.name;
},
iconClass() {
if (this.childItemType === TASK_TYPE_NAME && !this.showTaskIcon) {
return this.isChildItemOpen ? 'gl-text-green-500' : 'gl-text-blue-500';
}
return '';
},
stateTimestamp() {
return this.isChildItemOpen ? this.childItem.createdAt : this.childItem.closedAt;
},
stateTimestampTypeText() {
return this.isChildItemOpen ? this.$options.i18n.created : this.$options.i18n.closed;
},
hasMetadata() {
if (this.metadataWidgets) {
return (
Number.isInteger(this.metadataWidgets[WIDGET_TYPE_PROGRESS]?.progress) ||
Boolean(this.metadataWidgets[WIDGET_TYPE_HEALTH_STATUS]?.healthStatus) ||
Boolean(this.metadataWidgets[WIDGET_TYPE_MILESTONE]?.milestone) ||
this.metadataWidgets[WIDGET_TYPE_ASSIGNEES]?.assignees?.nodes.length > 0 ||
this.metadataWidgets[WIDGET_TYPE_LABELS]?.labels?.nodes.length > 0
);
}
return false;
},
showRemove() {
return this.canUpdate && this.isFocused;
},
displayLabels() {
return this.showLabels && this.labels.length;
},
},
methods: {
showScopedLabel(label) {
return isScopedLabel(label) && this.allowsScopedLabels;
},
},
};
</script>
<template>
<div
class="item-body work-item-link-child gl-relative gl-display-flex gl-flex-grow-1 gl-overflow-break-word gl-min-w-0 gl-pl-3 gl-pr-2 gl-py-2 gl-mx-n2 gl-rounded-base gl-gap-3"
data-testid="links-child"
@mouseover="isFocused = true"
@mouseleave="isFocused = false"
@focusin="isFocused = true"
@focusout="isFocused = false"
>
<div class="item-contents gl-display-flex gl-flex-grow-1 gl-flex-wrap gl-min-w-0">
<div
class="gl-display-flex gl-flex-grow-1 gl-flex-wrap flex-xl-nowrap gl-align-items-center gl-justify-content-space-between gl-gap-3 gl-min-w-0"
>
<div class="item-title gl-display-flex gl-gap-3 gl-min-w-0">
<span
:id="`stateIcon-${childItem.id}`"
class="gl-cursor-help"
data-testid="item-status-icon"
>
<gl-icon
class="gl-text-secondary"
:class="iconClass"
:name="iconName"
:aria-label="stateTimestampTypeText"
/>
</span>
<rich-timestamp-tooltip
:target="`stateIcon-${childItem.id}`"
:raw-timestamp="stateTimestamp"
:timestamp-type-text="stateTimestampTypeText"
/>
<span v-if="childItem.confidential">
<gl-icon
v-gl-tooltip.top
name="eye-slash"
class="gl-text-orange-500"
data-testid="confidential-icon"
:aria-label="$options.i18n.confidential"
:title="$options.i18n.confidential"
/>
</span>
<gl-link
:href="childItem.webUrl"
class="gl-overflow-break-word gl-font-weight-semibold"
@click="$emit('click', $event)"
@mouseover="$emit('mouseover')"
@mouseout="$emit('mouseout')"
>
{{ childItem.title }}
</gl-link>
</div>
<work-item-link-child-metadata
v-if="hasMetadata"
:metadata-widgets="metadataWidgets"
class="gl-ml-6 ml-xl-0"
/>
</div>
<div v-if="displayLabels" class="gl-display-flex gl-flex-wrap gl-flex-basis-full gl-ml-6">
<gl-label
v-for="label in labels"
:key="label.id"
:title="label.title"
:background-color="label.color"
:description="label.description"
:scoped="showScopedLabel(label)"
class="gl-my-2 gl-mr-2 gl-mb-auto gl-label-sm"
tooltip-placement="top"
/>
</div>
</div>
<div v-if="canUpdate">
<gl-button
:class="{ 'gl-visibility-visible': showRemove }"
class="gl-visibility-hidden"
category="tertiary"
size="small"
icon="close"
:aria-label="$options.i18n.remove"
data-testid="remove-work-item-link"
@click="$emit('removeChild', childItem)"
/>
</div>
</div>
</template>
|