Commit ab819597 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo Committed by Kushal Pandya

Set the selected value stream after create

Ensure we set the newly created value
stream when the request succeeds
parent 2329d705
...@@ -336,8 +336,8 @@ export const reorderStage = ({ dispatch, getters }, initialData) => { ...@@ -336,8 +336,8 @@ export const reorderStage = ({ dispatch, getters }, initialData) => {
); );
}; };
export const receiveCreateValueStreamSuccess = ({ commit, dispatch }) => { export const receiveCreateValueStreamSuccess = ({ commit, dispatch }, valueStream = {}) => {
commit(types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS); commit(types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS, valueStream);
return dispatch('fetchCycleAnalyticsData'); return dispatch('fetchCycleAnalyticsData');
}; };
...@@ -346,7 +346,7 @@ export const createValueStream = ({ commit, dispatch, getters }, data) => { ...@@ -346,7 +346,7 @@ export const createValueStream = ({ commit, dispatch, getters }, data) => {
commit(types.REQUEST_CREATE_VALUE_STREAM); commit(types.REQUEST_CREATE_VALUE_STREAM);
return Api.cycleAnalyticsCreateValueStream(currentGroupPath, data) return Api.cycleAnalyticsCreateValueStream(currentGroupPath, data)
.then(() => dispatch('receiveCreateValueStreamSuccess')) .then(({ data: newValueStream }) => dispatch('receiveCreateValueStreamSuccess', newValueStream))
.catch(({ response } = {}) => { .catch(({ response } = {}) => {
const { data: { message, payload: { errors } } = null } = response; const { data: { message, payload: { errors } } = null } = response;
commit(types.RECEIVE_CREATE_VALUE_STREAM_ERROR, { message, errors }); commit(types.RECEIVE_CREATE_VALUE_STREAM_ERROR, { message, errors });
...@@ -372,8 +372,8 @@ export const fetchValueStreamData = ({ dispatch }) => ...@@ -372,8 +372,8 @@ export const fetchValueStreamData = ({ dispatch }) =>
.then(() => dispatch('fetchStageMedianValues')) .then(() => dispatch('fetchStageMedianValues'))
.then(() => dispatch('durationChart/fetchDurationData')); .then(() => dispatch('durationChart/fetchDurationData'));
export const setSelectedValueStream = ({ commit, dispatch }, streamId) => { export const setSelectedValueStream = ({ commit, dispatch }, valueStream) => {
commit(types.SET_SELECTED_VALUE_STREAM, streamId); commit(types.SET_SELECTED_VALUE_STREAM, valueStream);
return dispatch(FETCH_VALUE_STREAM_DATA); return dispatch(FETCH_VALUE_STREAM_DATA);
}; };
......
...@@ -124,9 +124,10 @@ export default { ...@@ -124,9 +124,10 @@ export default {
state.isCreatingValueStream = false; state.isCreatingValueStream = false;
state.createValueStreamErrors = errors; state.createValueStreamErrors = errors;
}, },
[types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS](state) { [types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS](state, valueStream) {
state.isCreatingValueStream = false; state.isCreatingValueStream = false;
state.createValueStreamErrors = {}; state.createValueStreamErrors = {};
state.selectedValueStream = convertObjectPropsToCamelCase(valueStream);
}, },
[types.REQUEST_DELETE_VALUE_STREAM](state) { [types.REQUEST_DELETE_VALUE_STREAM](state) {
state.isDeletingValueStream = true; state.isDeletingValueStream = true;
...@@ -139,9 +140,10 @@ export default { ...@@ -139,9 +140,10 @@ export default {
[types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS](state) { [types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS](state) {
state.isDeletingValueStream = false; state.isDeletingValueStream = false;
state.deleteValueStreamError = null; state.deleteValueStreamError = null;
state.selectedValueStream = null;
}, },
[types.SET_SELECTED_VALUE_STREAM](state, valueStream) { [types.SET_SELECTED_VALUE_STREAM](state, valueStream) {
state.selectedValueStream = valueStream; state.selectedValueStream = convertObjectPropsToCamelCase(valueStream);
}, },
[types.REQUEST_VALUE_STREAMS](state) { [types.REQUEST_VALUE_STREAMS](state) {
state.isLoadingValueStreams = true; state.isLoadingValueStreams = true;
......
---
title: Set selected value stream after create and delete
merge_request: 46100
author:
type: fixed
...@@ -884,6 +884,7 @@ describe('Cycle analytics actions', () => { ...@@ -884,6 +884,7 @@ describe('Cycle analytics actions', () => {
describe('createValueStream', () => { describe('createValueStream', () => {
const payload = { name: 'cool value stream' }; const payload = { name: 'cool value stream' };
const createResp = { id: 'new value stream', is_custom: true, ...payload };
beforeEach(() => { beforeEach(() => {
state = { currentGroup }; state = { currentGroup };
...@@ -891,7 +892,7 @@ describe('Cycle analytics actions', () => { ...@@ -891,7 +892,7 @@ describe('Cycle analytics actions', () => {
describe('with no errors', () => { describe('with no errors', () => {
beforeEach(() => { beforeEach(() => {
mock.onPost(endpoints.valueStreamData).replyOnce(httpStatusCodes.OK, {}); mock.onPost(endpoints.valueStreamData).replyOnce(httpStatusCodes.OK, createResp);
}); });
it(`commits the ${types.REQUEST_CREATE_VALUE_STREAM} and ${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} actions`, () => { it(`commits the ${types.REQUEST_CREATE_VALUE_STREAM} and ${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} actions`, () => {
...@@ -904,7 +905,7 @@ describe('Cycle analytics actions', () => { ...@@ -904,7 +905,7 @@ describe('Cycle analytics actions', () => {
type: types.REQUEST_CREATE_VALUE_STREAM, type: types.REQUEST_CREATE_VALUE_STREAM,
}, },
], ],
[{ type: 'receiveCreateValueStreamSuccess' }], [{ type: 'receiveCreateValueStreamSuccess', payload: createResp }],
); );
}); });
}); });
......
...@@ -52,6 +52,7 @@ describe('Cycle analytics mutations', () => { ...@@ -52,6 +52,7 @@ describe('Cycle analytics mutations', () => {
${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} | ${'isDeletingValueStream'} | ${false} ${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} | ${'isDeletingValueStream'} | ${false}
${types.REQUEST_DELETE_VALUE_STREAM} | ${'deleteValueStreamError'} | ${null} ${types.REQUEST_DELETE_VALUE_STREAM} | ${'deleteValueStreamError'} | ${null}
${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} | ${'deleteValueStreamError'} | ${null} ${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} | ${'deleteValueStreamError'} | ${null}
${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} | ${'selectedValueStream'} | ${null}
${types.INITIALIZE_CYCLE_ANALYTICS_SUCCESS} | ${'isLoading'} | ${false} ${types.INITIALIZE_CYCLE_ANALYTICS_SUCCESS} | ${'isLoading'} | ${false}
`('$mutation will set $stateKey=$value', ({ mutation, stateKey, value }) => { `('$mutation will set $stateKey=$value', ({ mutation, stateKey, value }) => {
mutations[mutation](state); mutations[mutation](state);
...@@ -60,15 +61,16 @@ describe('Cycle analytics mutations', () => { ...@@ -60,15 +61,16 @@ describe('Cycle analytics mutations', () => {
}); });
it.each` it.each`
mutation | payload | expectedState mutation | payload | expectedState
${types.SET_FEATURE_FLAGS} | ${{ hasDurationChart: true }} | ${{ featureFlags: { hasDurationChart: true } }} ${types.SET_FEATURE_FLAGS} | ${{ hasDurationChart: true }} | ${{ featureFlags: { hasDurationChart: true } }}
${types.SET_SELECTED_PROJECTS} | ${selectedProjects} | ${{ selectedProjects }} ${types.SET_SELECTED_PROJECTS} | ${selectedProjects} | ${{ selectedProjects }}
${types.SET_DATE_RANGE} | ${{ startDate, endDate }} | ${{ startDate, endDate }} ${types.SET_DATE_RANGE} | ${{ startDate, endDate }} | ${{ startDate, endDate }}
${types.SET_SELECTED_STAGE} | ${{ id: 'first-stage' }} | ${{ selectedStage: { id: 'first-stage' } }} ${types.SET_SELECTED_STAGE} | ${{ id: 'first-stage' }} | ${{ selectedStage: { id: 'first-stage' } }}
${types.RECEIVE_CREATE_VALUE_STREAM_ERROR} | ${{ errors: { name: ['is required'] } }} | ${{ createValueStreamErrors: { name: ['is required'] }, isCreatingValueStream: false }} ${types.RECEIVE_CREATE_VALUE_STREAM_ERROR} | ${{ errors: { name: ['is required'] } }} | ${{ createValueStreamErrors: { name: ['is required'] }, isCreatingValueStream: false }}
${types.RECEIVE_DELETE_VALUE_STREAM_ERROR} | ${'Some error occurred'} | ${{ deleteValueStreamError: 'Some error occurred' }} ${types.RECEIVE_DELETE_VALUE_STREAM_ERROR} | ${'Some error occurred'} | ${{ deleteValueStreamError: 'Some error occurred' }}
${types.RECEIVE_VALUE_STREAMS_SUCCESS} | ${valueStreams} | ${{ valueStreams, isLoadingValueStreams: false }} ${types.RECEIVE_VALUE_STREAMS_SUCCESS} | ${valueStreams} | ${{ valueStreams, isLoadingValueStreams: false }}
${types.SET_SELECTED_VALUE_STREAM} | ${valueStreams[1].id} | ${{ selectedValueStream: {} }} ${types.SET_SELECTED_VALUE_STREAM} | ${valueStreams[1].id} | ${{ selectedValueStream: {} }}
${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} | ${valueStreams[1]} | ${{ selectedValueStream: valueStreams[1] }}
`( `(
'$mutation with payload $payload will update state with $expectedState', '$mutation with payload $payload will update state with $expectedState',
({ mutation, payload, expectedState }) => { ({ mutation, payload, expectedState }) => {
......
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