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

assignee_avatar_link.vue « assignees « components « sidebar « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 578c344da02d736e66ef4e6460590e0fca2efe69 (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
<script>
import { GlTooltipDirective, GlLink } from '@gitlab/ui';
import { IssuableType } from '~/issues/constants';
import { __ } from '~/locale';
import { isUserBusy } from '~/set_status_modal/utils';
import AssigneeAvatar from './assignee_avatar.vue';

const I18N = {
  BUSY: __('Busy'),
  CANNOT_MERGE: __('Cannot merge'),
  LC_CANNOT_MERGE: __('cannot merge'),
};

const paranthesize = (str) => `(${str})`;

const generateAssigneeTooltip = ({
  name,
  availability,
  cannotMerge = true,
  tooltipHasName = false,
}) => {
  if (!tooltipHasName) {
    return cannotMerge ? I18N.CANNOT_MERGE : '';
  }

  const statusInformation = [];
  if (availability && isUserBusy(availability)) {
    statusInformation.push(I18N.BUSY);
  }

  if (cannotMerge) {
    statusInformation.push(I18N.LC_CANNOT_MERGE);
  }

  if (tooltipHasName && statusInformation.length) {
    const status = statusInformation.map(paranthesize).join(' ');

    return `${name} ${status}`;
  }

  return name;
};

export default {
  components: {
    AssigneeAvatar,
    GlLink,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    user: {
      type: Object,
      required: true,
    },
    tooltipPlacement: {
      type: String,
      default: 'bottom',
      required: false,
    },
    tooltipHasName: {
      type: Boolean,
      default: true,
      required: false,
    },
    issuableType: {
      type: String,
      default: 'issue',
      required: false,
    },
  },
  computed: {
    cannotMerge() {
      const canMerge = this.user.mergeRequestInteraction?.canMerge || this.user.can_merge;
      return this.issuableType === IssuableType.MergeRequest && !canMerge;
    },
    tooltipTitle() {
      const { name = '', availability = '' } = this.user;
      return generateAssigneeTooltip({
        name,
        availability,
        cannotMerge: this.cannotMerge,
        tooltipHasName: this.tooltipHasName,
      });
    },
    tooltipOption() {
      return {
        container: 'body',
        placement: this.tooltipPlacement,
        boundary: 'viewport',
      };
    },
    assigneeUrl() {
      return this.user.web_url || this.user.webUrl;
    },
  },
};
</script>

<template>
  <!-- must be `d-inline-block` or parent flex-basis causes width issues -->
  <gl-link
    v-gl-tooltip="tooltipOption"
    :href="assigneeUrl"
    :title="tooltipTitle"
    class="gl-display-inline-block"
  >
    <!-- use d-flex so that slot can be appropriately styled -->
    <span class="gl-display-flex">
      <assignee-avatar :user="user" :img-size="32" :issuable-type="issuableType" />
      <slot></slot>
    </span>
  </gl-link>
</template>