@@ -245,8 +245,8 @@ const DirectoryTreeView = () => {
245245 useEffect ( ( ) => {
246246 console . log ( treeData ) ;
247247 if ( treeData . length > 3 ) {
248- setExpandedIds ( [ 'datastore_folder' ] ) ;
249- setKey ( treeData . length ) ;
248+ setExpandedIds ( [ 'datastore_folder' , '11785' ] ) ;
249+ // setKey(treeData.length + 1 );
250250 }
251251 } , [ treeData ] ) ;
252252
@@ -286,22 +286,49 @@ const DirectoryTreeView = () => {
286286 const onExpand = ( value ) => {
287287 console . log ( value ) ;
288288 const tempData = treeData ;
289- const newChildren = [ ] ;
290289
291290 if ( value && value . element && value . element . id !== 'datastore_folder' ) {
292- API . get ( `/api/automate/${ value . element . name } ?depth=1` ) . then ( ( test ) => {
293- tempData . forEach ( ( node ) => {
294- if ( node . id === value . element . id ) {
295- node . children = [ 'new-test-0' ] ;
296- tempData . push ( {
297- id : 'new-test-0' ,
298- name : 'new test' ,
291+ API . get ( `/api/automate/${ value . element . name } ?depth=1` ) . then ( ( newNodes ) => {
292+ const newChildren = [ ] ;
293+ newNodes . resources . forEach ( ( newNode ) => {
294+ if ( value . element . id !== newNode . id ) {
295+ newChildren . push ( {
296+ id : newNode . id ,
297+ name : newNode . name ,
299298 children : [ ] ,
300- parent : node . id ,
299+ parent : value . element . id ,
301300 metadata : { } ,
302301 } ) ;
302+ }
303+ } ) ;
304+ console . log ( newChildren ) ;
305+ return newChildren ;
306+ } ) . then ( ( newChildrenArray ) => {
307+ console . log ( newChildrenArray ) ;
308+ const tempIdsArray = treeIds ;
309+ newChildrenArray . forEach ( ( node ) => {
310+ if ( ! treeIds . includes ( node . id ) ) {
311+ tempIdsArray . push ( node . id ) ;
312+ tempData . forEach ( ( parentNode ) => {
313+ if ( parentNode . id === node . parent ) {
314+ const childrenNodesToKeep = [ ] ;
315+ parentNode . children . forEach ( ( child ) => {
316+ console . log ( typeof child === 'string' ) ;
317+ console . log ( child ) ;
318+ if ( typeof child === 'string' ) {
319+ childrenNodesToKeep . push ( child ) ;
320+ }
321+ } ) ;
322+ console . log ( childrenNodesToKeep ) ;
323+ parentNode . children = childrenNodesToKeep ;
324+ parentNode . children = parentNode . children . concat ( node . id ) ;
325+ }
326+ } ) ;
327+ tempData . push ( node ) ;
303328 console . log ( tempData ) ;
329+ setTreeIds ( tempIdsArray ) ;
304330 setTreeData ( tempData ) ;
331+ setKey ( Math . random ( ) ) ;
305332 }
306333 } ) ;
307334 } ) ;
0 commit comments