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 #12517 from NejcZdovc/hotfix/#12481-dnd
Browse files Browse the repository at this point in the history
Fixes dnd for bookmark toolbar
  • Loading branch information
cezaraugusto committed Jan 5, 2018
1 parent 2cef685 commit 81346ee
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/browser/reducers/bookmarkFoldersReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const Immutable = require('immutable')

// State
const bookmarksState = require('../../common/state/bookmarksState')
const bookmarkFoldersState = require('../../common/state/bookmarkFoldersState')
const bookmarkToolbarState = require('../../common/state/bookmarkToolbarState')

Expand Down Expand Up @@ -81,7 +82,7 @@ const bookmarkFoldersReducer = (state, action, immutableAction) => {
action.get('moveIntoParent')
)

const destinationDetail = bookmarkFoldersState.getFolder(state, action.get('destinationKey'))
const destinationDetail = bookmarksState.findBookmark(state, action.get('destinationKey'))
state = syncUtil.updateObjectCache(state, destinationDetail, STATE_SITES.BOOKMARK_FOLDERS)
if (
destinationDetail.get('parentFolderId') === 0 ||
Expand Down
2 changes: 1 addition & 1 deletion app/browser/reducers/bookmarksReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const bookmarksReducer = (state, action, immutableAction) => {
action.get('moveIntoParent')
)

const destinationDetail = bookmarksState.getBookmark(state, action.get('destinationKey'))
const destinationDetail = bookmarksState.findBookmark(state, action.get('destinationKey'))
state = syncUtil.updateObjectCache(state, destinationDetail, STATE_SITES.BOOKMARKS)

if (
Expand Down
5 changes: 5 additions & 0 deletions app/common/state/bookmarkFoldersState.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ const bookmarkFoldersState = {
? destinationItem.get('parentFolderId')
: destinationItem.get('folderId')

// always use parent ID when we are not moving into the folder
if (!moveIntoParent) {
parentFolderId = destinationItem.get('parentFolderId')
}

if (parentFolderId == null) {
parentFolderId = destinationKey
}
Expand Down
5 changes: 5 additions & 0 deletions app/common/state/bookmarksState.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ const bookmarksState = {
? destinationItem.get('parentFolderId')
: destinationItem.get('folderId')

// always use parent ID when we are not moving into the folder
if (!moveIntoParent) {
parentFolderId = destinationItem.get('parentFolderId')
}

if (parentFolderId == null) {
parentFolderId = destinationKey
}
Expand Down
41 changes: 40 additions & 1 deletion test/unit/app/common/state/bookmarkFoldersStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,46 @@ describe('bookmarkFoldersState unit test', function () {
})

it('destination parent ID is different then current parent ID', function () {
const result = bookmarkFoldersState.moveFolder(moveState, '69', '2')
const result = bookmarkFoldersState.moveFolder(moveState, '69', '2', false, false)
const expectedState = moveState
.setIn(['bookmarkFolders', '69', 'parentFolderId'], 1)
.setIn(['cache', 'bookmarkOrder', '0'], Immutable.fromJS([
{
key: '1',
order: 0,
type: siteTags.BOOKMARK_FOLDER
},
{
key: '70',
order: 1,
type: siteTags.BOOKMARK_FOLDER
}
]))
.setIn(['cache', 'bookmarkOrder', '1'], Immutable.fromJS([
{
key: '2',
order: 0,
type: siteTags.BOOKMARK_FOLDER
},
{
key: 'https://brave.com/|0|0',
order: 1,
type: siteTags.BOOKMARK
},
{
key: '69',
order: 2,
type: siteTags.BOOKMARK_FOLDER
}
]))
assert.deepEqual(result.toJS(), expectedState.toJS())
assert(removeCacheKeySpy.calledOnce)
assert(addFolderToCacheSpy.calledOnce)
assert(findBookmarkSpy.calledOnce)
})

it('we want to move folder into the parent', function () {
const result = bookmarkFoldersState.moveFolder(moveState, '69', '2', false, true)
const expectedState = moveState
.setIn(['bookmarkFolders', '69', 'parentFolderId'], 2)
.setIn(['cache', 'bookmarkOrder', '0'], Immutable.fromJS([
Expand Down
47 changes: 46 additions & 1 deletion test/unit/app/common/state/bookmarksStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,52 @@ describe('bookmarkState unit test', function () {
})

it('destination parent ID is different then current parent ID', function () {
const result = bookmarksState.moveBookmark(stateWithData, 'https://brave.com/|0|0', '2')
const result = bookmarksState.moveBookmark(stateWithData, 'https://brave.com/|0|0', '2', false, false)
const expectedState = stateWithData
.deleteIn(['bookmarks', 'https://brave.com/|0|0'])
.setIn(['bookmarks', 'https://brave.com/|0|1'], Immutable.fromJS(bookmark1))
.setIn(['bookmarks', 'https://brave.com/|0|1', 'parentFolderId'], 1)
.setIn(['bookmarks', 'https://brave.com/|0|1', 'key'], 'https://brave.com/|0|1')
.setIn(['cache', 'bookmarkOrder', '0'], Immutable.fromJS([
{
key: 'https://clifton.io/|0|0',
order: 0,
type: siteTags.BOOKMARK
},
{
key: '1',
order: 1,
type: siteTags.BOOKMARK_FOLDER
}
]))
.setIn(['cache', 'bookmarkOrder', '1'], Immutable.fromJS([
{
key: 'https://brianbondy.com/|0|1',
order: 0,
type: siteTags.BOOKMARK
},
{
key: '2',
order: 1,
type: siteTags.BOOKMARK_FOLDER
},
{
key: 'https://brave.com/|0|1',
order: 2,
type: siteTags.BOOKMARK
}
]))
.setIn(['cache', 'bookmarkLocation', 'https://brave.com/'], Immutable.fromJS([
'https://brave.com/|0|1'
]))
assert.deepEqual(result.toJS(), expectedState.toJS())
assert(removeCacheKeySpy.calledOnce)
assert(addFolderToCacheSpy.calledOnce)
assert(findBookmarkSpy.calledOnce)
})

it('we want to move it into the parent folder', function () {
const result = bookmarksState.moveBookmark(stateWithData, 'https://brave.com/|0|0', '2', false, true)
const expectedState = stateWithData
.deleteIn(['bookmarks', 'https://brave.com/|0|0'])
.setIn(['bookmarks', 'https://brave.com/|0|2'], Immutable.fromJS(bookmark1))
Expand Down

0 comments on commit 81346ee

Please sign in to comment.