debian-mirror-gitlab/app/assets/javascripts/analytics/usage_trends/components/usage_counts.vue

66 lines
1.6 KiB
Vue
Raw Normal View History

2021-01-03 14:25:43 +05:30
<script>
2021-03-11 19:13:27 +05:30
import MetricCard from '~/analytics/shared/components/metric_card.vue';
2021-09-04 01:27:46 +05:30
import createFlash from '~/flash';
2021-04-17 20:07:23 +05:30
import { number } from '~/lib/utils/unit_format';
2021-03-11 19:13:27 +05:30
import { s__ } from '~/locale';
2021-04-17 20:07:23 +05:30
import usageTrendsCountQuery from '../graphql/queries/usage_trends_count.query.graphql';
2021-01-03 14:25:43 +05:30
const defaultPrecision = 0;
export default {
2021-04-17 20:07:23 +05:30
name: 'UsageCounts',
2021-01-03 14:25:43 +05:30
components: {
MetricCard,
},
data() {
return {
counts: [],
};
},
apollo: {
counts: {
2021-04-17 20:07:23 +05:30
query: usageTrendsCountQuery,
2021-01-03 14:25:43 +05:30
update(data) {
return Object.entries(data).map(([key, obj]) => {
const label = this.$options.i18n.labels[key];
2021-04-17 20:07:23 +05:30
const value = obj.nodes?.length ? number(obj.nodes[0].count, defaultPrecision) : null;
2021-01-03 14:25:43 +05:30
return {
key,
value,
label,
};
});
},
error(error) {
2021-09-04 01:27:46 +05:30
createFlash({
message: this.$options.i18n.loadCountsError,
captureError: true,
error,
});
2021-01-03 14:25:43 +05:30
},
},
},
i18n: {
labels: {
2021-04-17 20:07:23 +05:30
users: s__('UsageTrends|Users'),
projects: s__('UsageTrends|Projects'),
groups: s__('UsageTrends|Groups'),
issues: s__('UsageTrends|Issues'),
2021-04-29 21:17:54 +05:30
mergeRequests: s__('UsageTrends|Merge requests'),
2021-04-17 20:07:23 +05:30
pipelines: s__('UsageTrends|Pipelines'),
2021-01-03 14:25:43 +05:30
},
2021-04-17 20:07:23 +05:30
loadCountsError: s__('Could not load usage counts. Please refresh the page to try again.'),
2021-01-03 14:25:43 +05:30
},
};
</script>
<template>
<metric-card
2021-01-29 00:20:46 +05:30
:title="__('Usage Trends')"
2021-01-03 14:25:43 +05:30
:metrics="counts"
:is-loading="$apollo.queries.counts.loading"
class="gl-mt-4"
/>
</template>