summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/work_items/components/work_item_links/work_item_link_child_metadata.vue
blob: 6974804523a14285fd3e5225d14762705b1a1000 (plain)
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
<script>
import { GlLabel, GlAvatar, GlAvatarLink, GlAvatarsInline, GlTooltipDirective } from '@gitlab/ui';

import { s__, sprintf } from '~/locale';
import { isScopedLabel } from '~/lib/utils/common_utils';

import ItemMilestone from '~/issuable/components/issue_milestone.vue';

import { WIDGET_TYPE_MILESTONE, WIDGET_TYPE_ASSIGNEES, WIDGET_TYPE_LABELS } from '../../constants';

export default {
  components: {
    GlLabel,
    GlAvatar,
    GlAvatarLink,
    GlAvatarsInline,
    ItemMilestone,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    metadataWidgets: {
      type: Object,
      required: false,
      default: () => ({}),
    },
  },
  computed: {
    milestone() {
      return this.metadataWidgets[WIDGET_TYPE_MILESTONE]?.milestone;
    },
    assignees() {
      return this.metadataWidgets[WIDGET_TYPE_ASSIGNEES]?.assignees?.nodes || [];
    },
    labels() {
      return this.metadataWidgets[WIDGET_TYPE_LABELS]?.labels?.nodes || [];
    },
    allowsScopedLabels() {
      return this.metadataWidgets[WIDGET_TYPE_LABELS]?.allowsScopedLabels;
    },
    assigneesCollapsedTooltip() {
      if (this.assignees.length > 2) {
        return sprintf(s__('WorkItem|%{count} more assignees'), {
          count: this.assignees.length - 2,
        });
      }
      return '';
    },
    assigneesContainerClass() {
      if (this.assignees.length === 2) {
        return 'fixed-width-avatars-2';
      } else if (this.assignees.length > 2) {
        return 'fixed-width-avatars-3';
      }
      return '';
    },
  },
  methods: {
    showScopedLabel(label) {
      return isScopedLabel(label) && this.allowsScopedLabels;
    },
  },
};
</script>

<template>
  <div class="gl-display-flex gl-flex-wrap gl-align-items-center">
    <slot></slot>
    <item-milestone
      v-if="milestone"
      :milestone="milestone"
      class="gl-display-flex gl-align-items-center gl-mr-5 gl-max-w-15 gl-text-secondary! gl-cursor-help! gl-text-decoration-none!"
    />
    <gl-avatars-inline
      v-if="assignees.length"
      :avatars="assignees"
      :collapsed="true"
      :max-visible="2"
      :avatar-size="24"
      badge-tooltip-prop="name"
      :badge-sr-only-text="assigneesCollapsedTooltip"
      :class="assigneesContainerClass"
      class="gl-mr-5"
    >
      <template #avatar="{ avatar }">
        <gl-avatar-link v-gl-tooltip target="blank" :href="avatar.webUrl" :title="avatar.name">
          <gl-avatar :src="avatar.avatarUrl" :size="24" />
        </gl-avatar-link>
      </template>
    </gl-avatars-inline>
    <div v-if="labels.length" class="gl-display-flex gl-flex-wrap">
      <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-mt-3 gl-sm-mt-0 gl-mr-2 gl-mb-auto gl-label-sm"
        tooltip-placement="top"
      />
    </div>
  </div>
</template>

<style scoped>
/**
 * These overrides are needed to address https://gitlab.com/gitlab-org/gitlab-ui/-/issues/865
 */
.fixed-width-avatars-2 {
  width: 42px !important;
}

.fixed-width-avatars-3 {
  width: 67px !important;
}
</style>