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

100% Statements 15/15
100% Branches 6/6
100% Functions 4/4
100% Lines 15/15

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  2x   2x 2x   2x 2x 2x 2x 2x 2x                                                   68x     17x     4x     4x 2x                                       62x                                                                                                                                      
<script>
import { GlSprintf } from '@gitlab/ui';
 
import { __ } from '~/locale';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
 
import BranchDetails from '../shared/branch_details.vue';
import GridColumnHeading from '../shared/grid_column_heading.vue';
import Pagination from '../shared/pagination.vue';
import Approvers from './approvers.vue';
import MergeRequest from './merge_request.vue';
import Status from './status.vue';
 
export default {
  components: {
    Approvers,
    BranchDetails,
    GlSprintf,
    GridColumnHeading,
    MergeRequest,
    Pagination,
    Status,
    TimeAgoTooltip,
  },
  props: {
    mergeRequests: {
      type: Array,
      required: true,
    },
    isLastPage: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  methods: {
    key(id, value) {
      return `${id}-${value}`;
    },
    hasBranchDetails(mergeRequest) {
      return mergeRequest.target_branch && mergeRequest.source_branch;
    },
    onRowClick(e, mergeRequest) {
      const link = e.target.closest('a');
 
      // Only toggle the drawer if the element isn't a link
      if (!link) {
        this.$emit('toggleDrawer', mergeRequest);
      }
    },
  },
  strings: {
    approvalStatusLabel: __('Approval Status'),
    mergedAtText: __('merged %{timeAgo}'),
    mergeRequestLabel: __('Merge Request'),
    pipelineStatusLabel: __('Pipeline'),
    updatesLabel: __('Updates'),
  },
  keyTypes: {
    mergeRequest: 'MR',
    approvalStatus: 'approvalStatus',
    pipeline: 'pipeline',
    updates: 'updates',
  },
};
</script>
 
<template>
  <div>
    <div class="dashboard-grid gl-display-grid gl-grid-tpl-rows-auto">
      <grid-column-heading :heading="$options.strings.mergeRequestLabel" />
      <grid-column-heading :heading="$options.strings.approvalStatusLabel" class="gl-text-center" />
      <grid-column-heading :heading="$options.strings.pipelineStatusLabel" class="gl-text-center" />
      <grid-column-heading :heading="$options.strings.updatesLabel" class="gl-text-right" />
 
      <div
        v-for="mergeRequest in mergeRequests"
        :key="mergeRequest.id"
        class="dashboard-merge-request dashboard-grid gl-display-grid gl-grid-tpl-rows-auto gl-hover-bg-blue-50 gl-hover-text-decoration-none gl-hover-cursor-pointer"
        data-testid="merge-request-drawer-toggle"
        tabindex="0"
        @click="onRowClick($event, mergeRequest)"
        @keypress.enter="onRowClick($event, mergeRequest)"
      >
        <merge-request
          :key="key(mergeRequest.id, $options.keyTypes.mergeRequest)"
          :merge-request="mergeRequest"
        />
 
        <status
          :key="key(mergeRequest.id, 'approval')"
          :status="{ type: 'approval', data: mergeRequest.approval_status }"
        />
 
        <status
          :key="key(mergeRequest.id, 'pipeline')"
          :status="{ type: 'pipeline', data: mergeRequest.pipeline_status }"
        />
 
        <div
          :key="key(mergeRequest.id, $options.keyTypes.updates)"
          class="gl-text-right gl-border-b-solid gl-border-b-1 gl-border-b-gray-100 gl-p-5 gl-relative"
        >
          <approvers :approvers="mergeRequest.approved_by_users" />
          <branch-details
            v-if="hasBranchDetails(mergeRequest)"
            class="gl-justify-content-end gl-text-gray-900"
            :source-branch="{
              name: mergeRequest.source_branch,
              uri: mergeRequest.source_branch_uri,
            }"
            :target-branch="{
              name: mergeRequest.target_branch,
              uri: mergeRequest.target_branch_uri,
            }"
          />
          <time-ago-tooltip
            :time="mergeRequest.merged_at"
            tooltip-placement="bottom"
            class="gl-text-gray-500"
          >
            <template #default="{ timeAgo }">
              <gl-sprintf :message="$options.strings.mergedAtText">
                <template #timeAgo>{{ timeAgo }}</template>
              </gl-sprintf>
            </template>
          </time-ago-tooltip>
        </div>
      </div>
    </div>
 
    <pagination class="gl-mt-5" :is-last-page="isLastPage" />
  </div>
</template>