Skip to content

Commit 7ddea7f

Browse files
committed
Fix hovering.
1 parent 78cdf40 commit 7ddea7f

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

src/components/tableV2/core/rows.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const Rows = ({
88
disableClickRow,
99
getRowHandler = "getCenterVisibleCells",
1010
onHoverRow,
11+
hoveredRow,
1112
onClickRow,
1213
pinnedStyles,
1314
table,
@@ -19,7 +20,6 @@ const Rows = ({
1920
loading,
2021
loadMore,
2122
}) => {
22-
const [hoveredRow, setHoveredRow] = useState(null)
2323
const { rows } = table.getRowModel()
2424

2525
const virtualizer = useVirtualizer({
@@ -47,16 +47,6 @@ const Rows = ({
4747
const paddingBottom =
4848
virtualRows.length > 0 ? totalHeight - (virtualRows?.[virtualRows.length - 1]?.end || 0) : 0
4949

50-
const handleOnMouseEnter = id => {
51-
onHoverRow?.(id)
52-
setHoveredRow(id)
53-
}
54-
55-
const handleOnMouseLeave = () => {
56-
onHoverRow?.(null)
57-
setHoveredRow(null)
58-
}
59-
6050
return (
6151
<>
6252
{paddingTop > 0 && (
@@ -78,8 +68,8 @@ const Rows = ({
7868
disableClickRow={() =>
7969
disableClickRow?.({ data: row.original, table: table, fullRow: row })
8070
}
81-
onMouseEnter={() => handleOnMouseEnter(row.id)}
82-
onMouseLeave={handleOnMouseLeave}
71+
onMouseEnter={() => onHoverRow(row.id)}
72+
onMouseLeave={() => onHoverRow(null)}
8373
isHovering={row.id === hoveredRow}
8474
background={virtualRow.index % 2 == 0 ? "mainBackground" : "tableRowBg"}
8575
>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useCallback, useState } from "react"
2+
3+
export default onHoverRow => {
4+
const [hoveredRow, setHoveredRow] = useState(null)
5+
6+
const onHover = useCallback(
7+
id => {
8+
setHoveredRow(id)
9+
onHoverRow?.(id)
10+
},
11+
[onHoverRow]
12+
)
13+
14+
return [hoveredRow, onHover]
15+
}

src/components/tableV2/netdataTable.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//TODO refactor bulk action and row action to single function to decrease repeatability
2-
import React, { useEffect, useMemo, useState, useCallback, useRef } from "react"
2+
import React, { useEffect, useState, useCallback, useRef } from "react"
33
import {
44
getCoreRowModel,
55
getFilteredRowModel,
@@ -14,6 +14,7 @@ import makePagination from "./features/pagination"
1414
import useBulkActions from "./features/useBulkActions"
1515
import ColumnPinning from "./features/columnPinning"
1616
import GlobalControls from "./features/globalControls"
17+
import useRowHover from "./features/useRowHover"
1718

1819
import MainTable from "./features/mainTable"
1920

@@ -58,6 +59,8 @@ const NetdataTable = ({
5859
virtualizeOptions = {},
5960
...rest
6061
}) => {
62+
const [hoveredRow, setHoveredRow] = useRowHover(onHoverRow)
63+
6164
const [columnVisibility, setColumnVisibility] = useState(defaultColumnVisibility)
6265

6366
useEffect(() => {
@@ -192,7 +195,8 @@ const NetdataTable = ({
192195
headers={table.getLeftFlatHeaders()}
193196
testPrefix={testPrefix}
194197
dataGa={dataGa}
195-
onHoverRow={onHoverRow}
198+
onHoverRow={setHoveredRow}
199+
hoveredRow={hoveredRow}
196200
scrollParentRef={scrollParentRef}
197201
virtualizeOptions={virtualizeOptions}
198202
/>
@@ -209,7 +213,8 @@ const NetdataTable = ({
209213
dataGa={dataGa}
210214
tableRef={tableRef}
211215
testPrefix={testPrefix}
212-
onHoverRow={onHoverRow}
216+
onHoverRow={setHoveredRow}
217+
hoveredRow={hoveredRow}
213218
virtualizeOptions={virtualizeOptions}
214219
{...rest}
215220
/>

0 commit comments

Comments
 (0)