({
bookmarkGroups,
bookmarkGroupTree,
bookmarksMap,
expandedKeys,
keyword
})
| 5 | } |
| 6 | |
| 7 | export function buildVisibleTreeRows ({ |
| 8 | bookmarkGroups, |
| 9 | bookmarkGroupTree, |
| 10 | bookmarksMap, |
| 11 | expandedKeys, |
| 12 | keyword |
| 13 | }) { |
| 14 | const groupTree = bookmarkGroupTree || {} |
| 15 | const rows = [] |
| 16 | const matchedRowKeys = [] |
| 17 | const expandedKeySet = new Set(expandedKeys || []) |
| 18 | const lowerKeyword = (keyword || '').toLowerCase() |
| 19 | const bookmarkMatchCache = new Map() |
| 20 | const groupMatchCache = new Map() |
| 21 | |
| 22 | const bookmarkMatches = (bookmarkId) => { |
| 23 | if (bookmarkMatchCache.has(bookmarkId)) { |
| 24 | return bookmarkMatchCache.get(bookmarkId) |
| 25 | } |
| 26 | const item = bookmarksMap.get(bookmarkId) |
| 27 | const matched = Boolean( |
| 28 | item && |
| 29 | (!lowerKeyword || |
| 30 | createName(item).toLowerCase().includes(lowerKeyword) || |
| 31 | (item.description || '').toLowerCase().includes(lowerKeyword)) |
| 32 | ) |
| 33 | bookmarkMatchCache.set(bookmarkId, matched) |
| 34 | return matched |
| 35 | } |
| 36 | |
| 37 | const groupHasMatchedBookmarks = (group) => { |
| 38 | if (!lowerKeyword) { |
| 39 | return true |
| 40 | } |
| 41 | if (!group) { |
| 42 | return false |
| 43 | } |
| 44 | if (groupMatchCache.has(group.id)) { |
| 45 | return groupMatchCache.get(group.id) |
| 46 | } |
| 47 | const hasMatch = (group.bookmarkIds || []).some(bookmarkMatches) || |
| 48 | (group.bookmarkGroupIds || []).some(id => { |
| 49 | return groupHasMatchedBookmarks(groupTree[id]) |
| 50 | }) |
| 51 | groupMatchCache.set(group.id, hasMatch) |
| 52 | return hasMatch |
| 53 | } |
| 54 | |
| 55 | const visitGroup = (group, parentId = '', depth = 1) => { |
| 56 | if (!group || (lowerKeyword && !groupHasMatchedBookmarks(group))) { |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | rows.push({ |
| 61 | key: `group:${group.id}`, |
| 62 | item: group, |
| 63 | isGroup: true, |
| 64 | parentId, |
no test coverage detected