Commit 393347dd authored by Martin Wortschack's avatar Martin Wortschack

Merge branch...

Merge branch '208524-error-in-custom-dashboard-yml-file-breaks-the-dashboards-dropdown' into 'master'

Error in custom dashboard yml file breaks the dashboards dropdown

See merge request gitlab-org/gitlab!26228
parents 130ac332 7ba2b54e
...@@ -79,7 +79,7 @@ export const fetchData = ({ dispatch }) => { ...@@ -79,7 +79,7 @@ export const fetchData = ({ dispatch }) => {
dispatch('fetchEnvironmentsData'); dispatch('fetchEnvironmentsData');
}; };
export const fetchDashboard = ({ state, dispatch }) => { export const fetchDashboard = ({ state, commit, dispatch }) => {
dispatch('requestMetricsDashboard'); dispatch('requestMetricsDashboard');
const params = {}; const params = {};
...@@ -100,6 +100,7 @@ export const fetchDashboard = ({ state, dispatch }) => { ...@@ -100,6 +100,7 @@ export const fetchDashboard = ({ state, dispatch }) => {
.catch(error => { .catch(error => {
Sentry.captureException(error); Sentry.captureException(error);
commit(types.SET_ALL_DASHBOARDS, error.response?.data?.all_dashboards ?? []);
dispatch('receiveMetricsDashboardFailure', error); dispatch('receiveMetricsDashboardFailure', error);
if (state.showErrorBanner) { if (state.showErrorBanner) {
......
---
title: Fix dashboards dropdown if custom dashboard is broken
merge_request: 26228
author:
type: fixed
...@@ -544,6 +544,12 @@ export const dashboardGitResponse = [ ...@@ -544,6 +544,12 @@ export const dashboardGitResponse = [
...customDashboardsData, ...customDashboardsData,
]; ];
export const mockDashboardsErrorResponse = {
all_dashboards: customDashboardsData,
message: "Each 'panel_group' must define an array :panels",
status: 'error',
};
export const graphDataPrometheusQuery = { export const graphDataPrometheusQuery = {
title: 'Super Chart A2', title: 'Super Chart A2',
type: 'single-stat', type: 'single-stat',
......
...@@ -30,6 +30,7 @@ import { ...@@ -30,6 +30,7 @@ import {
metricsDashboardResponse, metricsDashboardResponse,
metricsDashboardViewModel, metricsDashboardViewModel,
dashboardGitResponse, dashboardGitResponse,
mockDashboardsErrorResponse,
} from '../mock_data'; } from '../mock_data';
jest.mock('~/flash'); jest.mock('~/flash');
...@@ -257,9 +258,11 @@ describe('Monitoring store actions', () => { ...@@ -257,9 +258,11 @@ describe('Monitoring store actions', () => {
describe('fetchDashboard', () => { describe('fetchDashboard', () => {
let dispatch; let dispatch;
let state; let state;
let commit;
const response = metricsDashboardResponse; const response = metricsDashboardResponse;
beforeEach(() => { beforeEach(() => {
dispatch = jest.fn(); dispatch = jest.fn();
commit = jest.fn();
state = storeState(); state = storeState();
state.dashboardEndpoint = '/dashboard'; state.dashboardEndpoint = '/dashboard';
}); });
...@@ -270,6 +273,7 @@ describe('Monitoring store actions', () => { ...@@ -270,6 +273,7 @@ describe('Monitoring store actions', () => {
fetchDashboard( fetchDashboard(
{ {
state, state,
commit,
dispatch, dispatch,
}, },
params, params,
...@@ -287,19 +291,21 @@ describe('Monitoring store actions', () => { ...@@ -287,19 +291,21 @@ describe('Monitoring store actions', () => {
describe('on failure', () => { describe('on failure', () => {
let result; let result;
let errorResponse;
beforeEach(() => { beforeEach(() => {
const params = {}; const params = {};
result = () => { result = () => {
mock.onGet(state.dashboardEndpoint).replyOnce(500, errorResponse); mock.onGet(state.dashboardEndpoint).replyOnce(500, mockDashboardsErrorResponse);
return fetchDashboard({ state, dispatch }, params); return fetchDashboard({ state, commit, dispatch }, params);
}; };
}); });
it('dispatches a failure action', done => { it('dispatches a failure action', done => {
errorResponse = {};
result() result()
.then(() => { .then(() => {
expect(commit).toHaveBeenCalledWith(
types.SET_ALL_DASHBOARDS,
mockDashboardsErrorResponse.all_dashboards,
);
expect(dispatch).toHaveBeenCalledWith( expect(dispatch).toHaveBeenCalledWith(
'receiveMetricsDashboardFailure', 'receiveMetricsDashboardFailure',
new Error('Request failed with status code 500'), new Error('Request failed with status code 500'),
...@@ -311,15 +317,15 @@ describe('Monitoring store actions', () => { ...@@ -311,15 +317,15 @@ describe('Monitoring store actions', () => {
}); });
it('dispatches a failure action when a message is returned', done => { it('dispatches a failure action when a message is returned', done => {
const message = 'Something went wrong with Prometheus!';
errorResponse = { message };
result() result()
.then(() => { .then(() => {
expect(dispatch).toHaveBeenCalledWith( expect(dispatch).toHaveBeenCalledWith(
'receiveMetricsDashboardFailure', 'receiveMetricsDashboardFailure',
new Error('Request failed with status code 500'), new Error('Request failed with status code 500'),
); );
expect(createFlash).toHaveBeenCalledWith(expect.stringContaining(message)); expect(createFlash).toHaveBeenCalledWith(
expect.stringContaining(mockDashboardsErrorResponse.message),
);
done(); done();
}) })
.catch(done.fail); .catch(done.fail);
......
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