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

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

Issue 2812493002: MD Bookmarks: Restore any previously selected folder when clearing search (Closed)
Patch Set: Fix comment Created 3 years, 8 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
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 /** 5 /**
6 * @fileoverview Utility functions for the Bookmarks page. 6 * @fileoverview Utility functions for the Bookmarks page.
7 */ 7 */
8 8
9 cr.define('bookmarks.util', function() { 9 cr.define('bookmarks.util', function() {
10 /** 10 /**
11 * Returns the list of bookmark IDs to be displayed in the UI, taking into
12 * account search and the currently selected folder.
11 * @param {!BookmarksPageState} state 13 * @param {!BookmarksPageState} state
12 * @return {!Array<string>} 14 * @return {!Array<string>}
13 */ 15 */
14 function getDisplayedList(state) { 16 function getDisplayedList(state) {
15 if (!isShowingSearch(state)) 17 if (!isShowingSearch(state))
16 return assert(state.nodes[assert(state.selectedFolder)].children); 18 return assert(state.nodes[state.selectedFolder].children);
17 19
18 return state.search.results; 20 return state.search.results;
19 } 21 }
20 22
21 /** 23 /**
22 * @param {BookmarkTreeNode} treeNode 24 * @param {BookmarkTreeNode} treeNode
23 * @return {BookmarkNode} 25 * @return {BookmarkNode}
24 */ 26 */
25 function normalizeNode(treeNode) { 27 function normalizeNode(treeNode) {
26 var node = Object.assign({}, treeNode); 28 var node = Object.assign({}, treeNode);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 }, 77 },
76 selection: { 78 selection: {
77 items: new Set(), 79 items: new Set(),
78 anchor: null, 80 anchor: null,
79 }, 81 },
80 }; 82 };
81 } 83 }
82 84
83 /** 85 /**
84 * @param {BookmarksPageState} state 86 * @param {BookmarksPageState} state
85 * @return boolean 87 * @return {boolean}
86 */ 88 */
87 function isShowingSearch(state) { 89 function isShowingSearch(state) {
88 return !state.selectedFolder; 90 return !!state.search.term && !state.search.inProgress;
89 } 91 }
90 92
91 /** 93 /**
92 * @param {string} id 94 * @param {string} id
93 * @param {NodeList} nodes 95 * @param {NodeList} nodes
94 * @return {boolean} 96 * @return {boolean}
95 */ 97 */
96 function hasChildFolders(id, nodes) { 98 function hasChildFolders(id, nodes) {
97 var children = nodes[id].children; 99 var children = nodes[id].children;
98 for (var i = 0; i < children.length; i++) { 100 for (var i = 0; i < children.length; i++) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 getDescendants: getDescendants, 167 getDescendants: getDescendants,
166 getDisplayedList: getDisplayedList, 168 getDisplayedList: getDisplayedList,
167 hasChildFolders: hasChildFolders, 169 hasChildFolders: hasChildFolders,
168 isShowingSearch: isShowingSearch, 170 isShowingSearch: isShowingSearch,
169 normalizeNode: normalizeNode, 171 normalizeNode: normalizeNode,
170 normalizeNodes: normalizeNodes, 172 normalizeNodes: normalizeNodes,
171 removeIdsFromMap: removeIdsFromMap, 173 removeIdsFromMap: removeIdsFromMap,
172 removeIdsFromSet: removeIdsFromSet, 174 removeIdsFromSet: removeIdsFromSet,
173 }; 175 };
174 }); 176 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/types.js ('k') | chrome/test/data/webui/md_bookmarks/reducers_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698