From cd2192cdf7b06073b8d010157811f28c5b1b5e5e Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Tue, 1 Nov 2016 15:37:25 -0700 Subject: [PATCH] Bug fixes for about:bookmarks: - clear selection when click is outside of table - clear selection when any element is dragged Fixes https://github.com/brave/browser-laptop/issues/5223 Fixes https://github.com/brave/browser-laptop/issues/5249 Auditors: @darkdh Test Plan: 1. Launch Brave and visit about:bookmarks 2. Import bookmarks or have bookmarks ready 3. Drag bookmarks from the view on the right over to a different folder 4. Observe that the selection is cleared 5. Use Ctrl or Cmd and select multiple items 6. Click below the table or click the header for the table 7. Notice the selection is cleared --- js/about/bookmarks.js | 44 ++++++++++++++++++++++++++++-- js/constants/appConfig.js | 2 +- test/about/bookmarksManagerTest.js | 11 ++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/js/about/bookmarks.js b/js/about/bookmarks.js index 5d8c69d8e5b..b459561ebbc 100644 --- a/js/about/bookmarks.js +++ b/js/about/bookmarks.js @@ -62,6 +62,11 @@ class BookmarkFolderItem extends React.Component { true) } } + clearSelection () { + if (this.props.onClearSelection) { + this.props.onClearSelection() + } + } // NOTE: both folders AND bookmarks can be dropped here onDrop (e) { this.setState({ @@ -74,10 +79,12 @@ class BookmarkFolderItem extends React.Component { bookmarkData.forEach((bookmark) => { this.moveBookmark(e, bookmark) }) + this.clearSelection() return } this.moveBookmark(e, bookmarkData) + this.clearSelection() } } render () { @@ -137,6 +144,7 @@ class BookmarkFolderList extends ImmutableComponent { { this.props.isRoot ? this.props.isRoot && bookmarkFolder.get('parentFolderId') === -1 ? null - : { this.moveBookmark(e, bookmark, siteDetail) }) + this.clearSelection() return } this.moveBookmark(e, bookmarkData, siteDetail) + this.clearSelection() } } + clearSelection () { + this.refs.bookmarkTable.clearSelection() + } render () { const props = !this.props.draggable ? { onDragStart: this.onDragStart, @@ -312,6 +328,7 @@ class BookmarksList extends ImmutableComponent { } return
, 'Last Visited' @@ -348,6 +365,8 @@ class AboutBookmarks extends React.Component { this.onClearSearchText = this.onClearSearchText.bind(this) this.importBrowserData = this.importBrowserData.bind(this) this.addBookmarkFolder = this.addBookmarkFolder.bind(this) + this.onClick = this.onClick.bind(this) + this.clearSelection = this.clearSelection.bind(this) this.state = { bookmarks: Immutable.List(), bookmarkFolders: Immutable.Map(), @@ -377,6 +396,19 @@ class AboutBookmarks extends React.Component { search: '' }) } + onClick (e) { + // Determine if click was on sortableTable + let targetElement = e.target + while (targetElement) { + if (targetElement.tagName === 'TBODY') { + return + } + targetElement = targetElement.parentNode + } + + // Click was not a child element of sortableTable; clear selection + this.clearSelection() + } searchedBookmarks (searchTerm, bookmarks) { return bookmarks.filter((bookmark) => { const title = bookmark.get('customTitle') + bookmark.get('title') + bookmark.get('location') @@ -396,6 +428,9 @@ class AboutBookmarks extends React.Component { }) aboutActions.showAddBookmarkFolder(newFolder) } + clearSelection () { + this.refs.bookmarkList.clearSelection() + } componentDidMount () { this.refs.bookmarkSearch.focus() } @@ -415,14 +450,16 @@ class AboutBookmarks extends React.Component {
-
+
- bookmark.get('parentFolderId') === -1)} allBookmarkFolders={this.state.bookmarkFolders} isRoot @@ -431,6 +468,7 @@ class AboutBookmarks extends React.Component {