11import React from 'react' ;
22
3- import { debounce } from 'lodash' ;
4-
53import { DiskStateProgressBar } from '../../../components/DiskStateProgressBar/DiskStateProgressBar' ;
64import { InternalLink } from '../../../components/InternalLink' ;
75import { PDiskPopup } from '../../../components/PDiskPopup/PDiskPopup' ;
86import { VDisk } from '../../../components/VDisk/VDisk' ;
9- import routes , { createHref , getPDiskPagePath } from '../../../routes' ;
7+ import { getPDiskPagePath } from '../../../routes' ;
108import { valueIsDefined } from '../../../utils' ;
119import { cn } from '../../../utils/cn' ;
1210import type { PreparedPDisk , PreparedVDisk } from '../../../utils/disks/types' ;
13- import { STRUCTURE } from '../../Node/NodePages ' ;
11+ import { usePopupAnchor } from '../../../utils/hooks/usePopupAnchor ' ;
1412import type { StorageViewContext } from '../types' ;
1513import { isVdiskActive } from '../utils' ;
1614
1715import './PDisk.scss' ;
1816
1917const b = cn ( 'pdisk-storage' ) ;
2018
21- const DEBOUNCE_TIMEOUT = 100 ;
22-
2319interface PDiskProps {
2420 data ?: PreparedPDisk ;
2521 vDisks ?: PreparedVDisk [ ] ;
@@ -41,23 +37,14 @@ export const PDisk = ({
4137 progressBarClassName,
4238 viewContext,
4339} : PDiskProps ) => {
44- const [ isPopupVisible , setIsPopupVisible ] = React . useState ( false ) ;
45-
46- const anchor = React . useRef ( null ) ;
40+ const { isPopupVisible, anchor, onMouseEnter, onMouseLeave, hidePopup} = usePopupAnchor (
41+ onShowPopup ,
42+ onHidePopup ,
43+ ) ;
4744
4845 const { NodeId, PDiskId} = data ;
4946 const pDiskIdsDefined = valueIsDefined ( NodeId ) && valueIsDefined ( PDiskId ) ;
5047
51- const debouncedHandleShowPopup = debounce ( ( ) => {
52- setIsPopupVisible ( true ) ;
53- onShowPopup ?.( ) ;
54- } , DEBOUNCE_TIMEOUT ) ;
55-
56- const debouncedHandleHidePopup = debounce ( ( ) => {
57- setIsPopupVisible ( false ) ;
58- onHidePopup ?.( ) ;
59- } , DEBOUNCE_TIMEOUT ) ;
60-
6148 const renderVDisks = ( ) => {
6249 if ( ! vDisks ?. length ) {
6350 return null ;
@@ -90,10 +77,6 @@ export const PDisk = ({
9077
9178 let pDiskPath : string | undefined ;
9279
93- if ( pDiskIdsDefined ) {
94- pDiskPath = createHref ( routes . node , { id : NodeId , activeTab : STRUCTURE } , { pdiskId : PDiskId } ) ;
95- }
96-
9780 if ( pDiskIdsDefined ) {
9881 pDiskPath = getPDiskPagePath ( PDiskId , NodeId ) ;
9982 }
@@ -105,11 +88,8 @@ export const PDisk = ({
10588 < InternalLink
10689 to = { pDiskPath }
10790 className = { b ( 'content' ) }
108- onMouseEnter = { debouncedHandleShowPopup }
109- onMouseLeave = { ( ) => {
110- debouncedHandleShowPopup . cancel ( ) ;
111- debouncedHandleHidePopup ( ) ;
112- } }
91+ onMouseEnter = { onMouseEnter }
92+ onMouseLeave = { onMouseLeave }
11393 >
11494 < DiskStateProgressBar
11595 diskAllocatedPercent = { data . AllocatedPercent }
@@ -119,7 +99,12 @@ export const PDisk = ({
11999 < div className = { b ( 'media-type' ) } > { data . Type } </ div >
120100 </ InternalLink >
121101 </ div >
122- < PDiskPopup data = { data } anchorRef = { anchor } open = { isPopupVisible || showPopup } />
102+ < PDiskPopup
103+ data = { data }
104+ anchorRef = { anchor }
105+ open = { isPopupVisible || showPopup }
106+ hidePopup = { hidePopup }
107+ />
123108 </ React . Fragment >
124109 ) ;
125110} ;
0 commit comments