Commit 0baadb42 authored by Clement Ho's avatar Clement Ho

Merge branch '62971-embed-specific-metrics-chart-in-issue' into 'master'

Embed specific metrics chart in issue

Closes #62971

See merge request gitlab-org/gitlab-ce!31644
parents 2dcb69c9 69009fa1
...@@ -45,6 +45,11 @@ export default { ...@@ -45,6 +45,11 @@ export default {
required: false, required: false,
default: () => false, default: () => false,
}, },
singleEmbed: {
type: Boolean,
required: false,
default: false,
},
thresholds: { thresholds: {
type: Array, type: Array,
required: false, required: false,
...@@ -240,7 +245,10 @@ export default { ...@@ -240,7 +245,10 @@ export default {
</script> </script>
<template> <template>
<div class="prometheus-graph col-12 col-lg-6" :class="[showBorder ? 'p-2' : 'p-0']"> <div
class="prometheus-graph col-12"
:class="[showBorder ? 'p-2' : 'p-0', { 'col-lg-6': !singleEmbed }]"
>
<div :class="{ 'prometheus-graph-embed w-100 p-3': showBorder }"> <div :class="{ 'prometheus-graph-embed w-100 p-3': showBorder }">
<div class="prometheus-graph-header"> <div class="prometheus-graph-header">
<h5 ref="graphTitle" class="prometheus-graph-title">{{ graphData.title }}</h5> <h5 ref="graphTitle" class="prometheus-graph-title">{{ graphData.title }}</h5>
......
...@@ -36,12 +36,15 @@ export default { ...@@ -36,12 +36,15 @@ export default {
}, },
computed: { computed: {
...mapState('monitoringDashboard', ['groups', 'metricsWithData']), ...mapState('monitoringDashboard', ['groups', 'metricsWithData']),
groupData() { charts() {
const groupsWithData = this.groups.filter(group => this.chartsWithData(group.metrics).length); const groupWithMetrics = this.groups.find(group =>
if (groupsWithData.length) { group.metrics.find(chart => this.chartHasData(chart)),
return groupsWithData[0]; ) || { metrics: [] };
}
return null; return groupWithMetrics.metrics.filter(chart => this.chartHasData(chart));
},
isSingleChart() {
return this.charts.length === 1;
}, },
}, },
mounted() { mounted() {
...@@ -66,10 +69,8 @@ export default { ...@@ -66,10 +69,8 @@ export default {
'setFeatureFlags', 'setFeatureFlags',
'setShowErrorBanner', 'setShowErrorBanner',
]), ]),
chartsWithData(charts) { chartHasData(chart) {
return charts.filter(chart => return chart.metrics.some(metric => this.metricsWithData.includes(metric.metric_id));
chart.metrics.some(metric => this.metricsWithData.includes(metric.metric_id)),
);
}, },
onSidebarMutation() { onSidebarMutation() {
setTimeout(() => { setTimeout(() => {
...@@ -89,16 +90,17 @@ export default { ...@@ -89,16 +90,17 @@ export default {
}; };
</script> </script>
<template> <template>
<div class="metrics-embed"> <div class="metrics-embed" :class="{ 'd-inline-flex col-lg-6 p-0': isSingleChart }">
<div v-if="groupData" class="row w-100 m-n2 pb-4"> <div v-if="charts.length" class="row w-100 m-n2 pb-4">
<monitor-area-chart <monitor-area-chart
v-for="graphData in chartsWithData(groupData.metrics)" v-for="graphData in charts"
:key="graphData.title" :key="graphData.title"
:graph-data="graphData" :graph-data="graphData"
:container-width="elWidth" :container-width="elWidth"
group-id="monitor-area-chart" group-id="monitor-area-chart"
:project-path="null" :project-path="null"
:show-border="true" :show-border="true"
:single-embed="isSingleChart"
/> />
</div> </div>
</div> </div>
......
---
title: Embed specific metrics chart in issue
merge_request: 31644
author:
type: added
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment