Skip to content

Commit 3ac5c08

Browse files
authored
chore(netdata-table): add support for external search (#418)
* chore(netdata-table): add support for external search * Update search value to accept defaultValue passed by the user * Update external columnVisibility object when user updates visible columns * Move sort update functionality to separate function * Re-order props alphabetically * Fix typos * v2.6.9
1 parent de44eb9 commit 3ac5c08

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
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": "2.6.8",
3+
"version": "2.6.9",
44
"description": "netdata UI kit",
55
"main": "./lib/index.js",
66
"files": [

src/components/tableV2/features/globalControls.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@ const StyledTableControls = styled(Flex)`
1919
`
2020

2121
const GlobalControls = memo(
22-
({ handleSearch, dataGa, searchPlaceholder = "Search", bulkActions }) => {
22+
({ bulkActions, dataGa, handleSearch, searchPlaceholder = "Search", searchValue }) => {
2323
return (
2424
<StyledTableControls>
2525
{handleSearch && (
2626
<Box width={{ max: 50 }}>
2727
<SearchInput
2828
data-testid="table-global-search-filter"
2929
data-ga={`${dataGa}::search::table-filter`}
30+
defaultValue={searchValue}
31+
iconRight={<Icon name="magnify" color="textLite" />}
3032
onChange={debounce(300, e => {
3133
e.persist()
3234
handleSearch(e.target.value)
3335
})}
3436
placeholder={searchPlaceholder}
35-
iconRight={<Icon name="magnify" color="textLite" />}
3637
/>
3738
</Box>
3839
)}

src/components/tableV2/netdataTable.js

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//TODO refactor bulk action and row action to single funtion to decrease repeatabillity
1+
//TODO refactor bulk action and row action to single function to decrease repeatability
22
import React, { useEffect, useMemo, useState, useCallback, useRef } from "react"
33

44
import {
@@ -30,35 +30,37 @@ import useInfiniteScroll from "./hooks/useInfiniteScroll"
3030
const noop = () => {}
3131

3232
const NetdataTable = ({
33-
dataColumns,
33+
bulkActions = {},
34+
columnPinningOptions = {},
35+
columnVisibility: initialColumnVisibility,
3436
data,
35-
onRowSelected,
36-
onGlobalSearchChange,
37+
dataColumns,
38+
dataGa,
39+
disableClickRow,
40+
enableColumnPinning = false,
41+
enableColumnVisibility = false,
42+
enablePagination,
43+
enableResize = false,
3744
enableSelection,
38-
globalFilterFn = includesString,
39-
tableRef,
4045
enableSorting,
41-
rowActions = {},
42-
bulkActions = {},
46+
globalFilter: initialGlobalFilter = "",
47+
globalFilterFn = includesString,
48+
loadMoreOptions = {},
4349
onClickRow,
50+
onColumnVisibilityChange = noop,
51+
onGlobalSearchChange,
4452
onHoverRow,
53+
onRowSelected,
4554
onSortingChange = noop,
46-
disableClickRow,
47-
enablePagination,
4855
paginationOptions = {
4956
pageIndex: 0,
5057
pageSize: 100,
5158
},
52-
columnVisibility: initialColumnVisibility,
53-
testPrefix = "",
59+
rowActions = {},
5460
sortBy = [],
61+
tableRef,
62+
testPrefix = "",
5563
testPrefixCallback,
56-
dataGa,
57-
enableColumnVisibility = false,
58-
enableColumnPinning = false,
59-
columnPinningOptions = {},
60-
enableResize = false,
61-
loadMoreOptions = {},
6264
virtualizeOptions = {},
6365
}) => {
6466
const [isColumnDropdownVisible, setIsColumnDropdownVisible] = useState(false)
@@ -68,7 +70,7 @@ const NetdataTable = ({
6870
const [originalSelectedRows, setOriginalSelectedRow] = useState([])
6971
const [sorting, setSorting] = useState(sortBy)
7072
const [rowSelection, setRowSelection] = useState({})
71-
const [globalFilter, setGlobalFilter] = useState("")
73+
const [globalFilter, setGlobalFilter] = useState(initialGlobalFilter)
7274
const [pagination, setPagination] = useState({
7375
pageIndex: paginationOptions.pageIndex,
7476
pageSize: paginationOptions.pageSize,
@@ -83,11 +85,21 @@ const NetdataTable = ({
8385

8486
useInfiniteScroll({ target: scrollParentRef, updateTableData, ...loadMoreOptions })
8587

88+
const handleColumnVisibilityChange = useCallback(getVisibility => {
89+
onColumnVisibilityChange(getVisibility)
90+
setColumnVisibility(getVisibility)
91+
}, [])
92+
8693
const handleGlobalSearch = useCallback(value => {
8794
onGlobalSearchChange?.(value)
8895
setGlobalFilter(String(value))
8996
}, [])
9097

98+
const handleSortingChange = useCallback(getSorting => {
99+
onSortingChange(getSorting)
100+
setSorting(getSorting)
101+
}, [])
102+
91103
const makeActionsColumn = useMemo(() => makeRowActions({ rowActions, testPrefix }), [rowActions])
92104

93105
const renderBulkActions = () => [
@@ -133,7 +145,7 @@ const NetdataTable = ({
133145
},
134146
index
135147
) => {
136-
if (!id) throw new Error(`Please provide id at ${index}`)
148+
if (!id) throw new Error(`Please provide id at ${index}`)
137149

138150
return {
139151
id,
@@ -180,14 +192,11 @@ const NetdataTable = ({
180192
getFilteredRowModel: getFilteredRowModel(),
181193
onRowSelectionChange: setRowSelection,
182194
onGlobalFilterChange: handleGlobalSearch,
183-
onSortingChange: getSorting => {
184-
onSortingChange(getSorting)
185-
setSorting(getSorting)
186-
},
195+
onSortingChange: handleSortingChange,
187196
getSortedRowModel: getSortedRowModel(),
188197
getPaginationRowModel: getPaginationRowModel(),
189198
onPaginationChange: setPagination,
190-
onColumnVisibilityChange: setColumnVisibility,
199+
onColumnVisibilityChange: handleColumnVisibilityChange,
191200
onColumnPinningChange: setColumnPinning,
192201
})
193202

@@ -212,9 +221,10 @@ const NetdataTable = ({
212221
<SharedTableProvider>
213222
<Flex height="100%" overflow="hidden" width="100%" column>
214223
<GlobalControls
215-
handleSearch={onGlobalSearchChange ? handleGlobalSearch : null}
216-
dataGa={dataGa}
217224
bulkActions={renderBulkActions}
225+
dataGa={dataGa}
226+
handleSearch={onGlobalSearchChange ? handleGlobalSearch : null}
227+
searchValue={globalFilter}
218228
/>
219229
<Flex
220230
ref={scrollParentRef}

0 commit comments

Comments
 (0)