Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: chrome/browser/resources/md_bookmarks/command_manager.js

Issue 2850763002: MD Bookmarks: Update Delete command to only delete the minimal set of nodes (Closed)
Patch Set: Review comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/command_manager_test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 Polymer({ 5 Polymer({
6 is: 'bookmarks-command-manager', 6 is: 'bookmarks-command-manager',
7 7
8 behaviors: [ 8 behaviors: [
9 bookmarks.StoreClient, 9 bookmarks.StoreClient,
10 ], 10 ],
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 /** @type {!BookmarksEditDialogElement} */ (this.$.editDialog.get()) 96 /** @type {!BookmarksEditDialogElement} */ (this.$.editDialog.get())
97 .showEditDialog(this.getState().nodes[id]); 97 .showEditDialog(this.getState().nodes[id]);
98 break; 98 break;
99 case Command.COPY: 99 case Command.COPY:
100 var idList = Array.from(itemIds); 100 var idList = Array.from(itemIds);
101 chrome.bookmarkManagerPrivate.copy(idList, function() { 101 chrome.bookmarkManagerPrivate.copy(idList, function() {
102 // TODO(jiaxi): Add toast later. 102 // TODO(jiaxi): Add toast later.
103 }); 103 });
104 break; 104 break;
105 case Command.DELETE: 105 case Command.DELETE:
106 // TODO(tsergeant): Filter IDs so we don't try to delete children of
107 // something else already being deleted.
108 chrome.bookmarkManagerPrivate.removeTrees( 106 chrome.bookmarkManagerPrivate.removeTrees(
109 Array.from(itemIds), function() { 107 Array.from(this.minimizeDeletionSet_(itemIds)), function() {
110 // TODO(jiaxi): Add toast later. 108 // TODO(jiaxi): Add toast later.
111 }); 109 });
112 break; 110 break;
113 } 111 }
114
115 }, 112 },
116 113
117 //////////////////////////////////////////////////////////////////////////// 114 ////////////////////////////////////////////////////////////////////////////
118 // Private functions: 115 // Private functions:
119 116
120 /** 117 /**
118 * Minimize the set of |itemIds| by removing any node which has an ancestor
119 * node already in the set. This ensures that instead of trying to delete both
120 * a node and its descendant, we will only try to delete the topmost node,
121 * preventing an error in the bookmarkManagerPrivate.removeTrees API call.
122 * @param {!Set<string>} itemIds
123 * @return {!Set<string>}
124 */
125 minimizeDeletionSet_: function(itemIds) {
126 var minimizedSet = new Set();
127 var nodes = this.getState().nodes;
128 itemIds.forEach(function(itemId) {
129 var currentId = itemId;
130 while (currentId != ROOT_NODE_ID) {
131 currentId = assert(nodes[currentId].parentId);
132 if (itemIds.has(currentId))
133 return;
134 }
135 minimizedSet.add(itemId);
136 });
137 return minimizedSet;
138 },
139
140 /**
121 * @param {!Set<string>} itemIds 141 * @param {!Set<string>} itemIds
122 * @param {function(BookmarkNode):boolean} predicate 142 * @param {function(BookmarkNode):boolean} predicate
123 * @return {boolean} True if any node in |itemIds| returns true for 143 * @return {boolean} True if any node in |itemIds| returns true for
124 * |predicate|. 144 * |predicate|.
125 */ 145 */
126 containsMatchingNode_: function(itemIds, predicate) { 146 containsMatchingNode_: function(itemIds, predicate) {
127 var nodes = this.getState().nodes; 147 var nodes = this.getState().nodes;
128 148
129 return Array.from(itemIds).some(function(id) { 149 return Array.from(itemIds).some(function(id) {
130 return predicate(nodes[id]); 150 return predicate(nodes[id]);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 getEditActionLabel_: function() { 211 getEditActionLabel_: function() {
192 if (this.menuIds_.size > 1) 212 if (this.menuIds_.size > 1)
193 return; 213 return;
194 214
195 var id = Array.from(this.menuIds_)[0]; 215 var id = Array.from(this.menuIds_)[0];
196 var itemUrl = this.getState().nodes[id].url; 216 var itemUrl = this.getState().nodes[id].url;
197 var label = itemUrl ? 'menuEdit' : 'menuRename'; 217 var label = itemUrl ? 'menuEdit' : 'menuRename';
198 return loadTimeData.getString(label); 218 return loadTimeData.getString(label);
199 }, 219 },
200 }); 220 });
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/command_manager_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698