@@ -167,29 +167,38 @@ export function CodeGraph({
167167 }
168168
169169 const deleteNeighbors = ( nodes : Node [ ] ) => {
170+
170171 if ( nodes . length === 0 ) return ;
171-
172+
173+ const expandedNodes : Node [ ] = [ ]
174+
172175 graph . Elements = {
173- nodes : graph . Elements . nodes . map ( node => {
176+ nodes : graph . Elements . nodes . filter ( node => {
177+ if ( ! node . collapsed ) return true
178+
174179 const isTarget = graph . Elements . links . some ( link => link . target . id === node . id && nodes . some ( n => n . id === link . source . id ) ) ;
180+
181+ debugger
182+
183+ if ( ! isTarget ) return true
175184
176- if ( ! isTarget || ! node . collapsed ) return node
185+ const deleted = graph . NodesMap . delete ( Number ( node . id ) )
177186
178- if ( node . expand ) {
179- node . expand = false
180- deleteNeighbors ( [ node ] )
187+ if ( deleted && node . expand ) {
188+ expandedNodes . push ( node )
181189 }
182190
183- graph . NodesMap . delete ( Number ( node . id ) )
184- } ) . filter ( node => node !== undefined ) ,
191+ return false
192+ } ) ,
185193 links : graph . Elements . links
186194 }
195+
196+ deleteNeighbors ( expandedNodes )
187197
188198 graph . removeLinks ( )
189199 }
190200
191201 const handleExpand = async ( nodes : Node [ ] , expand : boolean ) => {
192-
193202 if ( expand ) {
194203 const elements = await onFetchNode ( nodes . map ( n => n . id ) )
195204
@@ -219,7 +228,6 @@ export function CodeGraph({
219228 const chart = chartRef . current
220229
221230 if ( chart ) {
222- const n = { name : node . properties . name , id : node . id }
223231
224232 let chartNode = graph . Elements . nodes . find ( n => n . id == node . id )
225233
@@ -234,8 +242,8 @@ export function CodeGraph({
234242 graph . visibleLinks ( true , [ chartNode ! . id ] )
235243 setData ( { ...graph . Elements } )
236244 }
237-
238- setSearchNode ( n )
245+
246+ setSearchNode ( chartNode )
239247 setTimeout ( ( ) => {
240248 chart . zoomToFit ( 1000 , 150 , ( n : NodeObject < Node > ) => n . id === chartNode ! . id ) ;
241249 } , 0 )
@@ -299,8 +307,7 @@ export function CodeGraph({
299307 < div className = 'flex gap-4' >
300308 < Input
301309 graph = { graph }
302- value = { searchNode . name || "" }
303- onValueChange = { ( { name } ) => setSearchNode ( { name } ) }
310+ onValueChange = { ( node ) => setSearchNode ( node ) }
304311 icon = { < Search /> }
305312 handleSubmit = { handleSearchSubmit }
306313 node = { searchNode }
@@ -405,7 +412,7 @@ export function CodeGraph({
405412 setSelectedObjects = { setSelectedObjects }
406413 setPosition = { setPosition }
407414 onFetchNode = { onFetchNode }
408- deleteNeighbors = { deleteNeighbors }
415+ handleExpand = { handleExpand }
409416 isShowPath = { isShowPath }
410417 setPath = { setPath }
411418 isPathResponse = { isPathResponse }
0 commit comments