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
22import React , { useEffect , useMemo , useState , useCallback , useRef } from "react"
33
44import {
@@ -30,35 +30,37 @@ import useInfiniteScroll from "./hooks/useInfiniteScroll"
3030const noop = ( ) => { }
3131
3232const 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