From 846a3e733dac7fea657521207a87c537f7c27f63 Mon Sep 17 00:00:00 2001 From: duanhongbo <6860300@qq.com> Date: Thu, 26 Nov 2020 11:32:34 +0800 Subject: [PATCH] feat: hide no matched nodes when searching --- render-process/Properties.tsx | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/render-process/Properties.tsx b/render-process/Properties.tsx index 9c40bca..72fdc4d 100644 --- a/render-process/Properties.tsx +++ b/render-process/Properties.tsx @@ -94,7 +94,7 @@ class FileDataNode implements DataNode { } } - expandSelf(recursive?: boolean) { + expandSelf(recursive: boolean = true) { if (this.isFolder) this.children = this.loadChilds(recursive); } @@ -121,6 +121,20 @@ class FileDataNode implements DataNode { return ret; } + removeChilds(exclude:string){ + for (let i = 0;i < this.children.length;++i) { + const child = this.children[i]; + if (child.isLeaf) { + const keyStr = child.key as string; + if(!keyStr.includes(exclude)){ + this.children.splice(i,1); + } + } else { + child.removeChilds(exclude); + } + } + } + // name:string; // path: string; // isFolder : boolean; @@ -242,13 +256,20 @@ export default class Properties extends Component { }) .filter((item, i, self) => item && self.indexOf(item) === i); if (value && value.length > 0) { + + const root = this.state.root; + root.removeChilds(value); this.setState({ + root:root, searchKey: value, expandedKeys: expandedKeys, autoExpandParent: true, }); } else { + const root = this.getRootNode(this.props.workdir); + root.expandSelf(); this.setState({ + root:root, searchKey: "", expandedKeys: this.state.defaultExpandedKeys, autoExpandParent: false, @@ -261,7 +282,6 @@ export default class Properties extends Component { filterNode(node: EventDataNode): boolean { const searchKey = this.state.searchKey; const nodeKey = node.title as string; - return nodeKey.includes(searchKey); } @@ -324,13 +344,12 @@ export default class Properties extends Component { filterTreeNode={this.filterNode.bind(this)} defaultExpandedKeys={[root.key]} onSelect={(keys, info) => { - console.log("onSelect", keys, info); + //console.log("onSelect", keys, info); if (info.node.isLeaf) { onOpenTree(keys[0] as string); } }} onExpand={(keys, info) => { - console.log("onExpand", info); this.setState({ expandedKeys: keys, autoExpandParent: false