11import { useEffect , useRef , useMemo } from 'react' ;
2- import { useDispatch , useSelector } from 'react-redux' ;
2+ import { useDispatch } from 'react-redux' ;
33import url from 'url' ;
44import _ from 'lodash' ;
55
66import cn from 'bem-cn-lite' ;
77
8- import { PDisk } from './Pdisk' ;
98import { Loader } from '../.././../components/Loader' ;
109
11- import { getNodeStructure , selectNodeStructure } from '../../../store/reducers/node' ;
10+ import { getNodeStructure } from '../../../store/reducers/node/node' ;
11+ import { selectNodeStructure } from '../../../store/reducers/node/selectors' ;
1212
1313import { AutoFetcher } from '../../../utils/autofetcher' ;
14+ import { useTypedSelector } from '../../../utils/hooks' ;
15+
16+ import { PDisk } from './Pdisk' ;
1417
1518import './NodeStructure.scss' ;
1619
@@ -32,20 +35,19 @@ interface NodeStructureProps {
3235
3336const autofetcher = new AutoFetcher ( ) ;
3437
35- function NodeStructure ( props : NodeStructureProps ) {
38+ function NodeStructure ( { nodeId , className , additionalNodesInfo } : NodeStructureProps ) {
3639 const dispatch = useDispatch ( ) ;
3740
38- const nodeStructure : any = useSelector ( selectNodeStructure ) ;
41+ const nodeStructure = useTypedSelector ( selectNodeStructure ) ;
3942
40- const loadingStructure = useSelector ( ( state : any ) => state . node . loadingStructure ) ;
41- const wasLoadedStructure = useSelector ( ( state : any ) => state . node . wasLoadedStructure ) ;
42- const nodeData = useSelector ( ( state : any ) => state . node ?. data ?. SystemStateInfo ?. [ 0 ] ) ;
43+ const { loadingStructure, wasLoadedStructure} = useTypedSelector ( ( state ) => state . node ) ;
44+ const nodeData = useTypedSelector ( ( state ) => state . node ?. data ?. SystemStateInfo ?. [ 0 ] ) ;
4345
4446 const nodeHref = useMemo ( ( ) => {
45- return props . additionalNodesInfo ?. getNodeRef
46- ? props . additionalNodesInfo . getNodeRef ( nodeData )
47+ return additionalNodesInfo ?. getNodeRef
48+ ? additionalNodesInfo . getNodeRef ( nodeData )
4749 : undefined ;
48- } , [ nodeData , props . additionalNodesInfo ] ) ;
50+ } , [ nodeData , additionalNodesInfo ] ) ;
4951
5052 const { pdiskId : pdiskIdFromUrl , vdiskId : vdiskIdFromUrl } = url . parse (
5153 window . location . href ,
@@ -71,16 +73,16 @@ function NodeStructure(props: NodeStructureProps) {
7173 } , [ ] ) ;
7274
7375 useEffect ( ( ) => {
74- dispatch ( getNodeStructure ( props . nodeId ) ) ;
76+ dispatch ( getNodeStructure ( nodeId ) ) ;
7577 autofetcher . start ( ) ;
76- autofetcher . fetch ( ( ) => dispatch ( getNodeStructure ( props . nodeId ) ) ) ;
78+ autofetcher . fetch ( ( ) => dispatch ( getNodeStructure ( nodeId ) ) ) ;
7779
7880 return ( ) => {
7981 scrolled . current = false ;
8082 isReady . current = false ;
8183 autofetcher . stop ( ) ;
8284 } ;
83- } , [ props . nodeId , dispatch ] ) ;
85+ } , [ nodeId , dispatch ] ) ;
8486
8587 useEffect ( ( ) => {
8688 if ( ! _ . isEmpty ( nodeStructure ) && scrollContainer ) {
@@ -98,9 +100,9 @@ function NodeStructure(props: NodeStructureProps) {
98100
99101 if ( vdiskIdFromUrl ) {
100102 const vDisks = nodeStructure [ pdiskIdFromUrl as string ] ?. vDisks ;
101- const vDisk = vDisks ?. find ( ( el : any ) => el . id === vdiskIdFromUrl ) ;
103+ const vDisk = vDisks ?. find ( ( el ) => el . id === vdiskIdFromUrl ) ;
102104 const dataTable = vDisk ? document . querySelector ( '.data-table' ) : undefined ;
103- const order = vDisk ?. order ;
105+ const order = vDisk ?. order || 0 ;
104106
105107 if ( dataTable ) {
106108 scrollToVdisk += ( dataTable as HTMLElement ) . offsetTop + 40 * order ;
@@ -147,7 +149,7 @@ function NodeStructure(props: NodeStructureProps) {
147149
148150 return (
149151 < div className = { b ( ) } ref = { scrollContainerRef } >
150- < div className = { props . className } > { renderContent ( ) } </ div >
152+ < div className = { className } > { renderContent ( ) } </ div >
151153 </ div >
152154 ) ;
153155}
0 commit comments