All files / app/assets/javascripts/releases/components release_block_milestone_info.vue

100% Statements 22/22
75% Branches 15/20
100% Functions 18/18
100% Lines 22/22

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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193        4x                                                                                         32x           32x           32x 32x     32x       103x 103x   103x                 32x     1x       2x 2x 2x   2x                   32x     35x         32x     6x                 3x     108x     108x                                                                                                                                
<script>
import { GlProgressBar, GlLink, GlButton, GlTooltipDirective } from '@gitlab/ui';
import { __, n__, sprintf } from '~/locale';
import { MAX_MILESTONES_TO_DISPLAY } from '../constants';
import IssuableStats from './issuable_stats.vue';
 
export default {
  name: 'ReleaseBlockMilestoneInfo',
  components: {
    GlProgressBar,
    GlLink,
    GlButton,
    IssuableStats,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    milestones: {
      type: Array,
      required: true,
    },
    openedIssuesPath: {
      type: String,
      required: false,
      default: '',
    },
    closedIssuesPath: {
      type: String,
      required: false,
      default: '',
    },
    openedMergeRequestsPath: {
      type: String,
      required: false,
      default: '',
    },
    mergedMergeRequestsPath: {
      type: String,
      required: false,
      default: '',
    },
    closedMergeRequestsPath: {
      type: String,
      required: false,
      default: '',
    },
  },
  data() {
    return {
      showAllMilestones: false,
    };
  },
  computed: {
    percentCompleteText() {
      return sprintf(__('%{percent}%{percentSymbol} complete'), {
        percent: this.percentComplete,
        percentSymbol: '%',
      });
    },
    percentComplete() {
      const percent = Math.round((this.issueCounts.closed / this.issueCounts.total) * 100);
      return Number.isNaN(percent) ? 0 : percent;
    },
    issueCounts() {
      return this.milestones
        .map((m) => m.issueStats || {})
        .reduce(
          (acc, current) => {
            acc.total += current.total || 0;
            acc.closed += current.closed || 0;
 
            return acc;
          },
          {
            total: 0,
            closed: 0,
          },
        );
    },
    showMergeRequestStats() {
      return this.milestones.some((m) => m.mrStats);
    },
    mergeRequestCounts() {
      return this.milestones
        .map((m) => m.mrStats || {})
        .reduce(
          (acc, current) => {
            acc.total += current.total || 0;
            acc.merged += current.merged || 0;
            acc.closed += current.closed || 0;
 
            return acc;
          },
          {
            total: 0,
            merged: 0,
            closed: 0,
          },
        );
    },
    milestoneLabelText() {
      return n__('Milestone', 'Milestones', this.milestones.length);
    },
    milestonesToDisplay() {
      return this.showAllMilestones
        ? this.milestones
        : this.milestones.slice(0, MAX_MILESTONES_TO_DISPLAY);
    },
    showMoreLink() {
      return this.milestones.length > MAX_MILESTONES_TO_DISPLAY;
    },
    moreText() {
      return this.showAllMilestones
        ? __('show fewer')
        : sprintf(__('show %{count} more'), {
            count: this.milestones.length - MAX_MILESTONES_TO_DISPLAY,
          });
    },
  },
  methods: {
    toggleShowAll() {
      this.showAllMilestones = !this.showAllMilestones;
    },
    shouldRenderBullet(milestoneIndex) {
      return Boolean(milestoneIndex !== this.milestonesToDisplay.length - 1 || this.showMoreLink);
    },
    shouldRenderShowMoreLink(milestoneIndex) {
      return Boolean(milestoneIndex === this.milestonesToDisplay.length - 1 && this.showMoreLink);
    },
  },
};
</script>
<template>
  <div class="release-block-milestone-info gl-display-flex gl-flex-wrap">
    <div
      v-gl-tooltip
      class="milestone-progress-bar-container js-milestone-progress-bar-container gl-display-flex gl-flex-direction-column gl-mr-6 gl-mb-5"
      :title="__('Closed issues')"
    >
      <span class="gl-mb-3">{{ percentCompleteText }}</span>
      <span class="gl-w-full">
        <gl-progress-bar :value="issueCounts.closed" :max="issueCounts.total" />
      </span>
    </div>
    <div
      class="gl-display-flex gl-flex-direction-column gl-mr-6 gl-mb-5 js-milestone-list-container"
    >
      <span class="gl-mb-2">{{ milestoneLabelText }}</span>
      <div class="gl-display-flex gl-flex-wrap gl-align-items-flex-end">
        <template v-for="(milestone, index) in milestonesToDisplay">
          <gl-link
            :key="milestone.id"
            v-gl-tooltip
            :title="milestone.description"
            :href="milestone.webUrl"
            class="gl-mr-2"
          >
            {{ milestone.title }}
          </gl-link>
          <template v-if="shouldRenderBullet(index)">
            <span :key="'bullet-' + milestone.id" class="gl-mr-2">&bull;</span>
          </template>
          <template v-if="shouldRenderShowMoreLink(index)">
            <gl-button :key="'more-button-' + milestone.id" variant="link" @click="toggleShowAll">
              {{ moreText }}
            </gl-button>
          </template>
        </template>
      </div>
    </div>
    <issuable-stats
      :label="__('Issues')"
      :total="issueCounts.total"
      :closed="issueCounts.closed"
      :opened-path="openedIssuesPath"
      :closed-path="closedIssuesPath"
      data-testid="issue-stats"
    />
    <issuable-stats
      v-if="showMergeRequestStats"
      :label="__('Merge requests')"
      :total="mergeRequestCounts.total"
      :merged="mergeRequestCounts.merged"
      :closed="mergeRequestCounts.closed"
      :opened-path="openedMergeRequestsPath"
      :merged-path="mergedMergeRequestsPath"
      :closed-path="closedMergeRequestsPath"
      data-testid="merge-request-stats"
    />
  </div>
</template>