@@ -245,8 +245,8 @@ const DirectoryTreeView = () => {
245
245
useEffect ( ( ) => {
246
246
console . log ( treeData ) ;
247
247
if ( treeData . length > 3 ) {
248
- setExpandedIds ( [ 'datastore_folder' ] ) ;
249
- setKey ( treeData . length ) ;
248
+ setExpandedIds ( [ 'datastore_folder' , '11785' ] ) ;
249
+ // setKey(treeData.length + 1 );
250
250
}
251
251
} , [ treeData ] ) ;
252
252
@@ -286,22 +286,49 @@ const DirectoryTreeView = () => {
286
286
const onExpand = ( value ) => {
287
287
console . log ( value ) ;
288
288
const tempData = treeData ;
289
- const newChildren = [ ] ;
290
289
291
290
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 ,
299
298
children : [ ] ,
300
- parent : node . id ,
299
+ parent : value . element . id ,
301
300
metadata : { } ,
302
301
} ) ;
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 ) ;
303
328
console . log ( tempData ) ;
329
+ setTreeIds ( tempIdsArray ) ;
304
330
setTreeData ( tempData ) ;
331
+ setKey ( Math . random ( ) ) ;
305
332
}
306
333
} ) ;
307
334
} ) ;
0 commit comments