diff --git a/src/components/tree/TreeInteractiveViewer.tsx b/src/components/tree/TreeInteractiveViewer.tsx index 8d33aa3..03766f2 100644 --- a/src/components/tree/TreeInteractiveViewer.tsx +++ b/src/components/tree/TreeInteractiveViewer.tsx @@ -28,6 +28,17 @@ export function TreeInteractiveViewer() { const [highlighter, setHighlighter] = useState(null) + useEffect(() => { + + if (loading) { + return; + } + + treeStore.cy.fit(); + + }, [loading]); + + useEffect(() => { fetch('/api/get-nodes', { @@ -67,13 +78,14 @@ export function TreeInteractiveViewer() { handleHighlight(evt); - if (evt.target !== treeStore.cy && !evt.target.isNode()) { + const target = evt.target; + + if (target === treeStore.cy || !target.isNode()) { + treeStore.setSelected(null); return; } - const node = evt.target; - treeStore.cy.center(node); - treeStore.setSelected(node.data()); + treeStore.setSelected(target.data()); } @@ -124,9 +136,6 @@ export function TreeInteractiveViewer() { cy={(cy) => { treeStore.cy = cy; cy.on('tap', handleNodeClick); - cy.on('unselect', 'node', () => { - treeStore.setSelected(null); - }); }} /> )} diff --git a/src/components/tree/TreeViewToolbar.tsx b/src/components/tree/TreeViewToolbar.tsx index 926edb4..3bea726 100644 --- a/src/components/tree/TreeViewToolbar.tsx +++ b/src/components/tree/TreeViewToolbar.tsx @@ -26,40 +26,41 @@ export function TreeViewToolbar() { function SearchField() { + const treeStore = useTreeStore(); + const [inputValue, setInputValue] = useState(""); const [filteredData, setFilteredData] = useState([]); const [loading, setLoading] = useState(false); const debounceFilter = debounce(handleChange, 1e3); function handleChange(e: ChangeEvent) { + setLoading(true); setInputValue(e.target.value); filter(); } function filter() { - setLoading(true); fetch('/api/search-node', { method: 'POST', body: JSON.stringify({value: inputValue}), - headers: { - 'Content-Type': 'application/json' - } }) .then(response => response.json()) - .then((data: TreeNodeDefinition[]) => { - setFilteredData(data); - }) - .catch(error => { - console.error('Error:', error); - }) + .then((data: TreeNodeDefinition[]) => setFilteredData(data)) + .catch(error => console.error('Error:', error)) .finally(() => setLoading(false)); } const handleClick = (node: TreeNodeDefinition) => { - console.log(node); + + if (!node.data.id) { + return; + } + + treeStore.setSelected(node.data) + setInputValue(""); } return ( @@ -67,10 +68,11 @@ function SearchField() {
- {/*