Skip to content

Commit c116dff

Browse files
Filtering only child nodes starting with parent path with end slash only.
1 parent 712dbd2 commit c116dff

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/components/TreeView/useCollapse.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BRANCH_NODE } from '@lcov-viewer/core';
2-
import { collapseRow, expandRow, hideRow, showRow } from '../render/collapse';
32
import { useEffect, useRef } from 'react';
3+
import { collapseRow, expandRow, hideRow, showRow } from '../render/collapse';
44

55
const findRow = (element) => {
66
let current = element;
@@ -12,6 +12,8 @@ const findRow = (element) => {
1212
return current;
1313
};
1414

15+
const makeParentPath = path => path && `${path}/`;
16+
1517
const useCollapse = () => {
1618
const ref = useRef();
1719
const state = useRef({});
@@ -41,11 +43,12 @@ const useCollapse = () => {
4143
} else {
4244
collapseRow(rowState.row);
4345
}
44-
45-
const childrenPaths = Object.keys(state.current).filter(path => path.startsWith(rowState.path) && path !== rowState.path);
46+
47+
const childrenPaths = Object.keys(state.current).filter(path => path.startsWith(makeParentPath(rowState.path)) && path !== rowState.path);
4648
const collapsedChildrenPaths = childrenPaths.filter(path => state.current[path].collapsed);
4749
const affectedChildrenPaths = childrenPaths
48-
.filter(path => !collapsedChildrenPaths.find(collapsedChildPath => path.startsWith(collapsedChildPath) && path !== collapsedChildPath));
50+
.filter(path => !collapsedChildrenPaths
51+
.find(collapsedChildPath => path.startsWith(makeParentPath(collapsedChildPath)) && path !== collapsedChildPath));
4952

5053
affectedChildrenPaths.forEach(path => {
5154
if (rowState.collapsed) {

0 commit comments

Comments
 (0)