@@ -60,50 +60,56 @@ export function SchemaTree(props: SchemaTreeProps) {
60
60
? 'database'
61
61
: mapPathTypeToNavigationTreeType ( rootType ) ;
62
62
63
- const fetchPath = async ( path : string ) => {
64
- let schemaData : TEvDescribeSchemeResult | undefined ;
65
- do {
66
- const promise = dispatch (
67
- schemaApi . endpoints . getSchema . initiate (
68
- { path, database, databaseFullPath} ,
69
- { forceRefetch : true } ,
70
- ) ,
71
- ) ;
72
- const { data, originalArgs} = await promise ;
73
- promise . unsubscribe ( ) ;
74
- // Check if the result from the current request is received. rtk-query may skip the current request and
75
- // return data from a parallel request, due to the same cache key.
76
- if ( originalArgs ?. path === path ) {
77
- schemaData = data ?. [ path ] ;
78
- break ;
63
+ const fetchPath = React . useCallback (
64
+ async ( path : string ) => {
65
+ let schemaData : TEvDescribeSchemeResult | undefined ;
66
+
67
+ do {
68
+ const promise = dispatch (
69
+ schemaApi . endpoints . getSchema . initiate (
70
+ { path, database, databaseFullPath} ,
71
+ { forceRefetch : true } ,
72
+ ) ,
73
+ ) ;
74
+
75
+ const { data, originalArgs} = await promise ;
76
+ promise . unsubscribe ( ) ;
77
+ // Check if the result from the current request is reonceived. rtk-query may skip the current request and
78
+ // return data from a parallel request, due to the same cache key.
79
+ if ( originalArgs ?. path === path ) {
80
+ schemaData = data ?. [ path ] ;
81
+ break ;
82
+ }
83
+ // eslint-disable-next-line no-constant-condition
84
+ } while ( true ) ;
85
+
86
+ if ( ! schemaData ) {
87
+ throw new Error ( `No describe data about path ${ path } ` ) ;
79
88
}
80
- // eslint-disable-next-line no-constant-condition
81
- } while ( true ) ;
82
89
83
- if ( ! schemaData ) {
84
- throw new Error ( `no describe data about path ${ path } ` ) ;
85
- }
86
- const { PathDescription : { Children = [ ] } = { } } = schemaData ;
87
-
88
- const childItems = Children . map ( ( childData ) => {
89
- const { Name = '' , PathType, PathSubType, ChildrenExist} = childData ;
90
-
91
- const isChildless =
92
- isChildlessPathType ( PathType , PathSubType ) ||
93
- ( valueIsDefined ( ChildrenExist ) && ! ChildrenExist ) ;
94
-
95
- return {
96
- name : Name ,
97
- type : mapPathTypeToNavigationTreeType ( PathType , PathSubType ) ,
98
- // FIXME: should only be explicitly set to true for tables with indexes
99
- // at the moment of writing there is no property to determine this, fix later
100
- expandable : ! isChildless ,
101
- meta : { subType : PathSubType } ,
102
- } ;
103
- } ) ;
104
-
105
- return childItems ;
106
- } ;
90
+ const { PathDescription : { Children = [ ] } = { } } = schemaData ;
91
+
92
+ const childItems = Children . map ( ( childData ) => {
93
+ const { Name = '' , PathType, PathSubType, ChildrenExist} = childData ;
94
+
95
+ const isChildless =
96
+ isChildlessPathType ( PathType , PathSubType ) ||
97
+ ( valueIsDefined ( ChildrenExist ) && ! ChildrenExist ) ;
98
+
99
+ return {
100
+ name : Name ,
101
+ type : mapPathTypeToNavigationTreeType ( PathType , PathSubType ) ,
102
+ // FIXME: should only be explicitly set to true for tables with indexes
103
+ // at the moment of writing there is no property to determine this, fix later
104
+ expandable : ! isChildless ,
105
+ meta : { subType : PathSubType } ,
106
+ } ;
107
+ } ) ;
108
+
109
+ return childItems ;
110
+ } ,
111
+ [ dispatch , database , databaseFullPath ] ,
112
+ ) ;
107
113
React . useEffect ( ( ) => {
108
114
// if the cached path is not in the current tree, show root
109
115
if ( ! currentPath ?. startsWith ( databaseFullPath ) ) {
0 commit comments