Commit db674e2d authored by Miguel Rincon's avatar Miguel Rincon Committed by Paul Slaughter

Moved entire dashboard to Vuex state

Currently only the panel groups are kept in the store
and other dashboard information is discarted.

In order for the information to be preserved by the client
it must be saved to the store.
parent 3a2c1c59
...@@ -39,7 +39,7 @@ export const requestMetricsDashboard = ({ commit }) => { ...@@ -39,7 +39,7 @@ export const requestMetricsDashboard = ({ commit }) => {
}; };
export const receiveMetricsDashboardSuccess = ({ commit, dispatch }, { response, params }) => { export const receiveMetricsDashboardSuccess = ({ commit, dispatch }, { response, params }) => {
commit(types.SET_ALL_DASHBOARDS, response.all_dashboards); commit(types.SET_ALL_DASHBOARDS, response.all_dashboards);
commit(types.RECEIVE_METRICS_DATA_SUCCESS, response.dashboard.panel_groups); commit(types.RECEIVE_METRICS_DATA_SUCCESS, response.dashboard);
return dispatch('fetchPrometheusMetrics', params); return dispatch('fetchPrometheusMetrics', params);
}; };
export const receiveMetricsDashboardFailure = ({ commit }, error) => { export const receiveMetricsDashboardFailure = ({ commit }, error) => {
......
...@@ -84,8 +84,10 @@ export default { ...@@ -84,8 +84,10 @@ export default {
state.emptyState = 'loading'; state.emptyState = 'loading';
state.showEmptyState = true; state.showEmptyState = true;
}, },
[types.RECEIVE_METRICS_DATA_SUCCESS](state, groupData) { [types.RECEIVE_METRICS_DATA_SUCCESS](state, dashboard) {
state.dashboard.panel_groups = groupData.map((group, i) => { state.dashboard = {
...dashboard,
panel_groups: dashboard.panel_groups.map((group, i) => {
const key = `${slugify(group.group || 'default')}-${i}`; const key = `${slugify(group.group || 'default')}-${i}`;
let { panels = [] } = group; let { panels = [] } = group;
...@@ -100,7 +102,8 @@ export default { ...@@ -100,7 +102,8 @@ export default {
panels, panels,
key, key,
}; };
}); }),
};
if (!state.dashboard.panel_groups.length) { if (!state.dashboard.panel_groups.length) {
state.emptyState = 'noData'; state.emptyState = 'noData';
......
...@@ -345,7 +345,7 @@ describe('Dashboard', () => { ...@@ -345,7 +345,7 @@ describe('Dashboard', () => {
it('metrics can be swapped', done => { it('metrics can be swapped', done => {
const firstDraggable = findDraggables().at(0); const firstDraggable = findDraggables().at(0);
const mockMetrics = [...metricsGroupsAPIResponse[1].panels]; const mockMetrics = [...metricsGroupsAPIResponse.panel_groups[1].panels];
const firstTitle = mockMetrics[0].title; const firstTitle = mockMetrics[0].title;
const secondTitle = mockMetrics[1].title; const secondTitle = mockMetrics[1].title;
......
...@@ -331,7 +331,9 @@ export const mockedQueryResultPayloadCoresTotal = { ...@@ -331,7 +331,9 @@ export const mockedQueryResultPayloadCoresTotal = {
], ],
}; };
export const metricsGroupsAPIResponse = [ export const metricsGroupsAPIResponse = {
dashboard: 'Environment metrics',
panel_groups: [
{ {
group: 'Response metrics (NGINX Ingress VTS)', group: 'Response metrics (NGINX Ingress VTS)',
priority: 10, priority: 10,
...@@ -401,7 +403,8 @@ export const metricsGroupsAPIResponse = [ ...@@ -401,7 +403,8 @@ export const metricsGroupsAPIResponse = [
}, },
], ],
}, },
]; ],
};
export const environmentData = [ export const environmentData = [
{ {
......
...@@ -298,7 +298,7 @@ describe('Monitoring store actions', () => { ...@@ -298,7 +298,7 @@ describe('Monitoring store actions', () => {
); );
expect(commit).toHaveBeenCalledWith( expect(commit).toHaveBeenCalledWith(
types.RECEIVE_METRICS_DATA_SUCCESS, types.RECEIVE_METRICS_DATA_SUCCESS,
metricsDashboardResponse.dashboard.panel_groups, metricsDashboardResponse.dashboard,
); );
expect(dispatch).toHaveBeenCalledWith('fetchPrometheusMetrics', params); expect(dispatch).toHaveBeenCalledWith('fetchPrometheusMetrics', params);
}); });
...@@ -441,7 +441,7 @@ describe('Monitoring store actions', () => { ...@@ -441,7 +441,7 @@ describe('Monitoring store actions', () => {
beforeEach(() => { beforeEach(() => {
state = storeState(); state = storeState();
[metric] = metricsDashboardResponse.dashboard.panel_groups[0].panels[0].metrics; [metric] = metricsDashboardResponse.dashboard.panel_groups[0].panels[0].metrics;
[data] = metricsGroupsAPIResponse[0].panels[0].metrics; [data] = metricsGroupsAPIResponse.panel_groups[0].panels[0].metrics;
}); });
it('commits result', done => { it('commits result', done => {
......
...@@ -100,12 +100,12 @@ describe('Monitoring mutations', () => { ...@@ -100,12 +100,12 @@ describe('Monitoring mutations', () => {
values: [[0, 1], [1, 1], [1, 3]], values: [[0, 1], [1, 1], [1, 3]],
}, },
]; ];
const dashboardGroups = metricsDashboardResponse.dashboard.panel_groups; const { dashboard } = metricsDashboardResponse;
const getMetric = () => stateCopy.dashboard.panel_groups[0].panels[0].metrics[0]; const getMetric = () => stateCopy.dashboard.panel_groups[0].panels[0].metrics[0];
describe('REQUEST_METRIC_RESULT', () => { describe('REQUEST_METRIC_RESULT', () => {
beforeEach(() => { beforeEach(() => {
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups); mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboard);
}); });
it('stores a loading state on a metric', () => { it('stores a loading state on a metric', () => {
expect(stateCopy.showEmptyState).toBe(true); expect(stateCopy.showEmptyState).toBe(true);
...@@ -128,7 +128,7 @@ describe('Monitoring mutations', () => { ...@@ -128,7 +128,7 @@ describe('Monitoring mutations', () => {
describe('RECEIVE_METRIC_RESULT_SUCCESS', () => { describe('RECEIVE_METRIC_RESULT_SUCCESS', () => {
beforeEach(() => { beforeEach(() => {
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups); mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboard);
}); });
it('clears empty state', () => { it('clears empty state', () => {
expect(stateCopy.showEmptyState).toBe(true); expect(stateCopy.showEmptyState).toBe(true);
...@@ -161,7 +161,7 @@ describe('Monitoring mutations', () => { ...@@ -161,7 +161,7 @@ describe('Monitoring mutations', () => {
describe('RECEIVE_METRIC_RESULT_FAILURE', () => { describe('RECEIVE_METRIC_RESULT_FAILURE', () => {
beforeEach(() => { beforeEach(() => {
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups); mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboard);
}); });
it('maintains the loading state when a metric fails', () => { it('maintains the loading state when a metric fails', () => {
expect(stateCopy.showEmptyState).toBe(true); expect(stateCopy.showEmptyState).toBe(true);
......
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