Commit 1a2f7672 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch...

Merge branch '12891-use-a-single-badge-to-show-number-of-active-alerts-on-metrics-dashboards' into 'master'

Use a single badge to show number of alerts on metrics dashboards

Closes #12891

See merge request gitlab-org/gitlab!15789
parents 8c81bfbb 60ef9077
<script> <script>
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
import { GlLink, GlButton } from '@gitlab/ui'; import { GlLink, GlButton, GlTooltip } from '@gitlab/ui';
import { GlAreaChart, GlLineChart, GlChartSeriesLabel } from '@gitlab/ui/dist/charts'; import { GlAreaChart, GlLineChart, GlChartSeriesLabel } from '@gitlab/ui/dist/charts';
import dateFormat from 'dateformat'; import dateFormat from 'dateformat';
import { debounceByAnimationFrame, roundOffFloat } from '~/lib/utils/common_utils'; import { debounceByAnimationFrame, roundOffFloat } from '~/lib/utils/common_utils';
...@@ -16,6 +16,7 @@ export default { ...@@ -16,6 +16,7 @@ export default {
components: { components: {
GlAreaChart, GlAreaChart,
GlLineChart, GlLineChart,
GlTooltip,
GlButton, GlButton,
GlChartSeriesLabel, GlChartSeriesLabel,
GlLink, GlLink,
...@@ -72,6 +73,7 @@ export default { ...@@ -72,6 +73,7 @@ export default {
isDeployment: false, isDeployment: false,
sha: '', sha: '',
}, },
showTitleTooltip: false,
width: 0, width: 0,
height: chartHeight, height: chartHeight,
svgs: {}, svgs: {},
...@@ -202,6 +204,12 @@ export default { ...@@ -202,6 +204,12 @@ export default {
watch: { watch: {
containerWidth: 'onResize', containerWidth: 'onResize',
}, },
mounted() {
const graphTitleEl = this.$refs.graphTitle;
if (graphTitleEl && graphTitleEl.scrollWidth > graphTitleEl.offsetWidth) {
this.showTitleTooltip = true;
}
},
beforeDestroy() { beforeDestroy() {
window.removeEventListener('resize', debouncedResize); window.removeEventListener('resize', debouncedResize);
}, },
...@@ -265,8 +273,16 @@ export default { ...@@ -265,8 +273,16 @@ export default {
<template> <template>
<div class="prometheus-graph"> <div class="prometheus-graph">
<div class="prometheus-graph-header"> <div class="prometheus-graph-header">
<h5 class="prometheus-graph-title js-graph-title">{{ graphData.title }}</h5> <h5
<div class="prometheus-graph-widgets js-graph-widgets"> ref="graphTitle"
class="prometheus-graph-title js-graph-title text-truncate append-right-8"
>
{{ graphData.title }}
</h5>
<gl-tooltip :target="() => $refs.graphTitle" :disabled="!showTitleTooltip">
{{ graphData.title }}
</gl-tooltip>
<div class="prometheus-graph-widgets js-graph-widgets flex-fill">
<slot></slot> <slot></slot>
</div> </div>
</div> </div>
......
...@@ -475,7 +475,10 @@ export default { ...@@ -475,7 +475,10 @@ export default {
:project-path="projectPath" :project-path="projectPath"
group-id="monitor-time-series-chart" group-id="monitor-time-series-chart"
> >
<div class="d-flex align-items-center"> <div
class="d-flex align-items-center"
:class="alertWidgetAvailable ? 'justify-content-between' : 'justify-content-end'"
>
<alert-widget <alert-widget
v-if="alertWidgetAvailable && graphData" v-if="alertWidgetAvailable && graphData"
:modal-id="`alert-modal-${index}-${graphIndex}`" :modal-id="`alert-modal-${index}-${graphIndex}`"
...@@ -486,7 +489,7 @@ export default { ...@@ -486,7 +489,7 @@ export default {
/> />
<gl-dropdown <gl-dropdown
v-gl-tooltip v-gl-tooltip
class="mx-2" class="ml-2 mr-3"
toggle-class="btn btn-transparent border-0" toggle-class="btn btn-transparent border-0"
:right="true" :right="true"
:no-caret="true" :no-caret="true"
......
...@@ -39,11 +39,14 @@ ...@@ -39,11 +39,14 @@
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
margin-bottom: $gl-padding-8; margin-bottom: $gl-padding-8;
}
h5 { .prometheus-graph-title {
font-size: $gl-font-size-large; font-size: $gl-font-size-large;
margin: 0; }
}
.alert-current-setting {
max-width: 240px;
} }
.prometheus-graph-cursor { .prometheus-graph-cursor {
......
<script> <script>
import { s__ } from '~/locale'; import { GlBadge, GlLoadingIcon, GlModal, GlModalDirective } from '@gitlab/ui';
import { s__, sprintf } from '~/locale';
import createFlash from '~/flash'; import createFlash from '~/flash';
import Icon from '~/vue_shared/components/icon.vue';
import AlertWidgetForm from './alert_widget_form.vue'; import AlertWidgetForm from './alert_widget_form.vue';
import AlertsService from '../services/alerts_service'; import AlertsService from '../services/alerts_service';
import { alertsValidator, queriesValidator } from '../validators'; import { alertsValidator, queriesValidator } from '../validators';
import { GlLoadingIcon, GlModal, GlModalDirective } from '@gitlab/ui';
export default { export default {
components: { components: {
AlertWidgetForm, AlertWidgetForm,
GlBadge,
GlLoadingIcon, GlLoadingIcon,
GlModal, GlModal,
Icon,
}, },
directives: { directives: {
GlModal: GlModalDirective, GlModal: GlModalDirective,
...@@ -50,9 +53,14 @@ export default { ...@@ -50,9 +53,14 @@ export default {
}, },
computed: { computed: {
alertSummary() { alertSummary() {
return Object.keys(this.alertsToManage) const alertsToManage = Object.keys(this.alertsToManage);
.map(this.formatAlertSummary) const alertCountMsg = sprintf(s__('PrometheusAlerts|%{count} alerts applied'), {
.join(', '); count: alertsToManage.length,
});
return alertsToManage.length > 1
? alertCountMsg
: alertsToManage.map(this.formatAlertSummary)[0];
}, },
}, },
created() { created() {
...@@ -92,6 +100,9 @@ export default { ...@@ -92,6 +100,9 @@ export default {
return `${alertQuery.label} ${alert.operator} ${alert.threshold}`; return `${alertQuery.label} ${alert.operator} ${alert.threshold}`;
}, },
showModal() {
this.$root.$emit('bv::show::modal', this.modalId);
},
hideModal() { hideModal() {
this.errorMessage = null; this.errorMessage = null;
this.$root.$emit('bv::hide::modal', this.modalId); this.$root.$emit('bv::hide::modal', this.modalId);
...@@ -148,11 +159,22 @@ export default { ...@@ -148,11 +159,22 @@ export default {
</script> </script>
<template> <template>
<div class="prometheus-alert-widget dropdown d-flex align-items-center"> <div class="prometheus-alert-widget dropdown flex-grow-2 overflow-hidden">
<span v-if="errorMessage" class="alert-error-message"> {{ errorMessage }} </span> <span v-if="errorMessage" class="alert-error-message">{{ errorMessage }}</span>
<span v-else class="alert-current-setting text-secondary"> <span
v-else
class="alert-current-setting text-secondary cursor-pointer d-flex align-items-end"
@click="showModal"
>
<gl-badge
v-if="alertSummary"
variant="secondary"
class="d-flex-center text-secondary text-truncate"
>
<icon name="notifications" class="s18 append-right-4" :size="16" />
<span class="text-truncate">{{ alertSummary }}</span>
</gl-badge>
<gl-loading-icon v-show="isLoading" :inline="true" /> <gl-loading-icon v-show="isLoading" :inline="true" />
{{ alertSummary }}
</span> </span>
<alert-widget-form <alert-widget-form
ref="widgetForm" ref="widgetForm"
......
---
title: Use a single badge to show number of active alerts on metrics dashboards
merge_request: 15789
author:
type: changed
...@@ -132,7 +132,7 @@ describe('AlertWidget', () => { ...@@ -132,7 +132,7 @@ describe('AlertWidget', () => {
}; };
createComponent(propsWithManyAlerts); createComponent(propsWithManyAlerts);
expect(findCurrentSettings().text()).toEqual('alert-label > 42, alert-label2 = 900'); expect(findCurrentSettings().text()).toEqual('2 alerts applied');
}); });
it('creates an alert with an appropriate handler', () => { it('creates an alert with an appropriate handler', () => {
......
...@@ -12641,6 +12641,9 @@ msgstr "" ...@@ -12641,6 +12641,9 @@ msgstr ""
msgid "Prometheus listen_address in config/gitlab.yml is not a valid URI" msgid "Prometheus listen_address in config/gitlab.yml is not a valid URI"
msgstr "" msgstr ""
msgid "PrometheusAlerts|%{count} alerts applied"
msgstr ""
msgid "PrometheusAlerts|Add alert" msgid "PrometheusAlerts|Add alert"
msgstr "" msgstr ""
......
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