All files / app/assets/javascripts/projects/pipelines/charts/components app.vue

86.36% Statements 19/22
75% Branches 9/12
37.5% Functions 6/16
90.47% Lines 19/21

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          1x                                                                 40x           40x   40x 38x               40x 37x     40x       40x 40x       41x 41x 41x     7x 5x 5x         10x 6x 6x                                                                                                            
<script>
import { GlTabs, GlTab } from '@gitlab/ui';
import API from '~/api';
import { mergeUrlParams, updateHistory, getParameterValues } from '~/lib/utils/url_utility';
import { InternalEvents } from '~/tracking';
import PipelineCharts from './pipeline_charts.vue';
 
export default {
  components: {
    GlTabs,
    GlTab,
    PipelineCharts,
    DeploymentFrequencyCharts: () =>
      import('ee_component/dora/components/deployment_frequency_charts.vue'),
    LeadTimeCharts: () => import('ee_component/dora/components/lead_time_charts.vue'),
    TimeToRestoreServiceCharts: () =>
      import('ee_component/dora/components/time_to_restore_service_charts.vue'),
    ChangeFailureRateCharts: () =>
      import('ee_component/dora/components/change_failure_rate_charts.vue'),
    ProjectQualitySummary: () => import('ee_component/project_quality_summary/app.vue'),
  },
  piplelinesTabEvent: 'p_analytics_ci_cd_pipelines',
  deploymentFrequencyTabEvent: 'p_analytics_ci_cd_deployment_frequency',
  leadTimeTabEvent: 'p_analytics_ci_cd_lead_time',
  timeToRestoreServiceTabEvent: 'p_analytics_ci_cd_time_to_restore_service',
  changeFailureRateTabEvent: 'p_analytics_ci_cd_change_failure_rate',
  mixins: [InternalEvents.mixin()],
  inject: {
    shouldRenderDoraCharts: {
      type: Boolean,
      default: false,
    },
    shouldRenderQualitySummary: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      selectedTab: 0,
    };
  },
  computed: {
    charts() {
      const chartsToShow = ['pipelines'];
 
      if (this.shouldRenderDoraCharts) {
        chartsToShow.push(
          'deployment-frequency',
          'lead-time',
          'time-to-restore-service',
          'change-failure-rate',
        );
      }
 
      if (this.shouldRenderQualitySummary) {
        chartsToShow.push('project-quality');
      }
 
      return chartsToShow;
    },
  },
  created() {
    this.selectTab();
    window.addEventListener('popstate', this.selectTab);
  },
  methods: {
    selectTab() {
      const [chart] = getParameterValues('chart') || this.charts;
      const tab = this.charts.indexOf(chart);
      this.selectedTab = tab >= 0 ? tab : 0;
    },
    onTabChange(index) {
      if (index !== this.selectedTab) {
        this.selectedTab = index;
        const path = mergeUrlParams({ chart: this.charts[index] }, window.location.pathname);
        updateHistory({ url: path, title: window.title });
      }
    },
    trackTabClick(event, trackWithInternalEvents = false) {
      if (trackWithInternalEvents) {
        this.trackEvent(event);
        return;
      }
      API.trackRedisHllUserEvent(event);
    },
  },
};
</script>
<template>
  <div>
    <gl-tabs v-if="charts.length > 1" :value="selectedTab" @input="onTabChange">
      <gl-tab
        :title="__('Pipelines')"
        data-testid="pipelines-tab"
        @click="trackTabClick($options.piplelinesTabEvent, true)"
      >
        <pipeline-charts />
      </gl-tab>
      <template v-if="shouldRenderDoraCharts">
        <gl-tab
          :title="__('Deployment frequency')"
          data-testid="deployment-frequency-tab"
          @click="trackTabClick($options.deploymentFrequencyTabEvent, true)"
        >
          <deployment-frequency-charts />
        </gl-tab>
        <gl-tab
          :title="__('Lead time')"
          data-testid="lead-time-tab"
          @click="trackTabClick($options.leadTimeTabEvent, true)"
        >
          <lead-time-charts />
        </gl-tab>
        <gl-tab
          :title="s__('DORA4Metrics|Time to restore service')"
          data-testid="time-to-restore-service-tab"
          @click="trackTabClick($options.timeToRestoreServiceTabEvent)"
        >
          <time-to-restore-service-charts />
        </gl-tab>
        <gl-tab
          :title="s__('DORA4Metrics|Change failure rate')"
          data-testid="change-failure-rate-tab"
          @click="trackTabClick($options.changeFailureRateTabEvent)"
        >
          <change-failure-rate-charts />
        </gl-tab>
      </template>
      <gl-tab v-if="shouldRenderQualitySummary" :title="s__('QualitySummary|Project quality')">
        <project-quality-summary />
      </gl-tab>
    </gl-tabs>
    <pipeline-charts v-else />
  </div>
</template>