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
503acc86
Commit
503acc86
authored
Oct 08, 2021
by
Rishabh Gupta
Committed by
Ezekiel Kigbo
Oct 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor: moving and renaming timeSummaryForPathNavigation
parent
3d1fac55
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
46 deletions
+44
-46
app/assets/javascripts/cycle_analytics/utils.js
app/assets/javascripts/cycle_analytics/utils.js
+2
-28
app/assets/javascripts/lib/utils/datetime/date_format_utility.js
...ets/javascripts/lib/utils/datetime/date_format_utility.js
+27
-2
spec/frontend/cycle_analytics/utils_spec.js
spec/frontend/cycle_analytics/utils_spec.js
+0
-16
spec/frontend/lib/utils/datetime/date_format_utility_spec.js
spec/frontend/lib/utils/datetime/date_format_utility_spec.js
+15
-0
No files found.
app/assets/javascripts/cycle_analytics/utils.js
View file @
503acc86
import
dateFormat
from
'
dateformat
'
;
import
{
unescape
}
from
'
lodash
'
;
import
{
dateFormats
}
from
'
~/analytics/shared/constants
'
;
import
{
hideFlash
}
from
'
~/flash
'
;
import
{
sanitize
}
from
'
~/lib/dompurify
'
;
import
{
roundToNearestHalf
}
from
'
~/lib/utils/common_utils
'
;
import
{
getDateInPast
}
from
'
~/lib/utils/datetime/date_calculation_utility
'
;
import
{
parseSeconds
}
from
'
~/lib/utils/datetime_utility
'
;
import
{
formatTimeAsSummary
}
from
'
~/lib/utils/datetime/date_format_utility
'
;
import
{
slugify
}
from
'
~/lib/utils/text_utility
'
;
import
{
s__
,
sprintf
}
from
'
../locale
'
;
export
const
removeFlash
=
(
type
=
'
alert
'
)
=>
{
const
flashEl
=
document
.
querySelector
(
`.flash-
${
type
}
`
);
...
...
@@ -45,29 +42,6 @@ export const transformStagesForPathNavigation = ({
return
formattedStages
;
};
export
const
timeSummaryForPathNavigation
=
({
seconds
,
hours
,
days
,
minutes
,
weeks
,
months
})
=>
{
if
(
months
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}M
'
),
{
value
:
roundToNearestHalf
(
months
),
});
}
else
if
(
weeks
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}w
'
),
{
value
:
roundToNearestHalf
(
weeks
),
});
}
else
if
(
days
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}d
'
),
{
value
:
roundToNearestHalf
(
days
),
});
}
else
if
(
hours
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}h
'
),
{
value
:
hours
});
}
else
if
(
minutes
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}m
'
),
{
value
:
minutes
});
}
else
if
(
seconds
)
{
return
unescape
(
sanitize
(
s__
(
'
ValueStreamAnalytics|<1m
'
),
{
ALLOWED_TAGS
:
[]
}));
}
return
'
-
'
;
};
/**
* Takes a raw median value in seconds and converts it to a string representation
* ie. converts 172800 => 2d (2 days)
...
...
@@ -76,7 +50,7 @@ export const timeSummaryForPathNavigation = ({ seconds, hours, days, minutes, we
* @returns {String} String representation ie 2w
*/
export
const
medianTimeToParsedSeconds
=
(
value
)
=>
timeSummaryForPathNavigation
({
formatTimeAsSummary
({
...
parseSeconds
(
value
,
{
daysPerWeek
:
7
,
hoursPerDay
:
24
}),
seconds
:
value
,
});
...
...
app/assets/javascripts/lib/utils/datetime/date_format_utility.js
View file @
503acc86
import
dateFormat
from
'
dateformat
'
;
import
{
isString
,
mapValues
,
reduce
,
isDate
}
from
'
lodash
'
;
import
{
s__
,
n__
,
__
}
from
'
../../../locale
'
;
import
{
isString
,
mapValues
,
reduce
,
isDate
,
unescape
}
from
'
lodash
'
;
import
{
roundToNearestHalf
}
from
'
~/lib/utils/common_utils
'
;
import
{
sanitize
}
from
'
~/lib/dompurify
'
;
import
{
s__
,
n__
,
__
,
sprintf
}
from
'
../../../locale
'
;
/**
* Returns i18n month names array.
...
...
@@ -361,3 +363,26 @@ export const dateToTimeInputValue = (date) => {
hour12
:
false
,
});
};
export
const
formatTimeAsSummary
=
({
seconds
,
hours
,
days
,
minutes
,
weeks
,
months
})
=>
{
if
(
months
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}M
'
),
{
value
:
roundToNearestHalf
(
months
),
});
}
else
if
(
weeks
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}w
'
),
{
value
:
roundToNearestHalf
(
weeks
),
});
}
else
if
(
days
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}d
'
),
{
value
:
roundToNearestHalf
(
days
),
});
}
else
if
(
hours
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}h
'
),
{
value
:
hours
});
}
else
if
(
minutes
)
{
return
sprintf
(
s__
(
'
ValueStreamAnalytics|%{value}m
'
),
{
value
:
minutes
});
}
else
if
(
seconds
)
{
return
unescape
(
sanitize
(
s__
(
'
ValueStreamAnalytics|<1m
'
),
{
ALLOWED_TAGS
:
[]
}));
}
return
'
-
'
;
};
spec/frontend/cycle_analytics/utils_spec.js
View file @
503acc86
import
{
useFakeDate
}
from
'
helpers/fake_date
'
;
import
{
transformStagesForPathNavigation
,
timeSummaryForPathNavigation
,
medianTimeToParsedSeconds
,
formatMedianValues
,
filterStagesByHiddenStatus
,
...
...
@@ -47,21 +46,6 @@ describe('Value stream analytics utils', () => {
});
});
describe
(
'
timeSummaryForPathNavigation
'
,
()
=>
{
it
.
each
`
unit | value | result
${
'
months
'
}
|
${
1.5
}
|
${
'
1.5M
'
}
${
'
weeks
'
}
|
${
1.25
}
|
${
'
1.5w
'
}
${
'
days
'
}
|
${
2
}
|
${
'
2d
'
}
${
'
hours
'
}
|
${
10
}
|
${
'
10h
'
}
${
'
minutes
'
}
|
${
20
}
|
${
'
20m
'
}
${
'
seconds
'
}
|
${
10
}
|
${
'
<1m
'
}
${
'
seconds
'
}
|
${
0
}
|
${
'
-
'
}
`
(
'
will format $value $unit to $result
'
,
({
unit
,
value
,
result
})
=>
{
expect
(
timeSummaryForPathNavigation
({
[
unit
]:
value
})).
toBe
(
result
);
});
});
describe
(
'
medianTimeToParsedSeconds
'
,
()
=>
{
it
.
each
`
value | result
...
...
spec/frontend/lib/utils/datetime/date_format_utility_spec.js
View file @
503acc86
...
...
@@ -118,3 +118,18 @@ describe('date_format_utility.js', () => {
});
});
});
describe
(
'
formatTimeAsSummary
'
,
()
=>
{
it
.
each
`
unit | value | result
${
'
months
'
}
|
${
1.5
}
|
${
'
1.5M
'
}
${
'
weeks
'
}
|
${
1.25
}
|
${
'
1.5w
'
}
${
'
days
'
}
|
${
2
}
|
${
'
2d
'
}
${
'
hours
'
}
|
${
10
}
|
${
'
10h
'
}
${
'
minutes
'
}
|
${
20
}
|
${
'
20m
'
}
${
'
seconds
'
}
|
${
10
}
|
${
'
<1m
'
}
${
'
seconds
'
}
|
${
0
}
|
${
'
-
'
}
`
(
'
will format $value $unit to $result
'
,
({
unit
,
value
,
result
})
=>
{
expect
(
utils
.
formatTimeAsSummary
({
[
unit
]:
value
})).
toBe
(
result
);
});
});
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