Commit 1ca52df4 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '221205-delete-value-stream-vuex' into 'master'

VSA delete value stream api request

See merge request gitlab-org/gitlab!41057
parents 51978267 275cba91
......@@ -352,6 +352,19 @@ export const createValueStream = ({ commit, dispatch, getters }, data) => {
});
};
export const deleteValueStream = ({ commit, dispatch, getters }, valueStreamId) => {
const { currentGroupPath } = getters;
commit(types.REQUEST_DELETE_VALUE_STREAM);
return Api.cycleAnalyticsDeleteValueStream(currentGroupPath, valueStreamId)
.then(() => commit(types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS))
.then(() => dispatch('fetchCycleAnalyticsData'))
.catch(({ response } = {}) => {
const { data: { message } = null } = response;
commit(types.RECEIVE_DELETE_VALUE_STREAM_ERROR, message);
});
};
export const fetchValueStreamData = ({ dispatch }) =>
Promise.resolve()
.then(() => dispatch('fetchGroupStagesAndEvents'))
......
......@@ -40,6 +40,10 @@ export const REQUEST_CREATE_VALUE_STREAM = 'REQUEST_CREATE_VALUE_STREAM';
export const RECEIVE_CREATE_VALUE_STREAM_SUCCESS = 'RECEIVE_CREATE_VALUE_STREAM_SUCCESS';
export const RECEIVE_CREATE_VALUE_STREAM_ERROR = 'RECEIVE_CREATE_VALUE_STREAM_ERROR';
export const REQUEST_DELETE_VALUE_STREAM = 'REQUEST_DELETE_VALUE_STREAM';
export const RECEIVE_DELETE_VALUE_STREAM_SUCCESS = 'RECEIVE_DELETE_VALUE_STREAM_SUCCESS';
export const RECEIVE_DELETE_VALUE_STREAM_ERROR = 'RECEIVE_DELETE_VALUE_STREAM_ERROR';
export const REQUEST_VALUE_STREAMS = 'REQUEST_VALUE_STREAMS';
export const RECEIVE_VALUE_STREAMS_SUCCESS = 'RECEIVE_VALUE_STREAMS_SUCCESS';
export const RECEIVE_VALUE_STREAMS_ERROR = 'RECEIVE_VALUE_STREAMS_ERROR';
......@@ -127,6 +127,18 @@ export default {
state.isCreatingValueStream = false;
state.createValueStreamErrors = {};
},
[types.REQUEST_DELETE_VALUE_STREAM](state) {
state.isDeletingValueStream = true;
state.deleteValueStreamError = null;
},
[types.RECEIVE_DELETE_VALUE_STREAM_ERROR](state, message) {
state.isDeletingValueStream = false;
state.deleteValueStreamError = message;
},
[types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS](state) {
state.isDeletingValueStream = false;
state.deleteValueStreamError = null;
},
[types.SET_SELECTED_VALUE_STREAM](state, streamId) {
state.selectedValueStream = state.valueStreams?.find(({ id }) => id === streamId) || null;
},
......@@ -141,8 +153,10 @@ export default {
},
[types.RECEIVE_VALUE_STREAMS_SUCCESS](state, data) {
state.isLoadingValueStreams = false;
state.valueStreams = data.sort(({ name: aName = '' }, { name: bName = '' }) => {
return aName.toUpperCase() > bName.toUpperCase() ? 1 : -1;
});
state.valueStreams = data
.map(convertObjectPropsToCamelCase)
.sort(({ name: aName = '' }, { name: bName = '' }) => {
return aName.toUpperCase() > bName.toUpperCase() ? 1 : -1;
});
},
};
......@@ -22,7 +22,10 @@ export default () => ({
isLoadingValueStreams: false,
isCreatingValueStream: false,
isDeletingValueStream: false,
createValueStreamErrors: {},
deleteValueStreamError: null,
stages: [],
summary: [],
......
......@@ -17,6 +17,8 @@ export default {
cycleAnalyticsGroupStagesAndEventsPath:
'/groups/:id/-/analytics/value_stream_analytics/value_streams/:value_stream_id/stages',
cycleAnalyticsValueStreamsPath: '/groups/:id/-/analytics/value_stream_analytics/value_streams',
cycleAnalyticsValueStreamPath:
'/groups/:id/-/analytics/value_stream_analytics/value_streams/:value_stream_id',
cycleAnalyticsStageEventsPath:
'/groups/:id/-/analytics/value_stream_analytics/value_streams/:value_stream_id/stages/:stage_id/records',
cycleAnalyticsStageMedianPath:
......@@ -177,6 +179,13 @@ export default {
return axios.post(url, data);
},
cycleAnalyticsDeleteValueStream(groupId, valueStreamId) {
const url = Api.buildUrl(this.cycleAnalyticsValueStreamPath)
.replace(':id', groupId)
.replace(':value_stream_id', valueStreamId);
return axios.delete(url);
},
cycleAnalyticsValueStreams(groupId, data) {
const url = Api.buildUrl(this.cycleAnalyticsValueStreamsPath).replace(':id', groupId);
return axios.get(url, data);
......
......@@ -1019,6 +1019,61 @@ describe('Cycle analytics actions', () => {
});
});
describe('deleteValueStream', () => {
const payload = 'my-fake-value-stream';
beforeEach(() => {
state = { selectedGroup };
});
describe('with no errors', () => {
beforeEach(() => {
mock.onDelete(endpoints.valueStreamData).replyOnce(httpStatusCodes.OK, {});
});
it(`commits the ${types.REQUEST_DELETE_VALUE_STREAM} and ${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} actions`, () => {
return testAction(
actions.deleteValueStream,
payload,
state,
[
{
type: types.REQUEST_DELETE_VALUE_STREAM,
},
{
type: types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS,
},
],
[{ type: 'fetchCycleAnalyticsData' }],
);
});
});
describe('with errors', () => {
const message = { message: 'failed to delete the value stream' };
const resp = { message };
beforeEach(() => {
mock.onDelete(endpoints.valueStreamData).replyOnce(httpStatusCodes.NOT_FOUND, resp);
});
it(`commits the ${types.REQUEST_DELETE_VALUE_STREAM} and ${types.RECEIVE_DELETE_VALUE_STREAM_ERROR} actions `, () => {
return testAction(
actions.deleteValueStream,
payload,
state,
[
{ type: types.REQUEST_DELETE_VALUE_STREAM },
{
type: types.RECEIVE_DELETE_VALUE_STREAM_ERROR,
payload: message,
},
],
[],
);
});
});
});
describe('fetchValueStreams', () => {
beforeEach(() => {
state = {
......
......@@ -49,6 +49,10 @@ describe('Cycle analytics mutations', () => {
${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} | ${'isCreatingValueStream'} | ${false}
${types.REQUEST_CREATE_VALUE_STREAM} | ${'createValueStreamErrors'} | ${{}}
${types.RECEIVE_CREATE_VALUE_STREAM_SUCCESS} | ${'createValueStreamErrors'} | ${{}}
${types.REQUEST_DELETE_VALUE_STREAM} | ${'isDeletingValueStream'} | ${true}
${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} | ${'isDeletingValueStream'} | ${false}
${types.REQUEST_DELETE_VALUE_STREAM} | ${'deleteValueStreamError'} | ${null}
${types.RECEIVE_DELETE_VALUE_STREAM_SUCCESS} | ${'deleteValueStreamError'} | ${null}
${types.INITIALIZE_CYCLE_ANALYTICS_SUCCESS} | ${'isLoading'} | ${false}
`('$mutation will set $stateKey=$value', ({ mutation, stateKey, value }) => {
mutations[mutation](state);
......@@ -64,6 +68,7 @@ describe('Cycle analytics mutations', () => {
${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: {} }}
`(
......
......@@ -370,6 +370,22 @@ describe('Api', () => {
});
});
describe('cycleAnalyticsDeleteValueStream', () => {
it('delete the custom value stream', done => {
const response = {};
const expectedUrl = valueStreamBaseUrl({ resource: `value_streams/${valueStreamId}` });
mock.onDelete(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsDeleteValueStream(groupId, valueStreamId)
.then(({ data, config: { url } }) => {
expect(data).toEqual(response);
expect(url).toEqual(expectedUrl);
})
.then(done)
.catch(done.fail);
});
});
describe('cycleAnalyticsGroupStagesAndEvents', () => {
it('fetches custom stage events and all stages', done => {
const response = { events: [], stages: [] };
......
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