fix: trigger onFilterResultChanged when filtered

This commit is contained in:
LiuTeiTei 2024-01-04 18:20:22 +08:00 committed by 刘菊萍(絮黎)
parent 173978ffd4
commit e1f3a11c41
3 changed files with 33 additions and 10 deletions

View File

@ -77,6 +77,11 @@ export const matchTreeNode = (
return matchTreeNode(childNode, keywords, filterOps); return matchTreeNode(childNode, keywords, filterOps);
}).find(Boolean); }).find(Boolean);
// 如果命中了子节点,需要将该节点展开
if (matchChild && treeNode.expandable) {
treeNode.setExpanded(true);
}
treeNode.setFilterReult({ treeNode.setFilterReult({
filterWorking: true, filterWorking: true,
matchChild, matchChild,

View File

@ -34,7 +34,7 @@ class ModalTreeNodeView extends PureComponent<{
} }
componentDidMount(): void { componentDidMount(): void {
const rootTreeNode = this.rootTreeNode; const { rootTreeNode } = this;
rootTreeNode.onExpandableChanged(() => { rootTreeNode.onExpandableChanged(() => {
this.setState({ this.setState({
treeChildren: rootTreeNode.children, treeChildren: rootTreeNode.children,
@ -53,7 +53,7 @@ class ModalTreeNodeView extends PureComponent<{
} }
render() { render() {
const rootTreeNode = this.rootTreeNode; const { rootTreeNode } = this;
const { expanded } = rootTreeNode; const { expanded } = rootTreeNode;
const hasVisibleModalNode = !!this.modalNodesManager?.getVisibleModalNode(); const hasVisibleModalNode = !!this.modalNodesManager?.getVisibleModalNode();
@ -98,6 +98,9 @@ export default class TreeNodeView extends PureComponent<{
conditionFlow: boolean; conditionFlow: boolean;
expandable: boolean; expandable: boolean;
treeChildren: TreeNode[] | null; treeChildren: TreeNode[] | null;
filterWorking: boolean;
matchChild: boolean;
matchSelf: boolean;
} = { } = {
expanded: false, expanded: false,
selected: false, selected: false,
@ -110,6 +113,9 @@ export default class TreeNodeView extends PureComponent<{
conditionFlow: false, conditionFlow: false,
expandable: false, expandable: false,
treeChildren: [], treeChildren: [],
filterWorking: false,
matchChild: false,
matchSelf: false,
}; };
eventOffCallbacks: Array<IPublicTypeDisposable | undefined> = []; eventOffCallbacks: Array<IPublicTypeDisposable | undefined> = [];
@ -154,6 +160,10 @@ export default class TreeNodeView extends PureComponent<{
treeChildren: treeNode.children, treeChildren: treeNode.children,
}); });
}); });
treeNode.onFilterResultChanged(() => {
const { filterWorking: newFilterWorking, matchChild: newMatchChild, matchSelf: newMatchSelf } = treeNode.filterReult;
this.setState({ filterWorking: newFilterWorking, matchChild: newMatchChild, matchSelf: newMatchSelf });
});
this.eventOffCallbacks.push( this.eventOffCallbacks.push(
doc?.onDropLocationChanged(() => { doc?.onDropLocationChanged(() => {
this.setState({ this.setState({
@ -216,7 +226,7 @@ export default class TreeNodeView extends PureComponent<{
let shouldShowModalTreeNode: boolean = this.shouldShowModalTreeNode(); let shouldShowModalTreeNode: boolean = this.shouldShowModalTreeNode();
// filter 处理 // filter 处理
const { filterWorking, matchChild, matchSelf } = treeNode.filterReult; const { filterWorking, matchChild, matchSelf } = this.state;
if (!isRootNode && filterWorking && !matchChild && !matchSelf) { if (!isRootNode && filterWorking && !matchChild && !matchSelf) {
// 条件过滤生效时,如果未命中本节点或子节点,则不展示该节点 // 条件过滤生效时,如果未命中本节点或子节点,则不展示该节点
// 根节点始终展示 // 根节点始终展示

View File

@ -29,9 +29,15 @@ export default class TreeTitle extends PureComponent<{
title: string; title: string;
condition?: boolean; condition?: boolean;
visible?: boolean; visible?: boolean;
filterWorking: boolean;
keywords: string;
matchSelf: boolean;
} = { } = {
editing: false, editing: false,
title: '', title: '',
filterWorking: false,
keywords: '',
matchSelf: false,
}; };
private lastInput?: HTMLInputElement; private lastInput?: HTMLInputElement;
@ -100,6 +106,10 @@ export default class TreeTitle extends PureComponent<{
visible: !hidden, visible: !hidden,
}); });
}); });
treeNode.onFilterResultChanged(() => {
const { filterWorking: newFilterWorking, keywords: newKeywords, matchSelf: newMatchSelf } = treeNode.filterReult;
this.setState({ filterWorking: newFilterWorking, keywords: newKeywords, matchSelf: newMatchSelf });
});
} }
deleteClick = () => { deleteClick = () => {
const { treeNode } = this.props; const { treeNode } = this.props;
@ -109,7 +119,7 @@ export default class TreeTitle extends PureComponent<{
render() { render() {
const { treeNode, isModal } = this.props; const { treeNode, isModal } = this.props;
const { pluginContext } = treeNode; const { pluginContext } = treeNode;
const { editing } = this.state; const { editing, filterWorking, matchSelf, keywords } = this.state;
const isCNode = !treeNode.isRoot(); const isCNode = !treeNode.isRoot();
const { node } = treeNode; const { node } = treeNode;
const { componentMeta } = node; const { componentMeta } = node;
@ -125,11 +135,9 @@ export default class TreeTitle extends PureComponent<{
marginLeft: -indent, marginLeft: -indent,
}; };
} }
const { filterWorking, matchSelf, keywords } = treeNode.filterReult;
const Extra = pluginContext.extraTitle; const Extra = pluginContext.extraTitle;
const { intlNode, common, config } = pluginContext; const { intlNode, common, config } = pluginContext;
const Tip = common.editorCabin.Tip; const { Tip, Title } = common.editorCabin;
const Title = common.editorCabin.Title;
const couldHide = availableActions.includes('hide'); const couldHide = availableActions.includes('hide');
const couldLock = availableActions.includes('lock'); const couldLock = availableActions.includes('lock');
const couldUnlock = availableActions.includes('unlock'); const couldUnlock = availableActions.includes('unlock');
@ -253,7 +261,7 @@ class RenameBtn extends PureComponent<{
}> { }> {
render() { render() {
const { intl, common } = this.props.treeNode.pluginContext; const { intl, common } = this.props.treeNode.pluginContext;
const Tip = common.editorCabin.Tip; const { Tip } = common.editorCabin;
return ( return (
<div <div
className="tree-node-rename-btn" className="tree-node-rename-btn"
@ -274,7 +282,7 @@ class LockBtn extends PureComponent<{
render() { render() {
const { treeNode, locked } = this.props; const { treeNode, locked } = this.props;
const { intl, common } = this.props.treeNode.pluginContext; const { intl, common } = this.props.treeNode.pluginContext;
const Tip = common.editorCabin.Tip; const { Tip } = common.editorCabin;
return ( return (
<div <div
className="tree-node-lock-btn" className="tree-node-lock-btn"
@ -300,7 +308,7 @@ class HideBtn extends PureComponent<{
render() { render() {
const { treeNode, hidden } = this.props; const { treeNode, hidden } = this.props;
const { intl, common } = treeNode.pluginContext; const { intl, common } = treeNode.pluginContext;
const Tip = common.editorCabin.Tip; const { Tip } = common.editorCabin;
return ( return (
<div <div
className="tree-node-hide-btn" className="tree-node-hide-btn"