Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
79738fe8
Commit
79738fe8
authored
Dec 12, 2019
by
Martin Wortschack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add utility functions
- Adds buildGroupFromDataset and buildProjectFromDataset
parent
e9350d05
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
0 deletions
+89
-0
ee/app/assets/javascripts/analytics/productivity_analytics/utils.js
...ets/javascripts/analytics/productivity_analytics/utils.js
+42
-0
ee/spec/frontend/analytics/productivity_analytics/utils_spec.js
...c/frontend/analytics/productivity_analytics/utils_spec.js
+47
-0
No files found.
ee/app/assets/javascripts/analytics/productivity_analytics/utils.js
View file @
79738fe8
...
...
@@ -186,3 +186,45 @@ export const getMedianLineData = (data, startDate, endDate, daysOffset) => {
return
result
;
};
/**
* Creates a group object from a dataset. Returns null if no groupId is present.
*
* @param {Object} dataset - The container's dataset
* @returns {Object} - A group object
*/
export
const
buildGroupFromDataset
=
dataset
=>
{
const
{
groupId
,
groupName
,
groupFullPath
,
groupAvatarUrl
}
=
dataset
;
if
(
groupId
)
{
return
{
id
:
Number
(
groupId
),
name
:
groupName
,
full_path
:
groupFullPath
,
avatar_url
:
groupAvatarUrl
,
};
}
return
null
;
};
/**
* Creates a project object from a dataset. Returns null if no projectId is present.
*
* @param {Object} dataset - The container's dataset
* @returns {Object} - A project object
*/
export
const
buildProjectFromDataset
=
dataset
=>
{
const
{
projectId
,
projectName
,
projectPathWithNamespace
,
projectAvatarUrl
}
=
dataset
;
if
(
projectId
)
{
return
{
id
:
Number
(
projectId
),
name
:
projectName
,
path_with_namespace
:
projectPathWithNamespace
,
avatar_url
:
projectAvatarUrl
,
};
}
return
null
;
};
ee/spec/frontend/analytics/productivity_analytics/utils_spec.js
View file @
79738fe8
...
...
@@ -2,6 +2,8 @@ import {
getLabelsEndpoint
,
getMilestonesEndpoint
,
getDefaultStartDate
,
buildGroupFromDataset
,
buildProjectFromDataset
,
initDateArray
,
transformScatterData
,
getScatterPlotData
,
...
...
@@ -62,6 +64,51 @@ describe('Productivity Analytics utils', () => {
});
});
describe
(
'
buildGroupFromDataset
'
,
()
=>
{
it
(
'
returns null if groupId is missing
'
,
()
=>
{
const
dataset
=
{
foo
:
'
bar
'
};
expect
(
buildGroupFromDataset
(
dataset
)).
toBeNull
();
});
it
(
'
returns a group object when the groupId is given
'
,
()
=>
{
const
dataset
=
{
groupId
:
'
1
'
,
groupName
:
'
My Group
'
,
groupFullPath
:
'
my-group
'
,
groupAvatarUrl
:
'
foo/bar
'
,
};
expect
(
buildGroupFromDataset
(
dataset
)).
toEqual
({
id
:
1
,
name
:
'
My Group
'
,
full_path
:
'
my-group
'
,
avatar_url
:
'
foo/bar
'
,
});
});
});
describe
(
'
buildProjectFromDataset
'
,
()
=>
{
it
(
'
returns null if projectId is missing
'
,
()
=>
{
const
dataset
=
{
foo
:
'
bar
'
};
expect
(
buildProjectFromDataset
(
dataset
)).
toBeNull
();
});
it
(
'
returns a project object when the projectId is given
'
,
()
=>
{
const
dataset
=
{
projectId
:
'
1
'
,
projectName
:
'
My Project
'
,
projectPathWithNamespace
:
'
my-group/my-project
'
,
};
expect
(
buildProjectFromDataset
(
dataset
)).
toEqual
({
id
:
1
,
name
:
'
My Project
'
,
path_with_namespace
:
'
my-group/my-project
'
,
avatar_url
:
undefined
,
});
});
});
describe
(
'
initDateArray
'
,
()
=>
{
it
(
'
creates a two-dimensional array with 3 empty arrays for startDate=2019-09-01 and endDate=2019-09-03
'
,
()
=>
{
const
startDate
=
new
Date
(
'
2019-09-01
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment