Welcome to mirror list, hosted at ThFree Co, Russian Federation.

issue_assignees.vue « issue « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 715cf97f0ac7b58ed99fd1a160f1e59cdd241f32 (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
<script>
import { GlTooltipDirective } from '@gitlab/ui';
import { __, sprintf } from '~/locale';

import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';

export default {
  components: {
    UserAvatarLink,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    assignees: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      maxVisibleAssignees: 2,
      maxAssigneeAvatars: 3,
      maxAssignees: 99,
    };
  },
  computed: {
    countOverLimit() {
      return this.assignees.length - this.maxVisibleAssignees;
    },
    assigneesToShow() {
      if (this.assignees.length > this.maxAssigneeAvatars) {
        return this.assignees.slice(0, this.maxVisibleAssignees);
      }
      return this.assignees;
    },
    assigneesCounterTooltip() {
      const { countOverLimit, maxAssignees } = this;
      const count = countOverLimit > maxAssignees ? maxAssignees : countOverLimit;

      return sprintf(__('%{count} more assignees'), { count });
    },
    shouldRenderAssigneesCounter() {
      const assigneesCount = this.assignees.length;
      if (assigneesCount <= this.maxAssigneeAvatars) {
        return false;
      }

      return assigneesCount > this.countOverLimit;
    },
    assigneeCounterLabel() {
      if (this.countOverLimit > this.maxAssignees) {
        return `${this.maxAssignees}+`;
      }

      return `+${this.countOverLimit}`;
    },
  },
  methods: {
    avatarUrlTitle(assignee) {
      return sprintf(__('Avatar for %{assigneeName}'), {
        assigneeName: assignee.name,
      });
    },
    // This method is for backward compat
    // since Graph query would return camelCase
    // props while Rails would return snake_case
    webUrl(assignee) {
      return assignee.web_url || assignee.webUrl;
    },
    avatarUrl(assignee) {
      return assignee.avatar_url || assignee.avatarUrl;
    },
  },
};
</script>
<template>
  <div class="issue-assignees">
    <user-avatar-link
      v-for="assignee in assigneesToShow"
      :key="assignee.id"
      :link-href="webUrl(assignee)"
      :img-alt="avatarUrlTitle(assignee)"
      :img-src="avatarUrl(assignee)"
      :img-size="24"
      class="js-no-trigger"
      tooltip-placement="bottom"
    >
      <span class="js-assignee-tooltip">
        <span class="bold d-block">{{ __('Assignee') }}</span> {{ assignee.name }}
        <span class="text-white-50">@{{ assignee.username }}</span>
      </span>
    </user-avatar-link>
    <span
      v-if="shouldRenderAssigneesCounter"
      v-gl-tooltip
      :title="assigneesCounterTooltip"
      class="avatar-counter"
      data-placement="bottom"
      >{{ assigneeCounterLabel }}</span
    >
  </div>
</template>