2021-06-11 15:09:58 +00:00
|
|
|
import {
|
|
|
|
getProjectValueStreamStages,
|
|
|
|
getProjectValueStreams,
|
2021-07-15 18:09:37 +00:00
|
|
|
getValueStreamStageMedian,
|
2021-08-04 18:09:57 +00:00
|
|
|
getValueStreamStageRecords,
|
2021-08-06 18:09:57 +00:00
|
|
|
getValueStreamStageCounts,
|
2021-06-11 15:09:58 +00:00
|
|
|
} from '~/api/analytics_api';
|
2021-10-12 15:12:08 +00:00
|
|
|
import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils';
|
2021-04-21 09:09:15 +00:00
|
|
|
import createFlash from '~/flash';
|
|
|
|
import { __ } from '~/locale';
|
2021-08-04 18:09:57 +00:00
|
|
|
import { DEFAULT_VALUE_STREAM, I18N_VSA_ERROR_STAGE_MEDIAN } from '../constants';
|
2021-04-21 09:09:15 +00:00
|
|
|
import * as types from './mutation_types';
|
|
|
|
|
2021-06-11 15:09:58 +00:00
|
|
|
export const setSelectedValueStream = ({ commit, dispatch }, valueStream) => {
|
|
|
|
commit(types.SET_SELECTED_VALUE_STREAM, valueStream);
|
2021-11-13 03:09:49 +00:00
|
|
|
return dispatch('fetchValueStreamStages');
|
2021-06-11 15:09:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchValueStreamStages = ({ commit, state }) => {
|
2021-08-04 18:09:57 +00:00
|
|
|
const {
|
|
|
|
endpoints: { fullPath },
|
|
|
|
selectedValueStream: { id },
|
|
|
|
} = state;
|
2021-06-11 15:09:58 +00:00
|
|
|
commit(types.REQUEST_VALUE_STREAM_STAGES);
|
|
|
|
|
2021-08-04 18:09:57 +00:00
|
|
|
return getProjectValueStreamStages(fullPath, id)
|
2021-06-11 15:09:58 +00:00
|
|
|
.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 }) => {
|
2021-07-15 18:09:37 +00:00
|
|
|
const {
|
2021-08-04 18:09:57 +00:00
|
|
|
endpoints: { fullPath },
|
2021-07-15 18:09:37 +00:00
|
|
|
} = state;
|
2021-06-11 15:09:58 +00:00
|
|
|
commit(types.REQUEST_VALUE_STREAMS);
|
|
|
|
|
|
|
|
return getProjectValueStreams(fullPath)
|
|
|
|
.then(({ data }) => dispatch('receiveValueStreamsSuccess', data))
|
|
|
|
.catch(({ response: { status } }) => {
|
|
|
|
commit(types.RECEIVE_VALUE_STREAMS_ERROR, status);
|
|
|
|
});
|
|
|
|
};
|
2021-04-21 09:09:15 +00:00
|
|
|
|
2021-10-12 15:12:08 +00:00
|
|
|
export const fetchStageData = ({
|
|
|
|
getters: { requestParams, filterParams, paginationParams },
|
|
|
|
commit,
|
|
|
|
}) => {
|
2021-04-21 09:09:15 +00:00
|
|
|
commit(types.REQUEST_STAGE_DATA);
|
|
|
|
|
2021-10-12 15:12:08 +00:00
|
|
|
return getValueStreamStageRecords(requestParams, { ...filterParams, ...paginationParams })
|
|
|
|
.then(({ data, headers }) => {
|
2021-06-07 09:10:26 +00:00
|
|
|
// 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-10-12 15:12:08 +00:00
|
|
|
const { page = null, nextPage = null } = parseIntPagination(normalizeHeaders(headers));
|
|
|
|
commit(types.SET_PAGINATION, { ...paginationParams, page, hasNextPage: Boolean(nextPage) });
|
2021-06-07 09:10:26 +00:00
|
|
|
}
|
|
|
|
})
|
2021-04-21 09:09:15 +00:00
|
|
|
.catch(() => commit(types.RECEIVE_STAGE_DATA_ERROR));
|
|
|
|
};
|
|
|
|
|
2021-07-15 18:09:37 +00:00
|
|
|
const getStageMedians = ({ stageId, vsaParams, filterParams = {} }) => {
|
|
|
|
return getValueStreamStageMedian({ ...vsaParams, stageId }, filterParams).then(({ data }) => ({
|
|
|
|
id: stageId,
|
|
|
|
value: data?.value || null,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchStageMedians = ({
|
|
|
|
state: { stages },
|
|
|
|
getters: { requestParams: vsaParams, filterParams },
|
|
|
|
commit,
|
|
|
|
}) => {
|
|
|
|
commit(types.REQUEST_STAGE_MEDIANS);
|
|
|
|
return Promise.all(
|
|
|
|
stages.map(({ id: stageId }) =>
|
|
|
|
getStageMedians({
|
|
|
|
vsaParams,
|
|
|
|
stageId,
|
|
|
|
filterParams,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.then((data) => commit(types.RECEIVE_STAGE_MEDIANS_SUCCESS, data))
|
|
|
|
.catch((error) => {
|
|
|
|
commit(types.RECEIVE_STAGE_MEDIANS_ERROR, error);
|
2021-08-02 12:09:59 +00:00
|
|
|
createFlash({ message: I18N_VSA_ERROR_STAGE_MEDIAN });
|
2021-07-15 18:09:37 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-08-06 18:09:57 +00:00
|
|
|
const getStageCounts = ({ stageId, vsaParams, filterParams = {} }) => {
|
|
|
|
return getValueStreamStageCounts({ ...vsaParams, stageId }, filterParams).then(({ data }) => ({
|
|
|
|
id: stageId,
|
|
|
|
...data,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchStageCountValues = ({
|
|
|
|
state: { stages },
|
|
|
|
getters: { requestParams: vsaParams, filterParams },
|
|
|
|
commit,
|
|
|
|
}) => {
|
|
|
|
commit(types.REQUEST_STAGE_COUNTS);
|
|
|
|
return Promise.all(
|
|
|
|
stages.map(({ id: stageId }) =>
|
|
|
|
getStageCounts({
|
|
|
|
vsaParams,
|
|
|
|
stageId,
|
|
|
|
filterParams,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.then((data) => commit(types.RECEIVE_STAGE_COUNTS_SUCCESS, data))
|
|
|
|
.catch((error) => {
|
|
|
|
commit(types.RECEIVE_STAGE_COUNTS_ERROR, error);
|
|
|
|
createFlash({
|
|
|
|
message: __('There was an error fetching stage total counts'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-11-13 03:09:49 +00:00
|
|
|
export const fetchValueStreamStageData = ({ dispatch }) =>
|
|
|
|
Promise.all([
|
|
|
|
dispatch('fetchStageData'),
|
|
|
|
dispatch('fetchStageMedians'),
|
|
|
|
dispatch('fetchStageCountValues'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
export const refetchStageData = async ({ dispatch, commit }) => {
|
|
|
|
commit(types.SET_LOADING, true);
|
|
|
|
await dispatch('fetchValueStreamStageData');
|
|
|
|
commit(types.SET_LOADING, false);
|
2021-06-11 15:09:58 +00:00
|
|
|
};
|
|
|
|
|
2021-11-13 03:09:49 +00:00
|
|
|
export const setSelectedStage = ({ dispatch, commit }, selectedStage = null) => {
|
|
|
|
commit(types.SET_SELECTED_STAGE, selectedStage);
|
|
|
|
return dispatch('refetchStageData');
|
2021-04-21 09:09:15 +00:00
|
|
|
};
|
|
|
|
|
2021-11-13 03:09:49 +00:00
|
|
|
export const setFilters = ({ dispatch }) => dispatch('refetchStageData');
|
2021-07-05 21:07:32 +00:00
|
|
|
|
2021-09-07 15:11:06 +00:00
|
|
|
export const setDateRange = ({ dispatch, commit }, { createdAfter, createdBefore }) => {
|
|
|
|
commit(types.SET_DATE_RANGE, { createdAfter, createdBefore });
|
2021-11-13 03:09:49 +00:00
|
|
|
return dispatch('refetchStageData');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const setInitialStage = ({ dispatch, commit, state: { stages } }, stage) => {
|
2022-08-09 03:11:51 +00:00
|
|
|
if (!stages.length && !stage) {
|
|
|
|
commit(types.SET_NO_ACCESS_ERROR);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-11-13 03:09:49 +00:00
|
|
|
const selectedStage = stage || stages[0];
|
|
|
|
commit(types.SET_SELECTED_STAGE, selectedStage);
|
|
|
|
return dispatch('fetchValueStreamStageData');
|
2021-06-11 15:09:58 +00:00
|
|
|
};
|
2021-04-21 09:09:15 +00:00
|
|
|
|
2021-10-12 15:12:08 +00:00
|
|
|
export const updateStageTablePagination = (
|
|
|
|
{ commit, dispatch, state: { selectedStage } },
|
|
|
|
paginationParams,
|
|
|
|
) => {
|
|
|
|
commit(types.SET_PAGINATION, paginationParams);
|
|
|
|
return dispatch('fetchStageData', selectedStage.id);
|
|
|
|
};
|
|
|
|
|
2021-11-13 03:09:49 +00:00
|
|
|
export const initializeVsa = async ({ commit, dispatch }, initialData = {}) => {
|
2021-04-21 09:09:15 +00:00
|
|
|
commit(types.INITIALIZE_VSA, initialData);
|
2021-08-04 18:09:57 +00:00
|
|
|
|
2021-09-07 15:11:06 +00:00
|
|
|
const {
|
|
|
|
endpoints: { fullPath, groupPath, milestonesPath = '', labelsPath = '' },
|
2021-11-13 03:09:49 +00:00
|
|
|
selectedAuthor,
|
|
|
|
selectedMilestone,
|
|
|
|
selectedAssigneeList,
|
|
|
|
selectedLabelList,
|
|
|
|
selectedStage = null,
|
2021-09-07 15:11:06 +00:00
|
|
|
} = initialData;
|
2021-11-13 03:09:49 +00:00
|
|
|
|
2021-09-07 15:11:06 +00:00
|
|
|
dispatch('filters/setEndpoints', {
|
2021-09-17 18:11:44 +00:00
|
|
|
labelsEndpoint: labelsPath,
|
|
|
|
milestonesEndpoint: milestonesPath,
|
2021-09-07 15:11:06 +00:00
|
|
|
groupEndpoint: groupPath,
|
|
|
|
projectEndpoint: fullPath,
|
|
|
|
});
|
|
|
|
|
2021-11-13 03:09:49 +00:00
|
|
|
dispatch('filters/initialize', {
|
|
|
|
selectedAuthor,
|
|
|
|
selectedMilestone,
|
|
|
|
selectedAssigneeList,
|
|
|
|
selectedLabelList,
|
|
|
|
});
|
|
|
|
|
|
|
|
commit(types.SET_LOADING, true);
|
|
|
|
await dispatch('fetchValueStreams');
|
|
|
|
await dispatch('setInitialStage', selectedStage);
|
|
|
|
commit(types.SET_LOADING, false);
|
2021-04-21 09:09:15 +00:00
|
|
|
};
|