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