Commit 89ee8c86 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'fix-request-for-labels-includes-subgroup' into 'master'

Fix request for group labels with a subgroup

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