feat: hide no matched nodes when searching

This commit is contained in:
duanhongbo committed 2020-11-26 11:32:34 +08:00
1 parent 31b3b7404f
commit 846a3e733d
1 file changed
+23 -4
+23 -4
View File
@@ -94,7 +94,7 @@ class FileDataNode implements DataNode {
} }
} }
expandSelf(recursive?: boolean) { expandSelf(recursive: boolean = true) {
if (this.isFolder) this.children = this.loadChilds(recursive); if (this.isFolder) this.children = this.loadChilds(recursive);
} }
@@ -121,6 +121,20 @@ class FileDataNode implements DataNode {
return ret; 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; // name:string;
// path: string; // path: string;
// isFolder : boolean; // isFolder : boolean;
@@ -242,13 +256,20 @@ export default class Properties extends Component<PropertiesProps> {
}) })
.filter((item, i, self) => item && self.indexOf(item) === i); .filter((item, i, self) => item && self.indexOf(item) === i);
if (value && value.length > 0) { if (value && value.length > 0) {
const root = this.state.root;
root.removeChilds(value);
this.setState({ this.setState({
root:root,
searchKey: value, searchKey: value,
expandedKeys: expandedKeys, expandedKeys: expandedKeys,
autoExpandParent: true, autoExpandParent: true,
}); });
} else { } else {
const root = this.getRootNode(this.props.workdir);
root.expandSelf();
this.setState({ this.setState({
root:root,
searchKey: "", searchKey: "",
expandedKeys: this.state.defaultExpandedKeys, expandedKeys: this.state.defaultExpandedKeys,
autoExpandParent: false, autoExpandParent: false,
@@ -261,7 +282,6 @@ export default class Properties extends Component<PropertiesProps> {
filterNode(node: EventDataNode): boolean { filterNode(node: EventDataNode): boolean {
const searchKey = this.state.searchKey; const searchKey = this.state.searchKey;
const nodeKey = node.title as string; const nodeKey = node.title as string;
return nodeKey.includes(searchKey); return nodeKey.includes(searchKey);
} }
@@ -324,13 +344,12 @@ export default class Properties extends Component<PropertiesProps> {
filterTreeNode={this.filterNode.bind(this)} filterTreeNode={this.filterNode.bind(this)}
defaultExpandedKeys={[root.key]} defaultExpandedKeys={[root.key]}
onSelect={(keys, info) => { onSelect={(keys, info) => {
console.log("onSelect", keys, info); //console.log("onSelect", keys, info);
if (info.node.isLeaf) { if (info.node.isLeaf) {
onOpenTree(keys[0] as string); onOpenTree(keys[0] as string);
} }
}} }}
onExpand={(keys, info) => { onExpand={(keys, info) => {
console.log("onExpand", info);
this.setState({ this.setState({
expandedKeys: keys, expandedKeys: keys,
autoExpandParent: false autoExpandParent: false