Commit b88f6835 authored by Phil Hughes's avatar Phil Hughes

Merge branch '212433-group-activity-analytics-add-new-members-count' into 'master'

Resolve "Group Activity Analytics: Add New Members count"

Closes #212433

See merge request gitlab-org/gitlab!28093
parents 3b0d2c83 8710f533
......@@ -21,6 +21,7 @@ export default {
metrics: {
mergeRequests: { value: null, label: s__('GroupActivyMetrics|Merge Requests created') },
issues: { value: null, label: s__('GroupActivyMetrics|Issues created') },
newMembers: { value: null, label: s__('GroupActivityMetrics|New Members created') },
},
};
},
......@@ -46,10 +47,12 @@ export default {
return Promise.all([
Api.groupActivityMergeRequestsCount(groupPath),
Api.groupActivityIssuesCount(groupPath),
Api.groupActivityNewMembersCount(groupPath),
])
.then(([mrResponse, issuesResponse]) => {
.then(([mrResponse, issuesResponse, newMembersResponse]) => {
this.metrics.mergeRequests.value = mrResponse.data.merge_requests_count;
this.metrics.issues.value = issuesResponse.data.issues_count;
this.metrics.newMembers.value = newMembersResponse.data.new_members_count;
this.isLoading = false;
})
.catch(() => {
......
......@@ -28,6 +28,7 @@ export default {
codeReviewAnalyticsPath: '/api/:version/analytics/code_review',
groupActivityIssuesPath: '/api/:version/analytics/group_activity/issues_count',
groupActivityMergeRequestsPath: '/api/:version/analytics/group_activity/merge_requests_count',
groupActivityNewMembersPath: '/api/:version/analytics/group_activity/new_members_count',
countriesPath: '/-/countries',
countryStatesPath: '/-/country_states',
paymentFormPath: '/-/subscriptions/payment_form',
......@@ -235,6 +236,11 @@ export default {
return axios.get(url, { params: { group_path: groupPath } });
},
groupActivityNewMembersCount(groupPath) {
const url = Api.buildUrl(this.groupActivityNewMembersPath);
return axios.get(url, { params: { group_path: groupPath } });
},
getGeoReplicableItems(replicable, params = {}) {
const url = Api.buildUrl(this.geoReplicationPath).replace(':replicable', replicable);
return axios.get(url, { params });
......
......@@ -51,6 +51,21 @@ exports[`GroupActivity component matches the snapshot 1`] = `
Issues created
</p>
</div>
<div
class="flex-grow text-center"
>
<h3
class="my-2"
>
30
</h3>
<p
class="text-secondary gl-font-size-small mb-2"
>
New Members created
</p>
</div>
</div>
</div>
......
......@@ -9,6 +9,7 @@ import waitForPromises from 'helpers/wait_for_promises';
const TEST_GROUP_ID = 'gitlab-org';
const TEST_MERGE_REQUESTS_COUNT = { data: { merge_requests_count: 10 } };
const TEST_ISSUES_COUNT = { data: { issues_count: 20 } };
const TEST_NEW_MEMBERS_COUNT = { data: { new_members_count: 30 } };
describe('GroupActivity component', () => {
let wrapper;
......@@ -30,6 +31,10 @@ describe('GroupActivity component', () => {
.mockReturnValue(Promise.resolve(TEST_MERGE_REQUESTS_COUNT));
jest.spyOn(Api, 'groupActivityIssuesCount').mockReturnValue(Promise.resolve(TEST_ISSUES_COUNT));
jest
.spyOn(Api, 'groupActivityNewMembersCount')
.mockReturnValue(Promise.resolve(TEST_NEW_MEMBERS_COUNT));
});
afterEach(() => {
......@@ -60,6 +65,7 @@ describe('GroupActivity component', () => {
.then(() => {
expect(Api.groupActivityMergeRequestsCount).toHaveBeenCalledWith(TEST_GROUP_ID);
expect(Api.groupActivityIssuesCount).toHaveBeenCalledWith(TEST_GROUP_ID);
expect(Api.groupActivityNewMembersCount).toHaveBeenCalledWith(TEST_GROUP_ID);
waitForPromises();
})
......@@ -67,6 +73,7 @@ describe('GroupActivity component', () => {
expect(wrapper.vm.isLoading).toBe(false);
expect(wrapper.vm.metrics.mergeRequests.value).toBe(10);
expect(wrapper.vm.metrics.issues.value).toBe(20);
expect(wrapper.vm.metrics.newMembers.value).toBe(30);
});
});
......@@ -80,6 +87,7 @@ describe('GroupActivity component', () => {
expect(findMetricCard().props('metrics')).toEqual([
{ key: 'mergeRequests', value: 10, label: 'Merge Requests created' },
{ key: 'issues', value: 20, label: 'Issues created' },
{ key: 'newMembers', value: 30, label: 'New Members created' },
]);
});
});
......
......@@ -583,6 +583,22 @@ describe('Api', () => {
});
});
});
describe('groupActivityNewMembersCount', () => {
it('fetches the number of new members created for a given group', () => {
const response = { new_members_count: 30 };
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/analytics/group_activity/new_members_count`;
jest.spyOn(Api, 'buildUrl').mockReturnValue(expectedUrl);
jest.spyOn(axios, 'get');
mock.onGet(expectedUrl).reply(200, response);
return Api.groupActivityNewMembersCount(groupId).then(({ data }) => {
expect(data).toEqual(response);
expect(axios.get).toHaveBeenCalledWith(expectedUrl, { params: { group_path: groupId } });
});
});
});
});
describe('GeoReplicable', () => {
......
......@@ -10079,6 +10079,9 @@ msgstr ""
msgid "Group: %{name}"
msgstr ""
msgid "GroupActivityMetrics|New Members created"
msgstr ""
msgid "GroupActivyMetrics|Issues created"
msgstr ""
......
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