diff --git a/ee/app/assets/javascripts/analytics/cycle_analytics/store/actions.js b/ee/app/assets/javascripts/analytics/cycle_analytics/store/actions.js index d266c94306c4972d78ca45c31433fafc4bf347ed..779ee3c2783648eba080ed24a0036d286574baea 100644 --- a/ee/app/assets/javascripts/analytics/cycle_analytics/store/actions.js +++ b/ee/app/assets/javascripts/analytics/cycle_analytics/store/actions.js @@ -336,8 +336,8 @@ export const reorderStage = ({ dispatch, getters }, initialData) => { ); }; -export const receiveCreateValueStreamSuccess = ({ commit, dispatch }) => { - commit(types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS); +export const receiveCreateValueStreamSuccess = ({ commit, dispatch }, valueStream = {}) => { + commit(types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS, valueStream); return dispatch('fetchCycleAnalyticsData'); }; @@ -346,7 +346,7 @@ export const createValueStream = ({ commit, dispatch, getters }, data) => { commit(types.REQUEST_CREATE_VALUE_STREAM); return Api.cycleAnalyticsCreateValueStream(currentGroupPath, data) - .then(() => dispatch('receiveCreateValueStreamSuccess')) + .then(({ data: newValueStream }) => dispatch('receiveCreateValueStreamSuccess', newValueStream)) .catch(({ response } = {}) => { const { data: { message, payload: { errors } } = null } = response; commit(types.RECEIVE_CREATE_VALUE_STREAM_ERROR, { message, errors }); @@ -372,8 +372,8 @@ export const fetchValueStreamData = ({ dispatch }) => .then(() => dispatch('fetchStageMedianValues')) .then(() => dispatch('durationChart/fetchDurationData')); -export const setSelectedValueStream = ({ commit, dispatch }, streamId) => { - commit(types.SET_SELECTED_VALUE_STREAM, streamId); +export const setSelectedValueStream = ({ commit, dispatch }, valueStream) => { + commit(types.SET_SELECTED_VALUE_STREAM, valueStream); return dispatch(FETCH_VALUE_STREAM_DATA); }; diff --git a/ee/app/assets/javascripts/analytics/cycle_analytics/store/mutations.js b/ee/app/assets/javascripts/analytics/cycle_analytics/store/mutations.js index eeda334096f427732d917f6f88044c73a693d4e3..226c37656da32d8ed4f6e3a80174d18156221360 100644 --- a/ee/app/assets/javascripts/analytics/cycle_analytics/store/mutations.js +++ b/ee/app/assets/javascripts/analytics/cycle_analytics/store/mutations.js @@ -124,9 +124,10 @@ export default { state.isCreatingValueStream = false; state.createValueStreamErrors = errors; }, - [types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS](state) { + [types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS](state, valueStream) { state.isCreatingValueStream = false; state.createValueStreamErrors = {}; + state.selectedValueStream = convertObjectPropsToCamelCase(valueStream); }, [types.REQUEST_DELETE_VALUE_STREAM](state) { state.isDeletingValueStream = true; @@ -139,9 +140,10 @@ export default { [types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS](state) { state.isDeletingValueStream = false; state.deleteValueStreamError = null; + state.selectedValueStream = null; }, [types.SET_SELECTED_VALUE_STREAM](state, valueStream) { - state.selectedValueStream = valueStream; + state.selectedValueStream = convertObjectPropsToCamelCase(valueStream); }, [types.REQUEST_VALUE_STREAMS](state) { state.isLoadingValueStreams = true; diff --git a/ee/changelogs/unreleased/263392-update-selected-value-stream-after-deletion.yml b/ee/changelogs/unreleased/263392-update-selected-value-stream-after-deletion.yml new file mode 100644 index 0000000000000000000000000000000000000000..c9c468ae031b033766874b1f080bddf60f1b95f9 --- /dev/null +++ b/ee/changelogs/unreleased/263392-update-selected-value-stream-after-deletion.yml @@ -0,0 +1,5 @@ +--- +title: Set selected value stream after create and delete +merge_request: 46100 +author: +type: fixed diff --git a/ee/spec/frontend/analytics/cycle_analytics/store/actions_spec.js b/ee/spec/frontend/analytics/cycle_analytics/store/actions_spec.js index 71958ed905fccab399d5930cf892a94750c0cd6e..02540550b1f1c4c2bdfb855c42e71b32c73f2af9 100644 --- a/ee/spec/frontend/analytics/cycle_analytics/store/actions_spec.js +++ b/ee/spec/frontend/analytics/cycle_analytics/store/actions_spec.js @@ -884,6 +884,7 @@ describe('Cycle analytics actions', () => { describe('createValueStream', () => { const payload = { name: 'cool value stream' }; + const createResp = { id: 'new value stream', is_custom: true, ...payload }; beforeEach(() => { state = { currentGroup }; @@ -891,7 +892,7 @@ describe('Cycle analytics actions', () => { describe('with no errors', () => { 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`, () => { @@ -904,7 +905,7 @@ describe('Cycle analytics actions', () => { type: types.REQUEST_CREATE_VALUE_STREAM, }, ], - [{ type: 'receiveCreateValueStreamSuccess' }], + [{ type: 'receiveCreateValueStreamSuccess', payload: createResp }], ); }); }); diff --git a/ee/spec/frontend/analytics/cycle_analytics/store/mutations_spec.js b/ee/spec/frontend/analytics/cycle_analytics/store/mutations_spec.js index 38aa6943a3308a84e0ac9a39b93137d150b857fa..9fe0d89d4845562e97e9d33e7b1e723950bf1cfe 100644 --- a/ee/spec/frontend/analytics/cycle_analytics/store/mutations_spec.js +++ b/ee/spec/frontend/analytics/cycle_analytics/store/mutations_spec.js @@ -52,6 +52,7 @@ describe('Cycle analytics mutations', () => { ${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} | ${'isDeletingValueStream'} | ${false} ${types.REQUEST_DELETE_VALUE_STREAM} | ${'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} `('$mutation will set $stateKey=$value', ({ mutation, stateKey, value }) => { mutations[mutation](state); @@ -60,15 +61,16 @@ describe('Cycle analytics mutations', () => { }); it.each` - mutation | payload | expectedState - ${types.SET_FEATURE_FLAGS} | ${{ hasDurationChart: true }} | ${{ featureFlags: { hasDurationChart: true } }} - ${types.SET_SELECTED_PROJECTS} | ${selectedProjects} | ${{ selectedProjects }} - ${types.SET_DATE_RANGE} | ${{ startDate, endDate }} | ${{ startDate, endDate }} - ${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_DELETE_VALUE_STREAM_ERROR} | ${'Some error occurred'} | ${{ deleteValueStreamError: 'Some error occurred' }} - ${types.RECEIVE_VALUE_STREAMS_SUCCESS} | ${valueStreams} | ${{ valueStreams, isLoadingValueStreams: false }} - ${types.SET_SELECTED_VALUE_STREAM} | ${valueStreams[1].id} | ${{ selectedValueStream: {} }} + mutation | payload | expectedState + ${types.SET_FEATURE_FLAGS} | ${{ hasDurationChart: true }} | ${{ featureFlags: { hasDurationChart: true } }} + ${types.SET_SELECTED_PROJECTS} | ${selectedProjects} | ${{ selectedProjects }} + ${types.SET_DATE_RANGE} | ${{ startDate, endDate }} | ${{ startDate, endDate }} + ${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_DELETE_VALUE_STREAM_ERROR} | ${'Some error occurred'} | ${{ deleteValueStreamError: 'Some error occurred' }} + ${types.RECEIVE_VALUE_STREAMS_SUCCESS} | ${valueStreams} | ${{ valueStreams, isLoadingValueStreams: false }} + ${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, payload, expectedState }) => {