This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Harden addSite and moveSite #7024
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,19 +75,24 @@ module.exports.getSiteKey = function (siteDetail) { | |
/** | ||
* Checks if a siteDetail has the specified tag | ||
* | ||
* @param sites The application state's Immutable sites list | ||
* @param sites The application state's Immutable sites map | ||
* @param siteDetail The site to check if it's in the specified tag | ||
* @return true if the location is already bookmarked | ||
*/ | ||
module.exports.isSiteBookmarked = function (sites, siteDetail) { | ||
if (!sites) { | ||
return false | ||
} | ||
const key = module.exports.getSiteKey(siteDetail) | ||
if (key === null) { | ||
return false | ||
|
||
const site = sites.find((site) => | ||
isBookmark(site.get('tags')) && | ||
site.get('location') === siteDetail.get('location') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto lack of partition here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated in f9861f9 |
||
) | ||
|
||
if (site) { | ||
return true | ||
} | ||
return isBookmark(sites.getIn([key, 'tags'])) | ||
return false | ||
} | ||
|
||
const getNextFolderIdItem = (sites) => | ||
|
@@ -228,8 +233,11 @@ module.exports.addSite = function (sites, siteDetail, tag, originalSiteDetail) { | |
} | ||
|
||
let site = mergeSiteDetails(oldSite, siteDetail, tag, folderId, sites.size) | ||
if (oldSite) { | ||
sites = sites.delete(oldKey) | ||
} | ||
|
||
const key = originalSiteKey || module.exports.getSiteKey(site) | ||
const key = module.exports.getSiteKey(site) | ||
if (key === null) { | ||
return sites | ||
} | ||
|
@@ -239,7 +247,7 @@ module.exports.addSite = function (sites, siteDetail, tag, originalSiteDetail) { | |
/** | ||
* Removes the specified tag from a siteDetail | ||
* | ||
* @param sites The application state's Immutable sites list | ||
* @param sites The application state's Immutable sites map | ||
* @param siteDetail The siteDetail to remove a tag from | ||
* @param reorder whether to reorder sites (default with reorder) | ||
* @return The new sites Immutable object | ||
|
@@ -306,7 +314,7 @@ module.exports.isMoveAllowed = (sites, sourceDetail, destinationDetail) => { | |
/** | ||
* Moves the specified site from one location to another | ||
* | ||
* @param sites The application state's Immutable sites list | ||
* @param sites The application state's Immutable sites map | ||
* @param siteDetail The site detail to move | ||
* @param destinationDetail The site detail to move to | ||
* @param prepend Whether the destination detail should be prepended or not, not used if destinationIsParent is true | ||
|
@@ -320,46 +328,45 @@ module.exports.moveSite = function (sites, sourceDetail, destinationDetail, prep | |
return sites | ||
} | ||
|
||
let sourceKey = module.exports.getSiteKey(sourceDetail) | ||
let destinationKey = module.exports.getSiteKey(destinationDetail) | ||
const sourceKey = module.exports.getSiteKey(sourceDetail) | ||
const destinationKey = module.exports.getSiteKey(destinationDetail) | ||
|
||
const sourceSiteIndex = sites.getIn([sourceKey, 'order']) | ||
let destinationSiteIndex | ||
if (destinationIsParent) { | ||
// When the destination is the parent we want to put it at the end | ||
destinationSiteIndex = sites.size - 1 | ||
prepend = false | ||
prepend = true | ||
} else { | ||
destinationSiteIndex = sites.getIn([destinationKey, 'order']) | ||
} | ||
|
||
let newIndex = destinationSiteIndex + (prepend ? 0 : 1) | ||
const newIndex = destinationSiteIndex + (prepend ? 0 : 1) | ||
let sourceSite = sites.get(sourceKey) | ||
let destinationSite = sites.get(destinationKey) | ||
if (!sourceSite) { | ||
return sites | ||
} | ||
const destinationSite = sites.get(destinationKey) | ||
sites = sites.delete(sourceKey) | ||
sites = sites.map((site) => { | ||
const siteOrder = site.get('order') | ||
if (siteOrder > sourceSiteIndex) { | ||
return site.set('order', siteOrder - 1) | ||
if (siteOrder >= newIndex && siteOrder < sourceSiteIndex) { | ||
return site.set('order', siteOrder + 1) | ||
} | ||
return site | ||
}) | ||
if (newIndex > sourceSiteIndex) { | ||
newIndex-- | ||
} | ||
sourceSite = sourceSite.set('order', newIndex) | ||
|
||
if (!disallowReparent) { | ||
if (destinationIsParent && destinationDetail.get('folderId') !== sourceSite.get('folderId')) { | ||
sourceSite = sourceSite.set('parentFolderId', destinationDetail.get('folderId')) | ||
} else if (!destinationSite.get('parentFolderId')) { | ||
sourceSite = sourceSite.delete('parentFolderId') | ||
sourceSite = sourceSite.set('parentFolderId', 0) | ||
} else if (destinationSite.get('parentFolderId') !== sourceSite.get('parentFolderId')) { | ||
sourceSite = sourceSite.set('parentFolderId', destinationSite.get('parentFolderId')) | ||
} | ||
} | ||
sourceKey = module.exports.getSiteKey(sourceSite) | ||
return sites.set(sourceKey, sourceSite) | ||
return sites.set(module.exports.getSiteKey(sourceSite), sourceSite) | ||
} | ||
|
||
module.exports.getDetailFromFrame = function (frame, tag) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we differentiate on bookmarks with different partitions, at least until today with previous releases. For example a user might want to bookmark twitter.com when logged in as user A and twitter.com when logged in as user B.