Commit 60733162 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo Committed by Bob Van Landuyt

Request parent labels when subgroup selected

Fixes a 404 error when we try and request
group labels for a subgroup

For value stream analytics, when a subgroup
is selected we should only query for the labels
associated with the parent group

Updated related specs

Added changelog entry
parent cf586958
......@@ -220,10 +220,10 @@ export const requestGroupLabels = ({ commit }) => commit(types.REQUEST_GROUP_LAB
export const fetchGroupLabels = ({ dispatch, state }) => {
dispatch('requestGroupLabels');
const {
selectedGroup: { fullPath },
selectedGroup: { fullPath, parentId = null },
} = state;
return Api.cycleAnalyticsGroupLabels(fullPath)
return Api.cycleAnalyticsGroupLabels(parentId || fullPath)
.then(({ data }) => dispatch('receiveGroupLabelsSuccess', data))
.catch(error =>
handleErrorOrRethrow({ error, action: () => dispatch('receiveGroupLabelsError', error) }),
......
......@@ -17,7 +17,7 @@ export const formattedDate = d => dateFormat(d, dateFormats.defaultDate);
* @returns {Object} - A group object
*/
export const buildGroupFromDataset = dataset => {
const { groupId, groupName, groupFullPath, groupAvatarUrl } = dataset;
const { groupId, groupName, groupFullPath, groupAvatarUrl, groupParentId } = dataset;
if (groupId) {
return {
......@@ -25,6 +25,7 @@ export const buildGroupFromDataset = dataset => {
name: groupName,
full_path: groupFullPath,
avatar_url: groupAvatarUrl,
parent_id: groupParentId,
};
}
......@@ -76,11 +77,18 @@ export const buildCycleAnalyticsInitialData = ({
projects = null,
groupName = null,
groupFullPath = null,
groupParentId = null,
groupAvatarUrl = null,
} = {}) => ({
group: groupId
? convertObjectPropsToCamelCase(
buildGroupFromDataset({ groupId, groupName, groupFullPath, groupAvatarUrl }),
buildGroupFromDataset({
groupId,
groupName,
groupFullPath,
groupAvatarUrl,
groupParentId,
}),
)
: null,
createdBefore: createdBefore ? new Date(createdBefore) : null,
......
---
title: Use group parent for subgroup labels requests
merge_request: 27564
author:
type: fixed
......@@ -54,6 +54,7 @@ module Gitlab
{
id: group.id,
name: group.name,
parent_id: group.parent_id,
full_path: group.full_path,
avatar_url: group.avatar_url
}
......
......@@ -11,6 +11,14 @@ const groupDataset = {
groupAvatarUrl: 'foo/bar',
};
const subGroupDataset = {
groupId: '1',
groupName: 'My Group',
groupFullPath: 'parent/my-group',
groupAvatarUrl: 'foo/bar',
groupParentId: 20,
};
const projectDataset = {
projectId: '1',
projectName: 'My Project',
......@@ -38,6 +46,16 @@ describe('buildGroupFromDataset', () => {
avatar_url: 'foo/bar',
});
});
it('sets the parent_id when a subgroup is given', () => {
expect(buildGroupFromDataset(subGroupDataset)).toEqual({
id: 1,
name: 'My Group',
full_path: 'parent/my-group',
avatar_url: 'foo/bar',
parent_id: 20,
});
});
});
describe('buildProjectFromDataset', () => {
......@@ -80,6 +98,7 @@ describe('buildCycleAnalyticsInitialData', () => {
${'avatarUrl'} | ${null}
${'fullPath'} | ${null}
${'name'} | ${null}
${'parentId'} | ${null}
`("will be $value if the '$field' field is not present", ({ field, value }) => {
expect(buildCycleAnalyticsInitialData({ groupId: groupDataset.groupId })).toMatchObject({
group: { id: 1, [field]: value },
......
......@@ -2,6 +2,7 @@ import MockAdapter from 'axios-mock-adapter';
import Api from 'ee/api';
import * as cycleAnalyticsConstants from 'ee/analytics/cycle_analytics/constants';
import axios from '~/lib/utils/axios_utils';
import httpStatus from '~/lib/utils/http_status';
import * as analyticsMockData from 'ee_jest/analytics/cycle_analytics/mock_data';
describe('Api', () => {
......@@ -537,7 +538,7 @@ describe('Api', () => {
it('fetches group level labels', done => {
const response = [];
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/labels`;
mock.onGet(expectedUrl).reply(200, response);
mock.onGet(expectedUrl).reply(httpStatus.OK, response);
Api.cycleAnalyticsGroupLabels(groupId)
.then(({ data, config: { url } }) => {
......
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