All files / ee/app/assets/javascripts/compliance_dashboard/components dashboard.vue

100% Statements 25/25
100% Branches 6/6
100% Functions 10/10
100% Lines 25/25

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  1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                                 15x               15x     13x     3x         19x     5x 1x   9x       4x 4x 4x     2x 2x 2x                       68x                                                                                  
<script>
import { GlTabs, GlTab } from '@gitlab/ui';
import Cookies from 'js-cookie';
import { __ } from '~/locale';
import { DRAWER_Z_INDEX } from '~/lib/utils/constants';
import { COMPLIANCE_TAB_COOKIE_KEY } from '../constants';
import { mapDashboardToDrawerData } from '../utils';
import MergeRequestDrawer from './drawer.vue';
import EmptyState from './empty_state.vue';
import MergeRequestsGrid from './merge_requests/grid.vue';
import MergeCommitsExportButton from './merge_requests/merge_commits_export_button.vue';
 
export default {
  name: 'ComplianceDashboard',
  components: {
    MergeRequestDrawer,
    MergeRequestsGrid,
    EmptyState,
    GlTab,
    GlTabs,
    MergeCommitsExportButton,
  },
  props: {
    emptyStateSvgPath: {
      type: String,
      required: true,
    },
    mergeRequests: {
      type: Array,
      required: true,
    },
    isLastPage: {
      type: Boolean,
      required: false,
      default: false,
    },
    mergeCommitsCsvExportPath: {
      type: String,
      required: false,
      default: '',
    },
  },
  data() {
    return {
      showDrawer: false,
      drawerMergeRequest: {},
      drawerProject: {},
    };
  },
  computed: {
    hasMergeRequests() {
      return this.mergeRequests.length > 0;
    },
    hasMergeCommitsCsvExportPath() {
      return this.mergeCommitsCsvExportPath !== '';
    },
    drawerMergeRequests() {
      return this.mergeRequests.map(mapDashboardToDrawerData);
    },
  },
  methods: {
    showTabs() {
      return Cookies.get(COMPLIANCE_TAB_COOKIE_KEY) === 'true';
    },
    toggleDrawer(mergeRequest) {
      if (this.showDrawer && mergeRequest.id === this.drawerMergeRequest.id) {
        this.closeDrawer();
      } else {
        this.openDrawer(this.drawerMergeRequests.find((mr) => mr.id === mergeRequest.id));
      }
    },
    openDrawer(data) {
      this.showDrawer = true;
      this.drawerMergeRequest = data.mergeRequest;
      this.drawerProject = data.project;
    },
    closeDrawer() {
      this.showDrawer = false;
      this.drawerMergeRequest = {};
      this.drawerProject = {};
    },
  },
  DRAWER_Z_INDEX,
  strings: {
    heading: __('Compliance report'),
    subheading: __('Here you will find recent merge request activity'),
    mergeRequestsTabLabel: __('Merge Requests'),
  },
};
</script>
 
<template>
  <div v-if="hasMergeRequests" class="compliance-dashboard">
    <header>
      <div class="gl-mt-5 d-flex">
        <h4 class="gl-flex-grow-1 gl-my-0">{{ $options.strings.heading }}</h4>
        <merge-commits-export-button
          v-if="hasMergeCommitsCsvExportPath"
          :merge-commits-csv-export-path="mergeCommitsCsvExportPath"
        />
      </div>
      <p>{{ $options.strings.subheading }}</p>
    </header>
 
    <gl-tabs v-if="showTabs()">
      <gl-tab>
        <template #title>
          <span>{{ $options.strings.mergeRequestsTabLabel }}</span>
        </template>
        <merge-requests-grid
          :merge-requests="mergeRequests"
          :is-last-page="isLastPage"
          @toggleDrawer="toggleDrawer"
        />
      </gl-tab>
    </gl-tabs>
    <merge-requests-grid
      v-else
      :merge-requests="mergeRequests"
      :is-last-page="isLastPage"
      @toggleDrawer="toggleDrawer"
    />
    <merge-request-drawer
      :show-drawer="showDrawer"
      :merge-request="drawerMergeRequest"
      :project="drawerProject"
      :z-index="$options.DRAWER_Z_INDEX"
      @close="closeDrawer"
    />
  </div>
  <empty-state v-else :image-path="emptyStateSvgPath" />
</template>