1
+ // todo: tableTree is very smart, so it is impossible to update it without re-render
2
+ // It is need change NavigationTree to dump component and pass props from parent component
3
+ // In this case we can store state of tree - uploaded entities, opened nodes, selected entity and so on
1
4
import React from 'react' ;
2
5
3
6
import { NavigationTree } from 'ydb-ui-components' ;
@@ -8,6 +11,7 @@ import {useQueryModes, useTypedDispatch} from '../../../../utils/hooks';
8
11
import { isChildlessPathType , mapPathTypeToNavigationTreeType } from '../../utils/schema' ;
9
12
import { getActions } from '../../utils/schemaActions' ;
10
13
import { getControls } from '../../utils/schemaControls' ;
14
+ import { CreateDirectoryDialog } from '../CreateDirectoryDialog/CreateDirectoryDialog' ;
11
15
12
16
interface SchemaTreeProps {
13
17
rootPath : string ;
@@ -19,10 +23,12 @@ interface SchemaTreeProps {
19
23
20
24
export function SchemaTree ( props : SchemaTreeProps ) {
21
25
const { rootPath, rootName, rootType, currentPath, onActivePathUpdate} = props ;
22
-
23
26
const dispatch = useTypedDispatch ( ) ;
24
27
25
28
const [ _ , setQueryMode ] = useQueryModes ( ) ;
29
+ const [ createDirectoryOpen , setCreateDirectoryOpen ] = React . useState ( false ) ;
30
+ const [ parentPath , setParentPath ] = React . useState ( '' ) ;
31
+ const [ schemaTreeKey , setSchemaTreeKey ] = React . useState ( '' ) ;
26
32
27
33
const fetchPath = async ( path : string ) => {
28
34
const promise = dispatch (
@@ -49,34 +55,57 @@ export function SchemaTree(props: SchemaTreeProps) {
49
55
50
56
return childItems ;
51
57
} ;
52
-
53
58
React . useEffect ( ( ) => {
54
59
// if the cached path is not in the current tree, show root
55
60
if ( ! currentPath ?. startsWith ( rootPath ) ) {
56
61
onActivePathUpdate ( rootPath ) ;
57
62
}
58
63
} , [ currentPath , onActivePathUpdate , rootPath ] ) ;
59
64
65
+ const handleSuccessSubmit = ( relativePath : string ) => {
66
+ const newPath = `${ parentPath } /${ relativePath } ` ;
67
+ onActivePathUpdate ( newPath ) ;
68
+ setSchemaTreeKey ( newPath ) ;
69
+ } ;
70
+
71
+ const handleCloseDialog = ( ) => {
72
+ setCreateDirectoryOpen ( false ) ;
73
+ } ;
74
+
75
+ const handleOpenCreateDirectoryDialog = ( value : string ) => {
76
+ setParentPath ( value ) ;
77
+ setCreateDirectoryOpen ( true ) ;
78
+ } ;
60
79
return (
61
- < NavigationTree
62
- rootState = { {
63
- path : rootPath ,
64
- name : rootName ,
65
- type : mapPathTypeToNavigationTreeType ( rootType ) ,
66
- collapsed : false ,
67
- } }
68
- fetchPath = { fetchPath }
69
- getActions = { getActions ( dispatch , {
70
- setActivePath : onActivePathUpdate ,
71
- setQueryMode,
72
- } ) }
73
- renderAdditionalNodeElements = { getControls ( dispatch , {
74
- setActivePath : onActivePathUpdate ,
75
- } ) }
76
- activePath = { currentPath }
77
- onActivePathUpdate = { onActivePathUpdate }
78
- cache = { false }
79
- virtualize
80
- />
80
+ < React . Fragment >
81
+ < CreateDirectoryDialog
82
+ onClose = { handleCloseDialog }
83
+ open = { createDirectoryOpen }
84
+ parentPath = { parentPath }
85
+ onSuccess = { handleSuccessSubmit }
86
+ />
87
+ < NavigationTree
88
+ key = { schemaTreeKey }
89
+ rootState = { {
90
+ path : rootPath ,
91
+ name : rootName ,
92
+ type : mapPathTypeToNavigationTreeType ( rootType ) ,
93
+ collapsed : false ,
94
+ } }
95
+ fetchPath = { fetchPath }
96
+ getActions = { getActions ( dispatch , {
97
+ setActivePath : onActivePathUpdate ,
98
+ setQueryMode,
99
+ showCreateDirectoryDialog : handleOpenCreateDirectoryDialog ,
100
+ } ) }
101
+ renderAdditionalNodeElements = { getControls ( dispatch , {
102
+ setActivePath : onActivePathUpdate ,
103
+ } ) }
104
+ activePath = { currentPath }
105
+ onActivePathUpdate = { onActivePathUpdate }
106
+ cache = { false }
107
+ virtualize
108
+ />
109
+ </ React . Fragment >
81
110
) ;
82
111
}
0 commit comments