2021-09-04 01:27:46 +05:30
|
|
|
import {
|
|
|
|
getProjectValueStreamStages,
|
|
|
|
getProjectValueStreams,
|
|
|
|
getProjectValueStreamStageData,
|
|
|
|
getProjectValueStreamMetrics,
|
|
|
|
} from '~/api/analytics_api';
|
2021-06-08 01:23:25 +05:30
|
|
|
import createFlash from '~/flash';
|
|
|
|
import { __ } from '~/locale';
|
2021-09-04 01:27:46 +05:30
|
|
|
import { DEFAULT_DAYS_TO_DISPLAY, DEFAULT_VALUE_STREAM } from '../constants';
|
2021-06-08 01:23:25 +05:30
|
|
|
import * as types from './mutation_types';
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
export const setSelectedValueStream = ({ commit, dispatch }, valueStream) => {
|
|
|
|
commit(types.SET_SELECTED_VALUE_STREAM, valueStream);
|
|
|
|
return dispatch('fetchValueStreamStages');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchValueStreamStages = ({ commit, state }) => {
|
|
|
|
const { fullPath, selectedValueStream } = state;
|
|
|
|
commit(types.REQUEST_VALUE_STREAM_STAGES);
|
|
|
|
|
|
|
|
return getProjectValueStreamStages(fullPath, selectedValueStream.id)
|
|
|
|
.then(({ data }) => commit(types.RECEIVE_VALUE_STREAM_STAGES_SUCCESS, data))
|
|
|
|
.catch(({ response: { status } }) => {
|
|
|
|
commit(types.RECEIVE_VALUE_STREAM_STAGES_ERROR, status);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const receiveValueStreamsSuccess = ({ commit, dispatch }, data = []) => {
|
|
|
|
commit(types.RECEIVE_VALUE_STREAMS_SUCCESS, data);
|
|
|
|
if (data.length) {
|
|
|
|
const [firstStream] = data;
|
|
|
|
return dispatch('setSelectedValueStream', firstStream);
|
|
|
|
}
|
|
|
|
return dispatch('setSelectedValueStream', DEFAULT_VALUE_STREAM);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchValueStreams = ({ commit, dispatch, state }) => {
|
|
|
|
const { fullPath } = state;
|
|
|
|
commit(types.REQUEST_VALUE_STREAMS);
|
|
|
|
|
|
|
|
return getProjectValueStreams(fullPath)
|
|
|
|
.then(({ data }) => dispatch('receiveValueStreamsSuccess', data))
|
|
|
|
.then(() => dispatch('setSelectedStage'))
|
|
|
|
.catch(({ response: { status } }) => {
|
|
|
|
commit(types.RECEIVE_VALUE_STREAMS_ERROR, status);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchCycleAnalyticsData = ({ state: { requestPath, startDate }, commit }) => {
|
2021-06-08 01:23:25 +05:30
|
|
|
commit(types.REQUEST_CYCLE_ANALYTICS_DATA);
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
return getProjectValueStreamMetrics(requestPath, { 'cycle_analytics[start_date]': startDate })
|
2021-06-08 01:23:25 +05:30
|
|
|
.then(({ data }) => commit(types.RECEIVE_CYCLE_ANALYTICS_DATA_SUCCESS, data))
|
|
|
|
.catch(() => {
|
|
|
|
commit(types.RECEIVE_CYCLE_ANALYTICS_DATA_ERROR);
|
|
|
|
createFlash({
|
2021-09-04 01:27:46 +05:30
|
|
|
message: __('There was an error while fetching value stream summary data.'),
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchStageData = ({ state: { requestPath, selectedStage, startDate }, commit }) => {
|
|
|
|
commit(types.REQUEST_STAGE_DATA);
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
return getProjectValueStreamStageData({
|
|
|
|
requestPath,
|
|
|
|
stageId: selectedStage.id,
|
|
|
|
params: { 'cycle_analytics[start_date]': startDate },
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
// when there's a query timeout, the request succeeds but the error is encoded in the response data
|
|
|
|
if (data?.error) {
|
|
|
|
commit(types.RECEIVE_STAGE_DATA_ERROR, data.error);
|
|
|
|
} else {
|
|
|
|
commit(types.RECEIVE_STAGE_DATA_SUCCESS, data);
|
|
|
|
}
|
2021-06-08 01:23:25 +05:30
|
|
|
})
|
|
|
|
.catch(() => commit(types.RECEIVE_STAGE_DATA_ERROR));
|
|
|
|
};
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
export const setSelectedStage = ({ dispatch, commit, state: { stages } }, selectedStage = null) => {
|
2021-06-08 01:23:25 +05:30
|
|
|
const stage = selectedStage || stages[0];
|
|
|
|
commit(types.SET_SELECTED_STAGE, stage);
|
2021-09-04 01:27:46 +05:30
|
|
|
return dispatch('fetchStageData');
|
|
|
|
};
|
|
|
|
|
|
|
|
const refetchData = (dispatch, commit) => {
|
|
|
|
commit(types.SET_LOADING, true);
|
|
|
|
return Promise.resolve()
|
|
|
|
.then(() => dispatch('fetchValueStreams'))
|
|
|
|
.then(() => dispatch('fetchCycleAnalyticsData'))
|
|
|
|
.finally(() => commit(types.SET_LOADING, false));
|
2021-06-08 01:23:25 +05:30
|
|
|
};
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
export const setDateRange = ({ dispatch, commit }, { startDate = DEFAULT_DAYS_TO_DISPLAY }) => {
|
2021-06-08 01:23:25 +05:30
|
|
|
commit(types.SET_DATE_RANGE, { startDate });
|
2021-09-04 01:27:46 +05:30
|
|
|
return refetchData(dispatch, commit);
|
|
|
|
};
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
export const initializeVsa = ({ commit, dispatch }, initialData = {}) => {
|
|
|
|
commit(types.INITIALIZE_VSA, initialData);
|
2021-09-04 01:27:46 +05:30
|
|
|
return refetchData(dispatch, commit);
|
2021-06-08 01:23:25 +05:30
|
|
|
};
|