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 {
ldapGroupsPath: '/api/:version/ldap/:provider/groups.json',
subscriptionPath: '/api/:version/namespaces/:id/gitlab_subscription',
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',
userSubscription(namespaceId) {
......@@ -43,8 +44,11 @@ export default {
});
},
groupEpics({ groupId }) {
const url = Api.buildUrl(this.groupEpicsPath).replace(':id', groupId);
groupEpics({ groupId, includeAncestorGroups = false, includeDescendantGroups = true }) {
const url = Api.buildUrl(this.groupEpicsPath)
.replace(':id', groupId)
.replace(':includeAncestorGroups', includeAncestorGroups)
.replace(':includeDescendantGroups', includeDescendantGroups);
return axios.get(url);
},
......
......@@ -17,14 +17,12 @@ export const setSelectedEpic = ({ commit }, selectedEpic) =>
commit(types.SET_SELECTED_EPIC, selectedEpic);
export const requestEpics = ({ commit }) => commit(types.REQUEST_EPICS);
export const receiveEpicsSuccess = ({ state, commit }, data) => {
const epics = data
.filter(rawEpic => rawEpic.group_id === state.groupId)
.map(rawEpic =>
convertObjectPropsToCamelCase(Object.assign(rawEpic, { url: rawEpic.web_edit_url }), {
dropKeys: ['web_edit_url'],
}),
);
export const receiveEpicsSuccess = ({ commit }, data) => {
const epics = data.map(rawEpic =>
convertObjectPropsToCamelCase(Object.assign({}, rawEpic, { url: rawEpic.web_edit_url }), {
dropKeys: ['web_edit_url'],
}),
);
commit(types.RECEIVE_EPICS_SUCCESS, { epics });
};
......@@ -37,6 +35,8 @@ export const fetchEpics = ({ state, dispatch }) => {
Api.groupEpics({
groupId: state.groupId,
includeDescendantGroups: false,
includeAncestorGroups: true,
})
.then(({ data }) => {
dispatch('receiveEpicsSuccess', data);
......
......@@ -88,7 +88,7 @@ describe('Api', () => {
describe('groupEpics', () => {
it('calls `axios.get` using param `groupId`', done => {
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);
......
......@@ -184,7 +184,11 @@ describe('EpicsSelect', () => {
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