update search state after rebuild graph tree
This commit is contained in:
1 parent
11b6a0b955
commit
6f4305b339
1 file changed
+16
-4
@@ -148,7 +148,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
index: 0,
|
index: 0,
|
||||||
filterStr: "",
|
filterStr: "",
|
||||||
filterCase: false,
|
filterCase: false,
|
||||||
filterFocus: false,
|
filterFocus: true,
|
||||||
filterType: "content",
|
filterType: "content",
|
||||||
placeholder: "",
|
placeholder: "",
|
||||||
});
|
});
|
||||||
@@ -170,6 +170,16 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
editor.graph.findAll("node", () => true).forEach((item) => item.draw());
|
editor.graph.findAll("node", () => true).forEach((item) => item.draw());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateSearchState = () => {
|
||||||
|
const option = { ...filterOption };
|
||||||
|
option.results.length = 0;
|
||||||
|
filterNodes(option, findDataById("1"));
|
||||||
|
setFilterOption({
|
||||||
|
...option,
|
||||||
|
});
|
||||||
|
editor.graph.findAll("node", () => true).forEach((item) => item.draw());
|
||||||
|
};
|
||||||
|
|
||||||
const onDebounceSearchChange = useDebounceCallback(onSearchChange, 200);
|
const onDebounceSearchChange = useDebounceCallback(onSearchChange, 200);
|
||||||
|
|
||||||
const onChange = () => {
|
const onChange = () => {
|
||||||
@@ -236,7 +246,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
|
|
||||||
const filterNodes = (option: FilterOption, node: TreeGraphData | null) => {
|
const filterNodes = (option: FilterOption, node: TreeGraphData | null) => {
|
||||||
if (node) {
|
if (node) {
|
||||||
node.highlightGray = option.filterFocus;
|
node.highlightGray = option.filterFocus && !!option.filterStr;
|
||||||
if (option.filterStr) {
|
if (option.filterStr) {
|
||||||
let found = false;
|
let found = false;
|
||||||
if (option.filterType === "id") {
|
if (option.filterType === "id") {
|
||||||
@@ -577,6 +587,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
if (editor.historyIndex > 0) {
|
if (editor.historyIndex > 0) {
|
||||||
const data = editor.historyStack[--editor.historyIndex];
|
const data = editor.historyStack[--editor.historyIndex];
|
||||||
useStackData(data);
|
useStackData(data);
|
||||||
|
updateSearchState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -584,6 +595,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
if (editor.historyIndex < editor.historyStack.length - 1) {
|
if (editor.historyIndex < editor.historyStack.length - 1) {
|
||||||
const data = editor.historyStack[++editor.historyIndex];
|
const data = editor.historyStack[++editor.historyIndex];
|
||||||
useStackData(data);
|
useStackData(data);
|
||||||
|
updateSearchState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -613,7 +625,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
editor.graph.changeData(editor.data);
|
editor.graph.changeData(editor.data);
|
||||||
editor.graph.layout();
|
editor.graph.layout();
|
||||||
restoreViewport();
|
restoreViewport();
|
||||||
|
updateSearchState();
|
||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1273,7 +1285,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
results: [],
|
results: [],
|
||||||
index: 0,
|
index: 0,
|
||||||
filterCase: false,
|
filterCase: false,
|
||||||
filterFocus: false,
|
filterFocus: true,
|
||||||
filterStr: "",
|
filterStr: "",
|
||||||
filterType: "content",
|
filterType: "content",
|
||||||
placeholder: "",
|
placeholder: "",
|
||||||
|
|||||||
Reference in new issue
Block a user