Skip to content

Commit 4536b28

Browse files
committed
v5.0.13
1 parent 8803cfa commit 4536b28

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/netdata-ui",
3-
"version": "5.0.12",
3+
"version": "5.0.13",
44
"description": "netdata UI kit",
55
"main": "dist/index.js",
66
"module": "dist/es6/index.js",

src/components/select/index.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, { useMemo } from "react"
1+
import React, { useRef, useMemo } from "react"
22
import styled from "styled-components"
33
import ReactSelect, { components as defaultComponents } from "react-select"
44
import Creatable from "react-select/creatable"
55
import { Icon } from "@/components/icon"
6+
import { useVirtualizer } from "@tanstack/react-virtual"
67

78
const useDataAttrs = (props, name) => {
89
const { "data-ga": dataGA, "data-testid": dataTestId } = props.selectProps
@@ -83,6 +84,57 @@ const customComponents = {
8384
ValueContainer: withDataAttrs(defaultComponents.ValueContainer, "ValueContainer"),
8485
}
8586

87+
const VirtualizedMenuList = props => {
88+
const parentRef = useRef()
89+
90+
const virtualizer = useVirtualizer({
91+
count: props.options.length,
92+
getScrollElement: () => parentRef.current,
93+
estimateSize: () => 20,
94+
overscan: 5,
95+
})
96+
97+
const virtualItems = virtualizer.getVirtualItems()
98+
99+
return (
100+
<customComponents.MenuList
101+
{...props}
102+
innerRef={parentRef}
103+
styles={{
104+
height: "300px",
105+
overflow: "auto",
106+
position: "relative",
107+
}}
108+
>
109+
<div
110+
style={{
111+
height: `${virtualizer.getTotalSize()}px`,
112+
position: "relative",
113+
}}
114+
>
115+
{virtualItems.map(virtualRow => {
116+
return (
117+
<div
118+
key={virtualRow.key}
119+
style={{
120+
transform: `translateY(${virtualRow.start}px)`,
121+
top: 0,
122+
left: 0,
123+
right: 0,
124+
position: "absolute",
125+
}}
126+
data-index={virtualRow.index}
127+
ref={virtualizer.measureElement}
128+
>
129+
{props.children[virtualRow.index]}
130+
</div>
131+
)
132+
})}
133+
</div>
134+
</customComponents.MenuList>
135+
)
136+
}
137+
86138
const makeCustomTheme = theme => selectTheme => {
87139
return {
88140
...selectTheme,
@@ -215,7 +267,7 @@ const makeCustomStyles = (theme, { minWidth, size, ...providedStyles } = {}) =>
215267

216268
const getAttrs = props => ({
217269
...props,
218-
components: { ...customComponents, ...props.components },
270+
components: { ...customComponents, MenuList: VirtualizedMenuList, ...props.components },
219271
theme: makeCustomTheme(props.theme),
220272
styles: makeCustomStyles(props.theme, props.styles),
221273
})

src/components/table/useVisibility.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import { useCallback, useEffect, useState, useRef } from "react"
1+
import { useCallback, useEffect, useState } from "react"
22

33
const noop = () => {}
44
const emptyObj = {}
55

66
export default (defaultColumnVisibility = emptyObj, onChange = noop) => {
77
const [columnVisibility, setColumnVisibility] = useState(() => defaultColumnVisibility)
8-
const initialSetRef = useRef(false)
98

109
useEffect(() => {
1110
if (columnVisibility === defaultColumnVisibility) return
1211

13-
initialSetRef.current = true
1412
setColumnVisibility(defaultColumnVisibility)
1513
}, [defaultColumnVisibility])
1614

0 commit comments

Comments
 (0)