All files / ee/app/assets/javascripts/analytics/code_review_analytics/components merge_request_table.vue

100% Statements 9/9
100% Branches 6/6
100% Functions 3/3
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 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 159  2x                                                                 22x         22x     20x 16x 16x   4x 2x     2x                                                                                                                                                                                                                        
<script>
// eslint-disable-next-line no-restricted-imports
import { mapState } from 'vuex';
import { escape } from 'lodash';
import {
  GlTableLite,
  GlLink,
  GlIcon,
  GlAvatarLink,
  GlAvatar,
  GlTooltipDirective,
} from '@gitlab/ui';
import { getTimeago } from '~/lib/utils/datetime_utility';
import { __, sprintf, n__ } from '~/locale';
import ApproversColumn from './approvers_column.vue';
 
export default {
  name: 'MergeRequestTable',
  components: {
    GlTableLite,
    GlLink,
    GlIcon,
    GlAvatarLink,
    GlAvatar,
    ApproversColumn,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  computed: {
    ...mapState('mergeRequests', ['mergeRequests']),
  },
  methods: {
    getTimeAgoString(createdAt) {
      return sprintf(__('created %{timeAgo}'), {
        timeAgo: escape(getTimeago().format(createdAt)),
      });
    },
    showReviewTime(value) {
      return value !== null && value !== '';
    },
    formatReviewTime(hours) {
      if (hours >= 24) {
        const days = Math.floor(hours / 24);
        return n__('1 day', '%d days', days);
      }
      if (hours >= 1 && hours < 24) {
        return n__('1 hour', '%d hours', hours);
      }
 
      return sprintf(__('%{lessThan} 1 hour'), { lessThan: '<' }, false);
    },
  },
  tableHeaderFields: [
    {
      key: 'mr_details',
      label: __('Merge Request'),
      thClass: 'w-30p',
      tdClass: 'table-col d-flex gl-align-items-center d-sm-table-cell',
    },
    {
      key: 'review_time',
      label: __('Review time'),
      class: 'text-right',
      tdClass: 'table-col d-flex gl-align-items-center d-sm-table-cell',
    },
    {
      key: 'author',
      label: __('Author'),
      tdClass: 'table-col d-flex gl-align-items-center d-sm-table-cell',
    },
    {
      key: 'approved_by',
      label: __('Approvers'),
      tdClass: 'table-col d-flex gl-align-items-center d-sm-table-cell',
    },
    {
      key: 'notes_count',
      label: __('Comments'),
      class: 'text-right',
      tdClass: 'table-col d-flex gl-align-items-center d-sm-table-cell',
    },
    {
      key: 'diff_stats',
      label: __('Commits'),
      class: 'text-right',
      tdClass: 'table-col d-flex gl-align-items-center d-sm-table-cell',
    },
    {
      key: 'line_changes',
      label: __('Line changes'),
      class: 'text-right',
      tdClass: 'table-col d-flex gl-align-items-center d-sm-table-cell',
    },
  ],
};
</script>
 
<template>
  <gl-table-lite
    class="my-3"
    :fields="$options.tableHeaderFields"
    :items="mergeRequests"
    stacked="sm"
  >
    <template #cell(mr_details)="items">
      <div class="d-flex flex-column flex-grow align-items-end align-items-sm-start">
        <div class="gl-max-w-34 str-truncated my-2">
          <gl-link :href="items.item.web_url" target="_blank" class="font-weight-bold text-plain">{{
            items.item.title
          }}</gl-link>
        </div>
        <ul class="horizontal-list list-items-separated text-secondary mb-0">
          <li>!{{ items.item.iid }}</li>
          <li>{{ getTimeAgoString(items.item.created_at) }}</li>
          <li v-if="items.item.milestone">
            <span class="d-flex gl-align-items-center">
              <gl-icon name="milestone" class="gl-mr-2" />
              {{ items.item.milestone.title }}
            </span>
          </li>
        </ul>
      </div>
    </template>
 
    <template #cell(review_time)="{ value }">
      <template v-if="showReviewTime(value)">
        <span v-text="formatReviewTime(value)"></span>
      </template>
      <template v-else> &ndash; </template>
    </template>
 
    <template #cell(author)="{ value }">
      <gl-avatar-link v-gl-tooltip target="_blank" :href="value.web_url" :title="value.name">
        <gl-avatar :size="24" :src="value.avatar_url" :entity-name="value.name" />
      </gl-avatar-link>
    </template>
 
    <template #cell(approved_by)="{ value }">
      <approvers-column
        :approvers="
          value && value.length
            ? value
            : [] /* eslint-disable-line @gitlab/vue-no-new-non-primitive-in-template */
        "
      />
    </template>
 
    <template #cell(diff_stats)="{ value }">
      <span>{{ value.commits_count }}</span>
    </template>
 
    <template #cell(line_changes)="items">
      <span class="font-weight-bold cgreen"> +{{ items.item.diff_stats.additions }} </span>
      <span class="font-weight-bold cred"> -{{ items.item.diff_stats.deletions }} </span>
    </template>
  </gl-table-lite>
</template>