( node: T, expandedKeys: ReadonlySet<string>, keyword: string, searchMatch: (node: T, term: string) => boolean, includeChildrenOnSearchMatch = false, parentMatches = false )
| 30 | * pre-filtered. |
| 31 | */ |
| 32 | export function countVisibleRows< |
| 33 | T extends VisibleRowNode & { readonly children?: readonly T[] }, |
| 34 | >( |
| 35 | node: T, |
| 36 | expandedKeys: ReadonlySet<string>, |
| 37 | keyword: string, |
| 38 | searchMatch: (node: T, term: string) => boolean, |
| 39 | includeChildrenOnSearchMatch = false, |
| 40 | parentMatches = false |
| 41 | ): number { |
| 42 | if (!keyword) { |
| 43 | let count = 1; |
| 44 | if (expandedKeys.has(node.key)) { |
| 45 | for (const child of node.children ?? []) { |
| 46 | count += countVisibleRows(child, expandedKeys, keyword, searchMatch); |
| 47 | } |
| 48 | } |
| 49 | return count; |
| 50 | } |
| 51 | |
| 52 | const selfMatches = searchMatch(node, keyword); |
| 53 | const includedByParent = includeChildrenOnSearchMatch && parentMatches; |
| 54 | let childCount = 0; |
| 55 | for (const child of node.children ?? []) { |
| 56 | childCount += countVisibleRows( |
| 57 | child, |
| 58 | expandedKeys, |
| 59 | keyword, |
| 60 | searchMatch, |
| 61 | includeChildrenOnSearchMatch, |
| 62 | selfMatches |
| 63 | ); |
| 64 | } |
| 65 | if (includedByParent || selfMatches || childCount > 0) { |
| 66 | return 1 + childCount; |
| 67 | } |
| 68 | return 0; |
| 69 | } |
no test coverage detected