Welcome to mirror list, hosted at ThFree Co, Russian Federation.

value_stream_metrics.vue « components « cycle_analytics « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9671742e564acd1a2ffeaa04178be5b0b2ddebc9 (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
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
<script>
import { GlDeprecatedSkeletonLoading as GlSkeletonLoading } from '@gitlab/ui';
import { GlSingleStat } from '@gitlab/ui/dist/charts';
import { flatten } from 'lodash';
import createFlash from '~/flash';
import { sprintf, s__ } from '~/locale';
import { redirectTo } from '~/lib/utils/url_utility';
import { METRICS_POPOVER_CONTENT } from '../constants';
import { removeFlash, prepareTimeMetricsData } from '../utils';
import MetricPopover from './metric_popover.vue';

const requestData = ({ request, endpoint, path, params, name }) => {
  return request({ endpoint, params, requestPath: path })
    .then(({ data }) => data)
    .catch(() => {
      const message = sprintf(
        s__(
          'ValueStreamAnalytics|There was an error while fetching value stream analytics %{requestTypeName} data.',
        ),
        { requestTypeName: name },
      );
      createFlash({ message });
    });
};

const fetchMetricsData = (reqs = [], path, params) => {
  const promises = reqs.map((r) => requestData({ ...r, path, params }));
  return Promise.all(promises).then((responses) =>
    prepareTimeMetricsData(flatten(responses), METRICS_POPOVER_CONTENT),
  );
};

export default {
  name: 'ValueStreamMetrics',
  components: {
    GlSingleStat,
    GlSkeletonLoading,
    MetricPopover,
  },
  props: {
    requestPath: {
      type: String,
      required: true,
    },
    requestParams: {
      type: Object,
      required: true,
    },
    requests: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      metrics: [],
      isLoading: false,
    };
  },
  watch: {
    requestParams() {
      this.fetchData();
    },
  },
  mounted() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      removeFlash();
      this.isLoading = true;
      return fetchMetricsData(this.requests, this.requestPath, this.requestParams)
        .then((data) => {
          this.metrics = data;
          this.isLoading = false;
        })
        .catch(() => {
          this.isLoading = false;
        });
    },
    hasLinks(links) {
      return links?.length && links[0].url;
    },
    clickHandler({ links }) {
      if (this.hasLinks(links)) {
        redirectTo(links[0].url);
      }
    },
  },
};
</script>
<template>
  <div class="gl-display-flex gl-flex-wrap" data-testid="vsa-time-metrics">
    <gl-skeleton-loading v-if="isLoading" class="gl-h-auto gl-py-3 gl-pr-9 gl-my-6" />
    <div v-for="metric in metrics" v-show="!isLoading" :key="metric.key" class="gl-my-6 gl-pr-9">
      <gl-single-stat
        :id="metric.key"
        :value="`${metric.value}`"
        :title="metric.label"
        :unit="metric.unit || ''"
        :should-animate="true"
        :animation-decimal-places="1"
        :class="{ 'gl-hover-cursor-pointer': hasLinks(metric.links) }"
        tabindex="0"
        @click="clickHandler(metric)"
      />
      <metric-popover :metric="metric" :target="metric.key" />
    </div>
  </div>
</template>