-
Notifications
You must be signed in to change notification settings - Fork 18
feat: get rid of ReduxTooltip #3192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
22e4923
407ebda
065baf6
fb0e2e6
bf136da
87ac421
54770e0
14446a3
95d8093
937864f
c6ba1f7
f2df4f2
3242259
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {Checkbox, Select} from '@gravity-ui/uikit'; | ||
| import {Checkbox, Popup, Select} from '@gravity-ui/uikit'; | ||
|
|
||
| import {ResponseError} from '../../components/Errors/ResponseError'; | ||
| import {Loader} from '../../components/Loader'; | ||
| import {TabletTooltipContent} from '../../components/TooltipsContent'; | ||
| import {heatmapApi, setHeatmapOptions} from '../../store/reducers/heatmap'; | ||
| import {hideTooltip, showTooltip} from '../../store/reducers/tooltip'; | ||
| import type {IHeatmapMetricValue} from '../../types/store/heatmap'; | ||
| import type {IHeatmapMetricValue, IHeatmapTabletData} from '../../types/store/heatmap'; | ||
| import {cn} from '../../utils/cn'; | ||
| import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants'; | ||
| import {formatNumber} from '../../utils/dataFormatters/dataFormatters'; | ||
|
|
@@ -32,6 +32,14 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => { | |
|
|
||
| const itemsContainer = React.createRef<HTMLDivElement>(); | ||
astandrik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const [tabletTooltip, setTabletTooltip] = React.useState<{ | ||
| tablet: IHeatmapTabletData; | ||
| position: {left: number; top: number}; | ||
| } | null>(null); | ||
| const [tabletTooltipAnchorElement, setTabletTooltipAnchorElement] = | ||
| React.useState<HTMLDivElement | null>(null); | ||
| const isTabletTooltipHoveredRef = React.useRef(false); | ||
|
|
||
| const [autoRefreshInterval] = useAutoRefreshInterval(); | ||
|
|
||
| const {currentData, isFetching, error} = heatmapApi.useGetHeatmapTabletsInfoQuery( | ||
|
|
@@ -44,13 +52,35 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => { | |
| const {tablets = [], metrics} = currentData || {}; | ||
| const {sort, heatmap, currentMetric} = useTypedSelector((state) => state.heatmap); | ||
|
|
||
| const onShowTooltip = (...args: Parameters<typeof showTooltip>) => { | ||
| dispatch(showTooltip(...args)); | ||
| }; | ||
| const handleShowTabletTooltip = React.useCallback( | ||
| (tablet: IHeatmapTabletData, position: {left: number; top: number}) => { | ||
| setTabletTooltip({tablet, position}); | ||
| }, | ||
| [], | ||
| ); | ||
|
|
||
| const onHideTooltip = () => { | ||
| dispatch(hideTooltip()); | ||
| }; | ||
| const handleHideTabletTooltip = React.useCallback(() => { | ||
| setTabletTooltip(null); | ||
| }, []); | ||
|
|
||
| const handleRequestHideTabletTooltip = React.useCallback(() => { | ||
| setTabletTooltip((prev) => { | ||
| if (!prev || isTabletTooltipHoveredRef.current) { | ||
| return prev; | ||
| } | ||
|
|
||
| return null; | ||
| }); | ||
| }, []); | ||
|
|
||
| const handleTooltipMouseEnter = React.useCallback(() => { | ||
| isTabletTooltipHoveredRef.current = true; | ||
| }, []); | ||
|
|
||
| const handleTooltipMouseLeave = React.useCallback(() => { | ||
| isTabletTooltipHoveredRef.current = false; | ||
| handleHideTabletTooltip(); | ||
| }, [handleHideTabletTooltip]); | ||
|
|
||
| const handleMetricChange = (value: string[]) => { | ||
| dispatch( | ||
|
|
@@ -76,14 +106,7 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => { | |
| }; | ||
|
|
||
| const renderHistogram = () => { | ||
| return ( | ||
| <Histogram | ||
| tablets={tablets} | ||
| currentMetric={currentMetric} | ||
| showTooltip={onShowTooltip} | ||
| hideTooltip={onHideTooltip} | ||
| /> | ||
| ); | ||
| return <Histogram tablets={tablets} currentMetric={currentMetric} />; | ||
| }; | ||
|
|
||
| const renderHeatmapCanvas = () => { | ||
|
|
@@ -108,11 +131,22 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => { | |
|
|
||
| return ( | ||
| <div ref={itemsContainer} className={b('items')}> | ||
| {tabletTooltip ? ( | ||
| <div | ||
| key={`${tabletTooltip.position.left}-${tabletTooltip.position.top}`} | ||
| ref={setTabletTooltipAnchorElement} | ||
| className={b('tooltip-anchor')} | ||
| style={{ | ||
| left: tabletTooltip.position.left, | ||
| top: tabletTooltip.position.top, | ||
| }} | ||
| /> | ||
| ) : null} | ||
| <HeatmapCanvas | ||
| tablets={sortedTablets} | ||
| parentRef={itemsContainer} | ||
| showTooltip={onShowTooltip} | ||
| hideTooltip={onHideTooltip} | ||
| onShowTabletTooltip={handleShowTabletTooltip} | ||
| onHideTabletTooltip={handleRequestHideTabletTooltip} | ||
| /> | ||
| </div> | ||
| ); | ||
|
|
@@ -128,6 +162,23 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => { | |
|
|
||
| return ( | ||
| <div className={b()}> | ||
| {tabletTooltip ? ( | ||
| <Popup | ||
| open | ||
| hasArrow | ||
| placement={['top', 'bottom', 'left', 'right']} | ||
| anchorElement={tabletTooltipAnchorElement} | ||
| onOutsideClick={handleHideTabletTooltip} | ||
| > | ||
| <div | ||
| className={b('tooltip')} | ||
| onMouseEnter={handleTooltipMouseEnter} | ||
| onMouseLeave={handleTooltipMouseLeave} | ||
| > | ||
| <TabletTooltipContent data={tabletTooltip.tablet} /> | ||
| </div> | ||
| </Popup> | ||
| ) : null} | ||
astandrik marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Popup may render before anchor element is readyThe Additional Locations (1) |
||
| <div className={b('filters')}> | ||
| <Select | ||
| className={b('heatmap-select')} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add paddings
