Commit 8ce3a303 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '263392-update-selected-value-stream-after-deletion' into 'master'

Update selected value stream after deletion or creation

See merge request gitlab-org/gitlab!46100
parents 654abb72 ab819597
......@@ -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);
};
......
......@@ -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;
......
---
title: Set selected value stream after create and delete
merge_request: 46100
author:
type: fixed
......@@ -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 }],
);
});
});
......
......@@ -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);
......@@ -69,6 +70,7 @@ describe('Cycle analytics mutations', () => {
${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 }) => {
......
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