Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Context menu sometimes errors and won't show up
Browse files Browse the repository at this point in the history
Fix #7017

Auditors: @bsclifton
  • Loading branch information
bbondy committed Feb 3, 2017
1 parent cfa3186 commit bfc0cd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 2 additions & 8 deletions app/common/lib/menuUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,15 @@ const isItemValid = (currentItem, previousItem) => {
* - entries which don't have a label or type
*/
module.exports.sanitizeTemplateItems = (template) => {
const reduced = template.reduce((previousValue, currentValue, currentIndex, array) => {
const result = currentIndex === 1 ? [] : previousValue
if (currentIndex === 1) {
if (isItemValid(previousValue)) {
result.push(previousValue)
}
}
const reduced = template.reduce((result, currentValue, currentIndex, array) => {
const previousItem = result.length > 0
? result[result.length - 1]
: undefined
if (isItemValid(currentValue, previousItem)) {
result.push(currentValue)
}
return result
})
}, [])

const result = Array.isArray(reduced)
? reduced
Expand Down
6 changes: 6 additions & 0 deletions test/unit/app/common/lib/menuUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,11 @@ describe('menuUtil tests', function () {
const expectedResult = []
assert.deepEqual(result, expectedResult)
})
it('supports empty arrays', function () {
const template = []
const result = menuUtil.sanitizeTemplateItems(template)
const expectedResult = []
assert.deepEqual(result, expectedResult)
})
})
})

1 comment on commit bfc0cd1

@bsclifton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.