Commit 22e633d2 authored by Kushal Pandya's avatar Kushal Pandya Committed by Heinrich Lee Yu

Use API query param to fetch ancestor group epics

Adds `include_ancestor_groups` & `include_descendant_groups` query
params support to group epics fetch API.
parent e2163d19
...@@ -7,7 +7,8 @@ export default { ...@@ -7,7 +7,8 @@ export default {
ldapGroupsPath: '/api/:version/ldap/:provider/groups.json', ldapGroupsPath: '/api/:version/ldap/:provider/groups.json',
subscriptionPath: '/api/:version/namespaces/:id/gitlab_subscription', subscriptionPath: '/api/:version/namespaces/:id/gitlab_subscription',
childEpicPath: '/api/:version/groups/:id/epics/:epic_iid/epics', childEpicPath: '/api/:version/groups/:id/epics/:epic_iid/epics',
groupEpicsPath: '/api/:version/groups/:id/epics', groupEpicsPath:
'/api/:version/groups/:id/epics?include_ancestor_groups=:includeAncestorGroups&include_descendant_groups=:includeDescendantGroups',
epicIssuePath: '/api/:version/groups/:id/epics/:epic_iid/issues/:issue_id', epicIssuePath: '/api/:version/groups/:id/epics/:epic_iid/issues/:issue_id',
userSubscription(namespaceId) { userSubscription(namespaceId) {
...@@ -43,8 +44,11 @@ export default { ...@@ -43,8 +44,11 @@ export default {
}); });
}, },
groupEpics({ groupId }) { groupEpics({ groupId, includeAncestorGroups = false, includeDescendantGroups = true }) {
const url = Api.buildUrl(this.groupEpicsPath).replace(':id', groupId); const url = Api.buildUrl(this.groupEpicsPath)
.replace(':id', groupId)
.replace(':includeAncestorGroups', includeAncestorGroups)
.replace(':includeDescendantGroups', includeDescendantGroups);
return axios.get(url); return axios.get(url);
}, },
......
...@@ -17,14 +17,12 @@ export const setSelectedEpic = ({ commit }, selectedEpic) => ...@@ -17,14 +17,12 @@ export const setSelectedEpic = ({ commit }, selectedEpic) =>
commit(types.SET_SELECTED_EPIC, selectedEpic); commit(types.SET_SELECTED_EPIC, selectedEpic);
export const requestEpics = ({ commit }) => commit(types.REQUEST_EPICS); export const requestEpics = ({ commit }) => commit(types.REQUEST_EPICS);
export const receiveEpicsSuccess = ({ state, commit }, data) => { export const receiveEpicsSuccess = ({ commit }, data) => {
const epics = data const epics = data.map(rawEpic =>
.filter(rawEpic => rawEpic.group_id === state.groupId) convertObjectPropsToCamelCase(Object.assign({}, rawEpic, { url: rawEpic.web_edit_url }), {
.map(rawEpic => dropKeys: ['web_edit_url'],
convertObjectPropsToCamelCase(Object.assign(rawEpic, { url: rawEpic.web_edit_url }), { }),
dropKeys: ['web_edit_url'], );
}),
);
commit(types.RECEIVE_EPICS_SUCCESS, { epics }); commit(types.RECEIVE_EPICS_SUCCESS, { epics });
}; };
...@@ -37,6 +35,8 @@ export const fetchEpics = ({ state, dispatch }) => { ...@@ -37,6 +35,8 @@ export const fetchEpics = ({ state, dispatch }) => {
Api.groupEpics({ Api.groupEpics({
groupId: state.groupId, groupId: state.groupId,
includeDescendantGroups: false,
includeAncestorGroups: true,
}) })
.then(({ data }) => { .then(({ data }) => {
dispatch('receiveEpicsSuccess', data); dispatch('receiveEpicsSuccess', data);
......
...@@ -88,7 +88,7 @@ describe('Api', () => { ...@@ -88,7 +88,7 @@ describe('Api', () => {
describe('groupEpics', () => { describe('groupEpics', () => {
it('calls `axios.get` using param `groupId`', done => { it('calls `axios.get` using param `groupId`', done => {
const groupId = 2; const groupId = 2;
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/epics`; const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/epics?include_ancestor_groups=false&include_descendant_groups=true`;
mock.onGet(expectedUrl).reply(200, mockEpics); mock.onGet(expectedUrl).reply(200, mockEpics);
......
...@@ -184,7 +184,11 @@ describe('EpicsSelect', () => { ...@@ -184,7 +184,11 @@ describe('EpicsSelect', () => {
dispatch: () => {}, dispatch: () => {},
}); });
expect(Api.groupEpics).toHaveBeenCalledWith({ groupId: state.groupId }); expect(Api.groupEpics).toHaveBeenCalledWith({
groupId: state.groupId,
includeDescendantGroups: false,
includeAncestorGroups: true,
});
}); });
}); });
......
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