Commit 1b95b8b6 authored by Mike Greiling's avatar Mike Greiling

Merge branch 'mw-productivity-analytics-fetch-secondary-charts' into 'master'

Productivity Analytics: Introduce fetchSecondaryChartData action

See merge request gitlab-org/gitlab!17347
parents bb31fea5 3f47b691
......@@ -2,13 +2,14 @@ import axios from '~/lib/utils/axios_utils';
import * as types from './mutation_types';
import { chartKeys } from '../../../constants';
export const fetchAllChartData = ({ commit, state, dispatch }) => {
// let's reset any data on the main chart first
// since any selected items will be used as query params for other charts)
commit(types.RESET_CHART_DATA, chartKeys.main);
/**
* Fetches data for all charts except for the main chart
*/
export const fetchSecondaryChartData = ({ state, dispatch }) => {
Object.keys(state.charts).forEach(chartKey => {
dispatch('fetchChartData', chartKey);
if (chartKey !== chartKeys.main) {
dispatch('fetchChartData', chartKey);
}
});
};
......
......@@ -7,8 +7,7 @@ export const setGroupNamespace = ({ commit, dispatch }, groupNamespace) => {
// let's fetch the main chart data first to see if the user has access to the selected group
// if there's no 403, then we fetch all remaining chart data and table data
return dispatch('charts/fetchChartData', chartKeys.main, { root: true }).then(() => {
dispatch('charts/fetchChartData', chartKeys.timeBasedHistogram, { root: true });
dispatch('charts/fetchChartData', chartKeys.commitBasedHistogram, { root: true });
dispatch('charts/fetchSecondaryChartData', null, { root: true });
dispatch('table/fetchMergeRequests', null, { root: true });
});
};
......@@ -17,8 +16,7 @@ export const setProjectPath = ({ commit, dispatch }, projectPath) => {
commit(types.SET_PROJECT_PATH, projectPath);
return dispatch('charts/fetchChartData', chartKeys.main, { root: true }).then(() => {
dispatch('charts/fetchChartData', chartKeys.timeBasedHistogram, { root: true });
dispatch('charts/fetchChartData', chartKeys.commitBasedHistogram, { root: true });
dispatch('charts/fetchSecondaryChartData', null, { root: true });
dispatch('table/fetchMergeRequests', null, { root: true });
});
};
......@@ -27,8 +25,7 @@ export const setPath = ({ commit, dispatch }, path) => {
commit(types.SET_PATH, path);
return dispatch('charts/fetchChartData', chartKeys.main, { root: true }).then(() => {
dispatch('charts/fetchChartData', chartKeys.timeBasedHistogram, { root: true });
dispatch('charts/fetchChartData', chartKeys.commitBasedHistogram, { root: true });
dispatch('charts/fetchSecondaryChartData', null, { root: true });
dispatch('table/fetchMergeRequests', null, { root: true });
});
};
......@@ -37,8 +34,7 @@ export const setDaysInPast = ({ commit, dispatch }, days) => {
commit(types.SET_DAYS_IN_PAST, days);
return dispatch('charts/fetchChartData', chartKeys.main, { root: true }).then(() => {
dispatch('charts/fetchChartData', chartKeys.timeBasedHistogram, { root: true });
dispatch('charts/fetchChartData', chartKeys.commitBasedHistogram, { root: true });
dispatch('charts/fetchSecondaryChartData', null, { root: true });
dispatch('table/fetchMergeRequests', null, { root: true });
});
};
......
......@@ -160,15 +160,14 @@ describe('Productivity analytics chart actions', () => {
});
});
describe('fetchAllChartData', () => {
it('commits reset for the main chart and dispatches fetchChartData for all chart types', done => {
describe('fetchSecondaryChartData', () => {
it('dispatches fetchChartData for all chart types except for the main chart', done => {
testAction(
actions.fetchAllChartData,
actions.fetchSecondaryChartData,
null,
mockedContext.state,
[{ type: types.RESET_CHART_DATA, payload: chartKeys.main }],
[],
[
{ type: 'fetchChartData', payload: chartKeys.main },
{ type: 'fetchChartData', payload: chartKeys.timeBasedHistogram },
{ type: 'fetchChartData', payload: chartKeys.commitBasedHistogram },
{ type: 'fetchChartData', payload: chartKeys.scatterplot },
......
......@@ -27,20 +27,14 @@ describe('Productivity analytics filter actions', () => {
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.timeBasedHistogram,
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchChartData',
chartKeys.commitBasedHistogram,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual([
'table/fetchMergeRequests',
jasmine.any(Object),
null,
{ root: true },
]);
})
......@@ -68,20 +62,14 @@ describe('Productivity analytics filter actions', () => {
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.timeBasedHistogram,
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchChartData',
chartKeys.commitBasedHistogram,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual([
'table/fetchMergeRequests',
jasmine.any(Object),
null,
{ root: true },
]);
})
......@@ -109,20 +97,14 @@ describe('Productivity analytics filter actions', () => {
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.timeBasedHistogram,
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchChartData',
chartKeys.commitBasedHistogram,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual([
'table/fetchMergeRequests',
jasmine.any(Object),
null,
{ root: true },
]);
})
......@@ -150,20 +132,14 @@ describe('Productivity analytics filter actions', () => {
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.timeBasedHistogram,
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchChartData',
chartKeys.commitBasedHistogram,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual([
'table/fetchMergeRequests',
jasmine.any(Object),
null,
{ root: 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