-
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 1 commit
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,25 +1,35 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {showTooltip} from '../../../store/reducers/tooltip'; | ||
| import {useTypedDispatch} from '../../../utils/hooks'; | ||
| import {Popup} from '@gravity-ui/uikit'; | ||
|
|
||
| import {b} from '../QueryResultTable'; | ||
|
|
||
| interface CellProps { | ||
| className?: string; | ||
| value: string; | ||
| isActive: boolean; | ||
| onToggle: () => void; | ||
| } | ||
|
|
||
| export const Cell = React.memo(function Cell(props: CellProps) { | ||
| const {className, value} = props; | ||
| const {className, value, isActive, onToggle} = props; | ||
|
|
||
| const dispatch = useTypedDispatch(); | ||
| const anchorRef = React.useRef<HTMLSpanElement | null>(null); | ||
|
|
||
| return ( | ||
| <span | ||
| className={b('cell', className)} | ||
| onClick={(e) => dispatch(showTooltip(e.target, value, 'cell'))} | ||
| > | ||
| {value} | ||
| </span> | ||
| <React.Fragment> | ||
| <Popup | ||
| open={isActive} | ||
| hasArrow | ||
| placement={['top', 'bottom']} | ||
| anchorRef={anchorRef} | ||
| onOutsideClick={onToggle} | ||
| > | ||
| <div className={b('cell-popup')}>{value}</div> | ||
| </Popup> | ||
| <span ref={anchorRef} className={b('cell', className)} onClick={onToggle}> | ||
| {value} | ||
| </span> | ||
| </React.Fragment> | ||
| ); | ||
| }); |
| 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, useVirtualElementRef} 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,16 @@ 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 [isTabletTooltipHovered, setIsTabletTooltipHovered] = React.useState(false); | ||
|
|
||
| const tabletTooltipAnchorRef = useVirtualElementRef({ | ||
| rect: tabletTooltip?.position, | ||
| }); | ||
|
|
||
| const [autoRefreshInterval] = useAutoRefreshInterval(); | ||
|
|
||
| const {currentData, isFetching, error} = heatmapApi.useGetHeatmapTabletsInfoQuery( | ||
|
|
@@ -44,13 +54,26 @@ 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 || isTabletTooltipHovered) { | ||
| return prev; | ||
| } | ||
|
|
||
| return null; | ||
| }); | ||
| }, [isTabletTooltipHovered]); | ||
astandrik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
astandrik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const handleMetricChange = (value: string[]) => { | ||
| dispatch( | ||
|
|
@@ -76,14 +99,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 = () => { | ||
|
|
@@ -111,8 +127,8 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => { | |
| <HeatmapCanvas | ||
| tablets={sortedTablets} | ||
| parentRef={itemsContainer} | ||
| showTooltip={onShowTooltip} | ||
| hideTooltip={onHideTooltip} | ||
| onShowTabletTooltip={handleShowTabletTooltip} | ||
| onHideTabletTooltip={handleRequestHideTabletTooltip} | ||
| /> | ||
| </div> | ||
| ); | ||
|
|
@@ -128,6 +144,25 @@ export const Heatmap = ({path, database, databaseFullPath}: HeatmapProps) => { | |
|
|
||
| return ( | ||
| <div className={b()}> | ||
| {tabletTooltip ? ( | ||
| <Popup | ||
| open | ||
| hasArrow | ||
| placement={['top', 'bottom', 'left', 'right']} | ||
| anchorRef={tabletTooltipAnchorRef} | ||
| onOutsideClick={handleHideTabletTooltip} | ||
| > | ||
| <div | ||
| onMouseEnter={() => setIsTabletTooltipHovered(true)} | ||
| onMouseLeave={() => { | ||
| setIsTabletTooltipHovered(false); | ||
| handleHideTabletTooltip(); | ||
| }} | ||
| > | ||
astandrik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <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')} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.