Commit 652867ef authored by Ezekiel Kigbo's avatar Ezekiel Kigbo Committed by Simon Knox

Update cycle analytics method parameters

Updates method calls with 3+ params
to take an object
parent 742ce87c
......@@ -53,16 +53,16 @@ export const receiveStageDataError = ({ commit }) => {
createFlash(__('There was an error fetching data for the selected stage'));
};
export const fetchStageData = ({ dispatch, getters }, slug) => {
export const fetchStageData = ({ dispatch, getters }, stageId) => {
const { cycleAnalyticsRequestParams = {}, currentValueStreamId, currentGroupPath } = getters;
dispatch('requestStageData');
return Api.cycleAnalyticsStageEvents(
currentGroupPath,
currentValueStreamId,
slug,
return Api.cycleAnalyticsStageEvents({
groupId: currentGroupPath,
valueStreamId: currentValueStreamId,
stageId,
cycleAnalyticsRequestParams,
)
})
.then(({ data }) => dispatch('receiveStageDataSuccess', data))
.catch(error => dispatch('receiveStageDataError', error));
};
......@@ -77,13 +77,11 @@ export const receiveStageMedianValuesError = ({ commit }) => {
createFlash(__('There was an error fetching median data for stages'));
};
const fetchStageMedian = (currentGroupPath, currentValueStreamId, stageId, params) =>
Api.cycleAnalyticsStageMedian(currentGroupPath, currentValueStreamId, stageId, params).then(
({ data }) => ({
const fetchStageMedian = ({ groupId, valueStreamId, stageId, params }) =>
Api.cycleAnalyticsStageMedian({ groupId, valueStreamId, stageId, params }).then(({ data }) => ({
id: stageId,
...data,
}),
);
}));
export const fetchStageMedianValues = ({ dispatch, getters }) => {
const {
......@@ -97,12 +95,12 @@ export const fetchStageMedianValues = ({ dispatch, getters }) => {
dispatch('requestStageMedianValues');
return Promise.all(
stageIds.map(stageId =>
fetchStageMedian(
currentGroupPath,
currentValueStreamId,
fetchStageMedian({
groupId: currentGroupPath,
valueStreamId: currentValueStreamId,
stageId,
cycleAnalyticsRequestParams,
),
}),
),
)
.then(data => dispatch('receiveStageMedianValuesSuccess', data))
......@@ -182,9 +180,13 @@ export const fetchGroupStagesAndEvents = ({ dispatch, getters }) => {
dispatch('requestGroupStages');
dispatch('customStages/setStageEvents', []);
return Api.cycleAnalyticsGroupStagesAndEvents(groupId, valueStreamId, {
return Api.cycleAnalyticsGroupStagesAndEvents({
groupId,
valueStreamId,
data: {
start_date: created_after,
project_ids,
},
})
.then(({ data: { stages = [], events = [] } }) => {
dispatch('receiveGroupStagesSuccess', stages);
......@@ -232,7 +234,12 @@ export const updateStage = ({ dispatch, getters }, { id, ...params }) => {
dispatch('requestUpdateStage');
dispatch('customStages/setSavingCustomStage');
return Api.cycleAnalyticsUpdateStage(currentGroupPath, currentValueStreamId, id, params)
return Api.cycleAnalyticsUpdateStage({
groupId: currentGroupPath,
valueStreamId: currentValueStreamId,
stageId: id,
data: params,
})
.then(({ data }) => dispatch('receiveUpdateStageSuccess', data))
.catch(({ response: { status = httpStatus.BAD_REQUEST, data: responseData } = {} }) =>
dispatch('receiveUpdateStageError', { status, responseData, data: { id, ...params } }),
......@@ -255,7 +262,11 @@ export const removeStage = ({ dispatch, getters }, stageId) => {
const { currentGroupPath, currentValueStreamId } = getters;
dispatch('requestRemoveStage');
return Api.cycleAnalyticsRemoveStage(currentGroupPath, currentValueStreamId, stageId)
return Api.cycleAnalyticsRemoveStage({
groupId: currentGroupPath,
valueStreamId: currentValueStreamId,
stageId,
})
.then(() => dispatch('receiveRemoveStageSuccess'))
.catch(error => dispatch('receiveRemoveStageError', error));
};
......@@ -312,7 +323,12 @@ export const reorderStage = ({ dispatch, getters }, initialData) => {
const params = moveAfterId ? { move_after_id: moveAfterId } : { move_before_id: moveBeforeId };
return Api.cycleAnalyticsUpdateStage(currentGroupPath, currentValueStreamId, id, params)
return Api.cycleAnalyticsUpdateStage({
groupId: currentGroupPath,
valueStreamId: currentValueStreamId,
stageId: id,
data: params,
})
.then(({ data }) => dispatch('receiveReorderStageSuccess', data))
.catch(({ response: { status = httpStatus.BAD_REQUEST, data: responseData } = {} }) =>
dispatch('receiveReorderStageError', { status, responseData }),
......
......@@ -71,7 +71,11 @@ export const createStage = ({ dispatch, rootGetters }, data) => {
dispatch('clearFormErrors');
dispatch('setSavingCustomStage');
return Api.cycleAnalyticsCreateStage(currentGroupPath, currentValueStreamId, data)
return Api.cycleAnalyticsCreateStage({
groupId: currentGroupPath,
valueStreamId: currentValueStreamId,
data,
})
.then(response => {
const { status, data: responseData } = response;
return dispatch('receiveCreateStageSuccess', { status, data: responseData });
......
......@@ -24,12 +24,12 @@ export const fetchDurationData = ({ dispatch, commit, rootGetters }) => {
activeStages.map(stage => {
const { slug } = stage;
return Api.cycleAnalyticsDurationChart(
currentGroupPath,
currentValueStreamId,
slug,
return Api.cycleAnalyticsDurationChart({
groupId: currentGroupPath,
valueStreamId: currentValueStreamId,
stageId: slug,
cycleAnalyticsRequestParams,
).then(({ data }) => ({
}).then(({ data }) => ({
slug,
selected: true,
data,
......
......@@ -138,7 +138,7 @@ export default {
return axios.get(url, { params });
},
cycleAnalyticsGroupStagesAndEvents(groupId, valueStreamId, params = {}) {
cycleAnalyticsGroupStagesAndEvents({ groupId, valueStreamId, params = {} }) {
const url = Api.buildUrl(this.cycleAnalyticsGroupStagesAndEventsPath)
.replace(':id', groupId)
.replace(':value_stream_id', valueStreamId);
......@@ -146,7 +146,7 @@ export default {
return axios.get(url, { params });
},
cycleAnalyticsStageEvents(groupId, valueStreamId, stageId, params = {}) {
cycleAnalyticsStageEvents({ groupId, valueStreamId, stageId, params = {} }) {
const url = Api.buildUrl(this.cycleAnalyticsStageEventsPath)
.replace(':id', groupId)
.replace(':value_stream_id', valueStreamId)
......@@ -155,7 +155,7 @@ export default {
return axios.get(url, { params });
},
cycleAnalyticsStageMedian(groupId, valueStreamId, stageId, params = {}) {
cycleAnalyticsStageMedian({ groupId, valueStreamId, stageId, params = {} }) {
const url = Api.buildUrl(this.cycleAnalyticsStageMedianPath)
.replace(':id', groupId)
.replace(':value_stream_id', valueStreamId)
......@@ -164,7 +164,7 @@ export default {
return axios.get(url, { params: { ...params } });
},
cycleAnalyticsCreateStage(groupId, valueStreamId, data) {
cycleAnalyticsCreateStage({ groupId, valueStreamId, data }) {
const url = Api.buildUrl(this.cycleAnalyticsGroupStagesAndEventsPath)
.replace(':id', groupId)
.replace(':value_stream_id', valueStreamId);
......@@ -182,30 +182,30 @@ export default {
return axios.get(url, data);
},
cycleAnalyticsStageUrl(groupId, valueStreamId, stageId) {
cycleAnalyticsStageUrl({ groupId, valueStreamId, stageId }) {
return Api.buildUrl(this.cycleAnalyticsStagePath)
.replace(':id', groupId)
.replace(':value_stream_id', valueStreamId)
.replace(':stage_id', stageId);
},
cycleAnalyticsUpdateStage(groupId, valueStreamId, stageId, data) {
const url = this.cycleAnalyticsStageUrl(groupId, valueStreamId, stageId);
cycleAnalyticsUpdateStage({ groupId, valueStreamId, stageId, data }) {
const url = this.cycleAnalyticsStageUrl({ groupId, valueStreamId, stageId });
return axios.put(url, data);
},
cycleAnalyticsRemoveStage(groupId, valueStreamId, stageId) {
const url = this.cycleAnalyticsStageUrl(groupId, valueStreamId, stageId);
cycleAnalyticsRemoveStage({ groupId, valueStreamId, stageId }) {
const url = this.cycleAnalyticsStageUrl({ groupId, valueStreamId, stageId });
return axios.delete(url);
},
cycleAnalyticsDurationChart(groupId, valueStreamId, stageSlug, params = {}) {
cycleAnalyticsDurationChart({ groupId, valueStreamId, stageId, params = {} }) {
const url = Api.buildUrl(this.cycleAnalyticsDurationChartPath)
.replace(':id', groupId)
.replace(':value_stream_id', valueStreamId)
.replace(':stage_id', stageSlug);
.replace(':stage_id', stageId);
return axios.get(url, {
params,
......
......@@ -381,7 +381,7 @@ describe('Api', () => {
const expectedUrl = valueStreamBaseUrl({ id: valueStreamId, resource: 'stages' });
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsGroupStagesAndEvents(groupId, valueStreamId, params)
Api.cycleAnalyticsGroupStagesAndEvents({ groupId, valueStreamId, params })
.then(responseObj =>
expectRequestWithCorrectParameters(responseObj, {
response,
......@@ -404,7 +404,7 @@ describe('Api', () => {
});
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsStageEvents(groupId, valueStreamId, stageId, params)
Api.cycleAnalyticsStageEvents({ groupId, valueStreamId, stageId, params })
.then(responseObj =>
expectRequestWithCorrectParameters(responseObj, {
response,
......@@ -427,7 +427,7 @@ describe('Api', () => {
});
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsStageMedian(groupId, valueStreamId, stageId, params)
Api.cycleAnalyticsStageMedian({ groupId, valueStreamId, stageId, params })
.then(responseObj =>
expectRequestWithCorrectParameters(responseObj, {
response,
......@@ -456,7 +456,7 @@ describe('Api', () => {
});
mock.onPost(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsCreateStage(groupId, valueStreamId, customStage)
Api.cycleAnalyticsCreateStage({ groupId, valueStreamId, data: customStage })
.then(({ data, config: { data: reqData, url } }) => {
expect(data).toEqual(response);
expect(JSON.parse(reqData)).toMatchObject(customStage);
......@@ -478,7 +478,7 @@ describe('Api', () => {
});
mock.onPut(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsUpdateStage(groupId, valueStreamId, stageId, stageData)
Api.cycleAnalyticsUpdateStage({ groupId, valueStreamId, stageId, data: stageData })
.then(({ data, config: { data: reqData, url } }) => {
expect(data).toEqual(response);
expect(JSON.parse(reqData)).toMatchObject(stageData);
......@@ -498,7 +498,7 @@ describe('Api', () => {
});
mock.onDelete(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsRemoveStage(groupId, valueStreamId, stageId)
Api.cycleAnalyticsRemoveStage({ groupId, valueStreamId, stageId })
.then(({ data, config: { url } }) => {
expect(data).toEqual(response);
......@@ -519,7 +519,7 @@ describe('Api', () => {
});
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsDurationChart(groupId, valueStreamId, stageId, params)
Api.cycleAnalyticsDurationChart({ groupId, valueStreamId, stageId, params })
.then(responseObj =>
expectRequestWithCorrectParameters(responseObj, {
response,
......
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