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
14import React from 'react' ;
25
36import { NavigationTree } from 'ydb-ui-components' ;
@@ -8,6 +11,7 @@ import {useQueryModes, useTypedDispatch} from '../../../../utils/hooks';
811import { isChildlessPathType , mapPathTypeToNavigationTreeType } from '../../utils/schema' ;
912import { getActions } from '../../utils/schemaActions' ;
1013import { getControls } from '../../utils/schemaControls' ;
14+ import { CreateDirectoryDialog } from '../CreateDirectoryDialog/CreateDirectoryDialog' ;
1115
1216interface SchemaTreeProps {
1317 rootPath : string ;
@@ -19,10 +23,12 @@ interface SchemaTreeProps {
1923
2024export function SchemaTree ( props : SchemaTreeProps ) {
2125 const { rootPath, rootName, rootType, currentPath, onActivePathUpdate} = props ;
22-
2326 const dispatch = useTypedDispatch ( ) ;
2427
2528 const [ _ , setQueryMode ] = useQueryModes ( ) ;
29+ const [ createDirectoryOpen , setCreateDirectoryOpen ] = React . useState ( false ) ;
30+ const [ parentPath , setParentPath ] = React . useState ( '' ) ;
31+ const [ schemaTreeKey , setSchemaTreeKey ] = React . useState ( '' ) ;
2632
2733 const fetchPath = async ( path : string ) => {
2834 const promise = dispatch (
@@ -49,34 +55,57 @@ export function SchemaTree(props: SchemaTreeProps) {
4955
5056 return childItems ;
5157 } ;
52-
5358 React . useEffect ( ( ) => {
5459 // if the cached path is not in the current tree, show root
5560 if ( ! currentPath ?. startsWith ( rootPath ) ) {
5661 onActivePathUpdate ( rootPath ) ;
5762 }
5863 } , [ currentPath , onActivePathUpdate , rootPath ] ) ;
5964
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+ } ;
6079 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 >
81110 ) ;
82111}
0 commit comments