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

Commit

Permalink
Merge pull request #4127 from darkdh/4124
Browse files Browse the repository at this point in the history
removeSite should also remove its children
  • Loading branch information
bsclifton authored Sep 20, 2016
2 parents 6e628fb + 036effa commit f5a0f63
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
11 changes: 11 additions & 0 deletions js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,18 @@ module.exports.removeSite = function (sites, siteDetail, tag) {
if (index === -1) {
return sites
}

const tags = sites.getIn([index, 'tags'])
if (isBookmarkFolder(tags)) {
const folderId = sites.getIn([index, 'folderId'])
const childSites = sites.filter((site) => site.get('parentFolderId') === folderId)
childSites.forEach((site) => {
const tags = site.get('tags')
tags.forEach((tag) => {
sites = module.exports.removeSite(sites, site, tag)
})
})
}
if (tags.size === 0 && !tag) {
// If called without tags and entry has no tags, remove the entry
return sites.splice(index, 1)
Expand Down
54 changes: 54 additions & 0 deletions test/unit/state/siteUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,60 @@ describe('siteUtil', function () {
.setIn([0, 'tags'], Immutable.List([]))
assert.deepEqual(processedSites, expectedSites)
})
it('removes folder and its children', function () {
const sites = Immutable.fromJS([
{
folderId: 1,
parentFolderId: 0,
tags: [siteTags.BOOKMARK_FOLDER]
},
{
folderId: 2,
parentFolderId: 1,
tags: [siteTags.BOOKMARK_FOLDER]
},
{
parentFolderId: 1,
location: testUrl1,
tags: [siteTags.BOOKMARK]
},
{
parentFolderId: 2,
location: testUrl2,
tags: [siteTags.BOOKMARK]
}
])
const siteDetail = {
folderId: 1,
parentFolderId: 0,
tags: [siteTags.BOOKMARK_FOLDER]
}
const processedSites = siteUtil.removeSite(sites, Immutable.fromJS(siteDetail), siteTags.BOOKMARK_FOLDER)
const expectedSites = Immutable.fromJS([
{
folderId: 1,
parentFolderId: 0,
tags: Immutable.List([])
},
{
folderId: 2,
parentFolderId: 0,
tags: Immutable.List([])
},
{
parentFolderId: 0,
location: testUrl1,
tags: Immutable.List([])
},
{
parentFolderId: 0,
location: testUrl2,
tags: Immutable.List([])
}
])
// toJS needed because immutable ownerID :(
assert.deepEqual(processedSites.toJS(), expectedSites.toJS())
})
})
describe('tag=falsey', function () {
it('deletes a history entry (has no tags)', function () {
Expand Down

0 comments on commit f5a0f63

Please sign in to comment.