Commit 6d0c0fa0 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'make-alert-widget-loading-optional' into 'master'

Make alert widget loading state optional

See merge request gitlab-org/gitlab!28168
parents af2a185e bfef0b61
...@@ -25,6 +25,11 @@ export default { ...@@ -25,6 +25,11 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
showLoadingState: {
type: Boolean,
required: false,
default: true,
},
// { [alertPath]: { alert_attributes } }. Populated from subsequent API calls. // { [alertPath]: { alert_attributes } }. Populated from subsequent API calls.
// Includes only the metrics/alerts to be managed by this widget. // Includes only the metrics/alerts to be managed by this widget.
alertsToManage: { alertsToManage: {
...@@ -75,6 +80,9 @@ export default { ...@@ -75,6 +80,9 @@ export default {
firingCount: this.firingAlerts.length, firingCount: this.firingAlerts.length,
}; };
}, },
shouldShowLoadingIcon() {
return this.showLoadingState && this.isLoading;
},
thresholds() { thresholds() {
const alertsToManage = Object.keys(this.alertsToManage); const alertsToManage = Object.keys(this.alertsToManage);
return alertsToManage.map(this.formatAlertSummary); return alertsToManage.map(this.formatAlertSummary);
...@@ -213,7 +221,7 @@ export default { ...@@ -213,7 +221,7 @@ export default {
<template> <template>
<div class="prometheus-alert-widget dropdown flex-grow-2 overflow-hidden"> <div class="prometheus-alert-widget dropdown flex-grow-2 overflow-hidden">
<gl-loading-icon v-if="isLoading" :inline="true" /> <gl-loading-icon v-if="shouldShowLoadingIcon" :inline="true" />
<span v-else-if="errorMessage" ref="alertErrorMessage" class="alert-error-message">{{ <span v-else-if="errorMessage" ref="alertErrorMessage" class="alert-error-message">{{
errorMessage errorMessage
}}</span> }}</span>
......
...@@ -123,6 +123,30 @@ describe('AlertWidget', () => { ...@@ -123,6 +123,30 @@ describe('AlertWidget', () => {
}); });
}); });
it('does not render loading spinner if showLoadingState is false', () => {
let resolveReadAlert;
mockReadAlert.mockReturnValue(
new Promise(resolve => {
resolveReadAlert = resolve;
}),
);
createComponent({
...defaultProps,
showLoadingState: false,
});
return wrapper.vm
.$nextTick()
.then(() => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
resolveReadAlert({ operator: '==', threshold: 42 });
})
.then(() => waitForPromises())
.then(() => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
});
});
it('displays an error message when fetch fails', () => { it('displays an error message when fetch fails', () => {
mockReadAlert.mockRejectedValue(); mockReadAlert.mockRejectedValue();
createComponent(propsWithAlert); createComponent(propsWithAlert);
......
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