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
069b4d16
Commit
069b4d16
authored
Jul 13, 2020
by
mfluharty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use lodash's differenceBy instead of filterByKey
Replace old custom utility function with standard lodash utility
parent
091f27bd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
28 deletions
+10
-28
app/assets/javascripts/reports/codequality_report/store/utils/filter_by_key.js
...s/reports/codequality_report/store/utils/filter_by_key.js
+0
-12
app/assets/javascripts/reports/codequality_report/workers/codequality_comparison_worker.js
...dequality_report/workers/codequality_comparison_worker.js
+3
-3
spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js
...quality_report/store/utils/codequality_comparison_spec.js
+7
-3
spec/frontend/reports/codequality_report/store/utils/filter_by_key_spec.js
...orts/codequality_report/store/utils/filter_by_key_spec.js
+0
-10
No files found.
app/assets/javascripts/reports/codequality_report/store/utils/filter_by_key.js
deleted
100644 → 0
View file @
091f27bd
/**
* Compares two arrays by the given key and returns the difference
*
* @param {Array} firstArray
* @param {Array} secondArray
* @param {String} key
* @returns {Array}
*/
const
filterByKey
=
(
firstArray
=
[],
secondArray
=
[],
key
=
''
)
=>
firstArray
.
filter
(
item
=>
!
secondArray
.
find
(
el
=>
el
[
key
]
===
item
[
key
]));
export
default
filterByKey
;
app/assets/javascripts/reports/codequality_report/workers/codequality_comparison_worker.js
View file @
069b4d16
import
filterByKey
from
'
../store/utils/filter_by_key
'
;
import
{
differenceBy
}
from
'
lodash
'
;
const
KEY_TO_FILTER_BY
=
'
fingerprint
'
;
...
...
@@ -19,8 +19,8 @@ self.addEventListener('message', e => {
// eslint-disable-next-line no-restricted-globals
self
.
postMessage
({
newIssues
:
filterByKe
y
(
headIssues
,
baseIssues
,
KEY_TO_FILTER_BY
),
resolvedIssues
:
filterByKe
y
(
baseIssues
,
headIssues
,
KEY_TO_FILTER_BY
),
newIssues
:
differenceB
y
(
headIssues
,
baseIssues
,
KEY_TO_FILTER_BY
),
resolvedIssues
:
differenceB
y
(
baseIssues
,
headIssues
,
KEY_TO_FILTER_BY
),
});
// eslint-disable-next-line no-restricted-globals
...
...
spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js
View file @
069b4d16
...
...
@@ -2,7 +2,6 @@ import {
parseCodeclimateMetrics
,
doCodeClimateComparison
,
}
from
'
~/reports/codequality_report/store/utils/codequality_comparison
'
;
import
mockFilterByKey
from
'
~/reports/codequality_report/store/utils/filter_by_key
'
;
import
{
baseIssues
,
mockParsedHeadIssues
,
mockParsedBaseIssues
}
from
'
../../mock_data
'
;
jest
.
mock
(
'
~/reports/codequality_report/workers/codequality_comparison_worker
'
,
()
=>
{
...
...
@@ -15,10 +14,15 @@ jest.mock('~/reports/codequality_report/workers/codequality_comparison_worker',
postMessage
:
data
=>
{
if
(
!
data
.
headIssues
)
return
mockPostMessageCallback
({
data
:
{}
});
if
(
!
data
.
baseIssues
)
throw
new
Error
();
const
key
=
'
fingerprint
'
;
return
mockPostMessageCallback
({
data
:
{
newIssues
:
mockFilterByKey
(
data
.
headIssues
,
data
.
baseIssues
,
'
fingerprint
'
),
resolvedIssues
:
mockFilterByKey
(
data
.
baseIssues
,
data
.
headIssues
,
'
fingerprint
'
),
newIssues
:
data
.
headIssues
.
filter
(
item
=>
!
data
.
baseIssues
.
find
(
el
=>
el
[
key
]
===
item
[
key
]),
),
resolvedIssues
:
data
.
baseIssues
.
filter
(
item
=>
!
data
.
headIssues
.
find
(
el
=>
el
[
key
]
===
item
[
key
]),
),
},
});
},
...
...
spec/frontend/reports/codequality_report/store/utils/filter_by_key_spec.js
deleted
100644 → 0
View file @
091f27bd
import
filterByKey
from
'
~/reports/codequality_report/store/utils/filter_by_key
'
;
import
{
mockParsedHeadIssues
,
mockParsedBaseIssues
,
issueDiff
}
from
'
../../mock_data
'
;
describe
(
'
filterByKey
'
,
()
=>
{
it
(
'
should return a diff of the arrays based on the given key
'
,
()
=>
{
const
result
=
filterByKey
(
mockParsedHeadIssues
,
mockParsedBaseIssues
,
'
fingerprint
'
);
expect
(
result
).
toEqual
(
issueDiff
);
});
});
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