OLD | NEW |
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 | 11 * Returns the list of bookmark IDs to be displayed in the UI, taking into |
12 * account search and the currently selected folder. | 12 * account search and the currently selected folder. |
13 * @param {!BookmarksPageState} state | 13 * @param {!BookmarksPageState} state |
14 * @return {!Array<string>} | 14 * @return {!Array<string>} |
15 */ | 15 */ |
16 function getDisplayedList(state) { | 16 function getDisplayedList(state) { |
17 if (!isShowingSearch(state)) | 17 if (isShowingSearch(state)) |
18 return assert(state.nodes[state.selectedFolder].children); | 18 return assert(state.search.results); |
19 | 19 |
20 return state.search.results; | 20 return assert(state.nodes[state.selectedFolder].children); |
21 } | 21 } |
22 | 22 |
23 /** | 23 /** |
24 * @param {BookmarkTreeNode} treeNode | 24 * @param {BookmarkTreeNode} treeNode |
25 * @return {BookmarkNode} | 25 * @return {BookmarkNode} |
26 */ | 26 */ |
27 function normalizeNode(treeNode) { | 27 function normalizeNode(treeNode) { |
28 var node = Object.assign({}, treeNode); | 28 var node = Object.assign({}, treeNode); |
29 // Node index is not necessary and not kept up-to-date. Remove it from the | 29 // Node index is not necessary and not kept up-to-date. Remove it from the |
30 // data structure so we don't accidentally depend on the incorrect | 30 // data structure so we don't accidentally depend on the incorrect |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 nodes: {}, | 70 nodes: {}, |
71 selectedFolder: BOOKMARKS_BAR_ID, | 71 selectedFolder: BOOKMARKS_BAR_ID, |
72 closedFolders: new Set(), | 72 closedFolders: new Set(), |
73 prefs: { | 73 prefs: { |
74 canEdit: true, | 74 canEdit: true, |
75 incognitoAvailability: IncognitoAvailability.ENABLED, | 75 incognitoAvailability: IncognitoAvailability.ENABLED, |
76 }, | 76 }, |
77 search: { | 77 search: { |
78 term: '', | 78 term: '', |
79 inProgress: false, | 79 inProgress: false, |
80 results: [], | 80 results: null, |
81 }, | 81 }, |
82 selection: { | 82 selection: { |
83 items: new Set(), | 83 items: new Set(), |
84 anchor: null, | 84 anchor: null, |
85 }, | 85 }, |
86 }; | 86 }; |
87 } | 87 } |
88 | 88 |
89 /** | 89 /** |
90 * @param {BookmarksPageState} state | 90 * @param {BookmarksPageState} state |
91 * @return {boolean} | 91 * @return {boolean} |
92 */ | 92 */ |
93 function isShowingSearch(state) { | 93 function isShowingSearch(state) { |
94 return !!state.search.term && !state.search.inProgress; | 94 return state.search.results != null; |
95 } | 95 } |
96 | 96 |
97 /** | 97 /** |
98 * Returns true if the node with ID |itemId| is modifiable, allowing | 98 * Returns true if the node with ID |itemId| is modifiable, allowing |
99 * the node to be renamed, moved or deleted. Note that if a node is | 99 * the node to be renamed, moved or deleted. Note that if a node is |
100 * uneditable, it may still have editable children (for example, the top-level | 100 * uneditable, it may still have editable children (for example, the top-level |
101 * folders). | 101 * folders). |
102 * @param {BookmarksPageState} state | 102 * @param {BookmarksPageState} state |
103 * @param {string} itemId | 103 * @param {string} itemId |
104 * @return {boolean} | 104 * @return {boolean} |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 getDescendants: getDescendants, | 200 getDescendants: getDescendants, |
201 getDisplayedList: getDisplayedList, | 201 getDisplayedList: getDisplayedList, |
202 hasChildFolders: hasChildFolders, | 202 hasChildFolders: hasChildFolders, |
203 isShowingSearch: isShowingSearch, | 203 isShowingSearch: isShowingSearch, |
204 normalizeNode: normalizeNode, | 204 normalizeNode: normalizeNode, |
205 normalizeNodes: normalizeNodes, | 205 normalizeNodes: normalizeNodes, |
206 removeIdsFromMap: removeIdsFromMap, | 206 removeIdsFromMap: removeIdsFromMap, |
207 removeIdsFromSet: removeIdsFromSet, | 207 removeIdsFromSet: removeIdsFromSet, |
208 }; | 208 }; |
209 }); | 209 }); |
OLD | NEW |