MCPcopy Create free account
hub / github.com/bytebase/bytebase / countVisibleRows

Function countVisibleRows

frontend/src/react/components/ui/tree-utils.ts:32–69  ·  view source on GitHub ↗
(
  node: T,
  expandedKeys: ReadonlySet<string>,
  keyword: string,
  searchMatch: (node: T, term: string) => boolean,
  includeChildrenOnSearchMatch = false,
  parentMatches = false
)

Source from the content-addressed store, hash-verified

30 * pre-filtered.
31 */
32export 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}

Callers 4

SheetTreeFunction · 0.90
SchemaPaneInnerFunction · 0.90
EnvironmentTreeSectionFunction · 0.90
tree-utils.test.tsFile · 0.90

Calls 1

searchMatchFunction · 0.50

Tested by

no test coverage detected