summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/assignees/uncollapsed_assignee_list.vue
blob: 8717d205dcb7913241a135db24f88d45bbe329c5 (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
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
<script>
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { IssuableType } from '~/issues/constants';
import { __, sprintf } from '~/locale';
import AttentionRequestedToggle from '../attention_requested_toggle.vue';
import AssigneeAvatarLink from './assignee_avatar_link.vue';
import UserNameWithStatus from './user_name_with_status.vue';

const DEFAULT_RENDER_COUNT = 5;

export default {
  components: {
    AttentionRequestedToggle,
    AssigneeAvatarLink,
    UserNameWithStatus,
  },
  mixins: [glFeatureFlagsMixin()],
  props: {
    users: {
      type: Array,
      required: true,
    },
    issuableType: {
      type: String,
      required: false,
      default: 'issue',
    },
  },
  data() {
    return {
      showLess: true,
    };
  },
  computed: {
    firstUser() {
      return this.users[0];
    },
    hasOneUser() {
      if (this.showVerticalList) {
        return false;
      }

      return this.users.length === 1;
    },
    hiddenAssigneesLabel() {
      const { numberOfHiddenAssignees } = this;
      return sprintf(__('+ %{numberOfHiddenAssignees} more'), { numberOfHiddenAssignees });
    },
    renderShowMoreSection() {
      return this.users.length > DEFAULT_RENDER_COUNT;
    },
    numberOfHiddenAssignees() {
      return this.users.length - DEFAULT_RENDER_COUNT;
    },
    uncollapsedUsers() {
      if (this.showVerticalList) {
        return this.users;
      }

      const uncollapsedLength = this.showLess
        ? Math.min(this.users.length, DEFAULT_RENDER_COUNT)
        : this.users.length;
      return this.showLess ? this.users.slice(0, uncollapsedLength) : this.users;
    },
    username() {
      return `@${this.firstUser.username}`;
    },
    showVerticalList() {
      return this.glFeatures.mrAttentionRequests && this.isMergeRequest;
    },
    isMergeRequest() {
      return this.issuableType === IssuableType.MergeRequest;
    },
  },
  methods: {
    toggleShowLess() {
      this.showLess = !this.showLess;
    },
    userAvailability(u) {
      if (this.issuableType === IssuableType.MergeRequest) {
        return u?.availability || '';
      }
      return u?.status?.availability || '';
    },
    toggleAttentionRequested(data) {
      this.$emit('toggle-attention-requested', data);
    },
  },
};
</script>

<template>
  <assignee-avatar-link
    v-if="hasOneUser"
    tooltip-placement="left"
    :tooltip-has-name="false"
    :user="firstUser"
    :issuable-type="issuableType"
  >
    <div class="ml-2 gl-line-height-normal">
      <user-name-with-status :name="firstUser.name" :availability="userAvailability(firstUser)" />
      <div>{{ username }}</div>
    </div>
  </assignee-avatar-link>
  <div v-else>
    <div class="gl-display-flex gl-flex-wrap">
      <div
        v-for="(user, index) in uncollapsedUsers"
        :key="user.id"
        :class="{
          'user-item': !showVerticalList,
          'gl-display-inline-block': !showVerticalList,
          'gl-display-grid gl-align-items-center': showVerticalList,
          'gl-mb-3': index !== users.length - 1 && showVerticalList,
        }"
        class="assignee-grid"
      >
        <assignee-avatar-link
          :user="user"
          :issuable-type="issuableType"
          :tooltip-has-name="!showVerticalList"
          class="gl-word-break-word"
          data-css-area="user"
        >
          <div
            v-if="showVerticalList"
            class="gl-ml-3 gl-line-height-normal gl-display-grid"
            data-testid="username"
          >
            <user-name-with-status :name="user.name" :availability="userAvailability(user)" />
            <span>@{{ user.username }}</span>
          </div>
        </assignee-avatar-link>
        <attention-requested-toggle
          v-if="showVerticalList"
          :user="user"
          type="assignee"
          class="gl-mr-2"
          data-css-area="attention"
          @toggle-attention-requested="toggleAttentionRequested"
        />
      </div>
    </div>
    <div v-if="renderShowMoreSection" class="user-list-more gl-hover-text-blue-800">
      <button
        type="button"
        class="btn-link"
        data-qa-selector="more_assignees_link"
        @click="toggleShowLess"
      >
        <template v-if="showLess">
          {{ hiddenAssigneesLabel }}
        </template>
        <template v-else>{{ __('- show less') }}</template>
      </button>
    </div>
  </div>
</template>