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

removeSite should also remove its children #4127

Merged
merged 1 commit into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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