@@ -28,7 +28,6 @@ interface NodeStructureProps {
28
28
nodeId : string ;
29
29
className ?: string ;
30
30
additionalNodesInfo ?: any ;
31
- scrollContainer : Element | null ;
32
31
}
33
32
34
33
const autofetcher = new AutoFetcher ( ) ;
@@ -40,9 +39,7 @@ function NodeStructure(props: NodeStructureProps) {
40
39
41
40
const loadingStructure = useSelector ( ( state : any ) => state . node . loadingStructure ) ;
42
41
const wasLoadedStructure = useSelector ( ( state : any ) => state . node . wasLoadedStructure ) ;
43
- const nodeData = useSelector (
44
- ( state : any ) => state . node ?. data ?. SystemStateInfo ?. [ 0 ]
45
- ) ;
42
+ const nodeData = useSelector ( ( state : any ) => state . node ?. data ?. SystemStateInfo ?. [ 0 ] ) ;
46
43
47
44
const nodeHref = useMemo ( ( ) => {
48
45
return props . additionalNodesInfo ?. getNodeRef
@@ -55,13 +52,15 @@ function NodeStructure(props: NodeStructureProps) {
55
52
true ,
56
53
) . query ;
57
54
55
+ const scrollContainerRef = useRef < HTMLDivElement > ( null ) ;
56
+ const scrollContainer = scrollContainerRef . current ;
57
+
58
58
const isReady = useRef ( false ) ;
59
59
60
60
const scrolled = useRef ( false ) ;
61
61
62
62
useEffect ( ( ) => {
63
63
return ( ) => {
64
- const { scrollContainer} = props ;
65
64
if ( scrollContainer ) {
66
65
scrollContainer . scrollTo ( {
67
66
behavior : 'smooth' ,
@@ -84,13 +83,12 @@ function NodeStructure(props: NodeStructureProps) {
84
83
} , [ props . nodeId , dispatch ] ) ;
85
84
86
85
useEffect ( ( ) => {
87
- if ( ! _ . isEmpty ( nodeStructure ) && props . scrollContainer ) {
86
+ if ( ! _ . isEmpty ( nodeStructure ) && scrollContainer ) {
88
87
isReady . current = true ;
89
88
}
90
- } , [ nodeStructure , props . scrollContainer ] ) ;
89
+ } , [ nodeStructure ] ) ;
91
90
92
91
useEffect ( ( ) => {
93
- const { scrollContainer} = props ;
94
92
if ( isReady . current && ! scrolled . current && scrollContainer ) {
95
93
const element = document . getElementById (
96
94
generateId ( { type : 'pdisk' , id : pdiskIdFromUrl as string } ) ,
@@ -105,20 +103,20 @@ function NodeStructure(props: NodeStructureProps) {
105
103
const order = vDisk ?. order ;
106
104
107
105
if ( dataTable ) {
108
- scrollToVdisk += ( dataTable as HTMLElement ) . offsetTop + 40 * ( order + 1 ) ;
106
+ scrollToVdisk += ( dataTable as HTMLElement ) . offsetTop + 40 * order ;
109
107
}
110
108
}
111
109
112
110
if ( element ) {
113
111
scrollContainer . scrollTo ( {
114
112
behavior : 'smooth' ,
115
113
// should subtract 20 to avoid sticking the element to tabs
116
- top : scrollToVdisk ? scrollToVdisk : element . offsetTop - 20 ,
114
+ top : scrollToVdisk ? scrollToVdisk : element . offsetTop ,
117
115
} ) ;
118
116
scrolled . current = true ;
119
117
}
120
118
}
121
- } , [ nodeStructure , props . scrollContainer , pdiskIdFromUrl , vdiskIdFromUrl ] ) ;
119
+ } , [ nodeStructure , pdiskIdFromUrl , vdiskIdFromUrl ] ) ;
122
120
123
121
const renderStub = ( ) => {
124
122
return 'There is no information about node structure.' ;
@@ -147,7 +145,11 @@ function NodeStructure(props: NodeStructureProps) {
147
145
return renderStructure ( ) ;
148
146
} ;
149
147
150
- return < div className = { b ( null , props . className ) } > { renderContent ( ) } </ div > ;
148
+ return (
149
+ < div className = { b ( ) } ref = { scrollContainerRef } >
150
+ < div className = { props . className } > { renderContent ( ) } </ div >
151
+ </ div >
152
+ ) ;
151
153
}
152
154
153
155
export default NodeStructure ;
0 commit comments