summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/pipelines/charts/components/statistics_list.vue
blob: 94cecd2e479818fc7c488a30c084619553e24a8e (plain)
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
<script>
import { formatTime } from '~/lib/utils/datetime_utility';
import { SUPPORTED_FORMATS, getFormatter } from '~/lib/utils/unit_format';
import { s__, n__ } from '~/locale';

const defaultPrecision = 2;

export default {
  props: {
    counts: {
      type: Object,
      required: true,
    },
  },
  computed: {
    totalDuration() {
      return formatTime(this.counts.totalDuration);
    },
    statistics() {
      const formatter = getFormatter(SUPPORTED_FORMATS.percentHundred);

      return [
        {
          title: s__('PipelineCharts|Total:'),
          value: n__('1 pipeline', '%d pipelines', this.counts.total),
        },
        {
          title: s__('PipelineCharts|Successful:'),
          value: n__('1 pipeline', '%d pipelines', this.counts.success),
        },
        {
          title: s__('PipelineCharts|Failed:'),
          value: n__('1 pipeline', '%d pipelines', this.counts.failed),
        },
        {
          title: s__('PipelineCharts|Success ratio:'),
          value: formatter(this.counts.successRatio, defaultPrecision),
        },
        {
          title: s__('PipelineCharts|Total duration:'),
          value: this.totalDuration,
        },
      ];
    },
  },
};
</script>
<template>
  <ul>
    <template v-for="({ title, value }, index) in statistics">
      <li :key="index">
        <span>{{ title }}</span>
        <strong>{{ value }}</strong>
      </li>
    </template>
  </ul>
</template>