All files / ee/app/assets/javascripts/compliance_dashboard/components/merge_requests approvers.vue

100% Statements 9/9
100% Branches 2/2
100% Functions 6/6
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  3x 3x 3x                                     6x     6x     6x     6x     2x                         36x                                                                                                                              
<script>
import { GlAvatarLink, GlAvatar, GlAvatarsInline, GlTooltipDirective } from '@gitlab/ui';
import { sprintf, __ } from '~/locale';
import { PRESENTABLE_APPROVERS_LIMIT } from '../../constants';
 
export default {
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  components: {
    GlAvatarsInline,
    GlAvatarLink,
    GlAvatar,
  },
  props: {
    approvers: {
      type: Array,
      required: true,
    },
  },
  computed: {
    hasApprovers() {
      return this.approvers.length > 0;
    },
    approversToPresent() {
      return this.approvers.slice(0, PRESENTABLE_APPROVERS_LIMIT);
    },
    amountOfApproversOverLimit() {
      return this.approvers.length - PRESENTABLE_APPROVERS_LIMIT;
    },
    isApproversOverLimit() {
      return this.amountOfApproversOverLimit > 0;
    },
    approversOverLimitString() {
      return sprintf(__('+%{approvers} more approvers'), {
        approvers: this.amountOfApproversOverLimit,
      });
    },
  },
  PRESENTABLE_APPROVERS_LIMIT,
  strings: {
    approvedBy: __('approved by: '),
    noApprovers: __('no approvers'),
  },
};
</script>
 
<template>
  <div class="gl-display-flex gl-align-items-center gl-justify-content-end" data-testid="approvers">
    <span class="gl-text-gray-500">
      <template v-if="hasApprovers">
        {{ $options.strings.approvedBy }}
      </template>
      <template v-else>
        {{ $options.strings.noApprovers }}
      </template>
    </span>
    <gl-avatars-inline
      v-if="hasApprovers"
      :avatars="approvers"
      :collapsed="true"
      :max-visible="$options.PRESENTABLE_APPROVERS_LIMIT"
      :avatar-size="24"
      class="gl-display-inline-flex gl-lg-display-none! gl-ml-3"
      badge-tooltip-prop="name"
    >
      <template #avatar="{ avatar }">
        <gl-avatar-link
          v-gl-tooltip
          target="blank"
          :href="avatar.web_url"
          :title="avatar.name"
          class="gl-text-gray-900 author-link js-user-link"
        >
          <gl-avatar
            :src="avatar.avatar_url"
            :entity-id="avatar.id"
            :entity-name="avatar.name"
            :size="24"
          />
        </gl-avatar-link>
      </template>
    </gl-avatars-inline>
 
    <gl-avatar-link
      v-for="approver in approversToPresent"
      :key="approver.id"
      :title="approver.name"
      :href="approver.web_url"
      :data-user-id="approver.id"
      :data-name="approver.name"
      class="gl-display-none gl-lg-display-inline-flex! gl-align-items-center gl-justify-content-end gl-ml-3 gl-text-gray-900 author-link js-user-link"
    >
      <gl-avatar
        :src="approver.avatar_url"
        :entity-id="approver.id"
        :entity-name="approver.name"
        :size="16"
        class="gl-mr-2"
      />
      <span>{{ approver.name }}</span>
    </gl-avatar-link>
    <span
      v-if="isApproversOverLimit"
      v-gl-tooltip.top="approversOverLimitString"
      class="gl-display-none gl-lg-display-inline-block! avatar-counter gl-ml-3 gl-px-2 gl-flex-shrink-0 gl-flex-grow-0"
      >+ {{ amountOfApproversOverLimit }}</span
    >
  </div>
</template>