22 benchmarkJobsColumns ,
33 jobsColumns ,
44 nodesLeaderboardColumns ,
5+ NodesLeaderboardColumnsVisibility ,
56 nodesLeaderboardHomeColumns ,
67 nodesTopByJobCountColumns ,
78 nodesTopByRevenueColumns ,
@@ -11,7 +12,7 @@ import {
1112} from '@/components/table/columns' ;
1213import { TableContextType } from '@/components/table/context-type' ;
1314import CustomPagination from '@/components/table/custom-pagination' ;
14- import CustomToolbar from '@/components/table/custom-toolbar' ;
15+ import CustomToolbar , { CustomToolbarProps } from '@/components/table/custom-toolbar' ;
1516import { TableTypeEnum } from '@/components/table/table-type' ;
1617import styled from '@emotion/styled' ;
1718import {
@@ -25,8 +26,8 @@ import {
2526 GridValidRowModel ,
2627 useGridApiRef ,
2728} from '@mui/x-data-grid' ;
28- import { GridSlotsComponentsProps } from '@mui/x-data-grid/internals' ;
29- import { useCallback , useMemo , useRef , useState } from 'react' ;
29+ import { GridSlotsComponentsProps , GridToolbarProps } from '@mui/x-data-grid/internals' ;
30+ import { JSXElementConstructor , useCallback , useMemo , useRef , useState } from 'react' ;
3031
3132const StyledRoot = styled ( 'div' ) ( {
3233 display : 'flex' ,
@@ -44,16 +45,9 @@ const StyledDataGridWrapper = styled('div')<{ autoHeight?: boolean }>(({ autoHei
4445 } ,
4546} ) ) ;
4647
47- const StyledScrollWrapper = styled ( 'div' ) ( {
48- overflowX : 'auto' ,
49- WebkitOverflowScrolling : 'touch' ,
50- width : '100%' ,
51- } ) ;
52-
5348const StyledDataGrid = styled ( DataGrid ) < { clickable ?: boolean } > ( ( { clickable } ) => ( {
5449 background : 'none' ,
5550 border : 'none' ,
56- minWidth : 600 ,
5751 borderBottom : '1px solid var(--border)' ,
5852 borderRadius : 0 ,
5953 color : 'var(--text-primary)' ,
@@ -209,6 +203,17 @@ export const Table = <T extends GridValidRowModel>({
209203 }
210204 } , [ tableType ] ) ;
211205
206+ const columnVisibilityModel = useMemo ( ( ) => {
207+ switch ( tableType ) {
208+ case TableTypeEnum . NODES_LEADERBOARD : {
209+ return NodesLeaderboardColumnsVisibility ;
210+ }
211+ default : {
212+ return undefined ;
213+ }
214+ }
215+ } , [ tableType ] ) ;
216+
212217 const handlePaginationChange = useCallback (
213218 ( model : { page : number ; pageSize : number } ) => {
214219 if ( paginationType === 'context' && context ) {
@@ -292,7 +297,7 @@ export const Table = <T extends GridValidRowModel>({
292297 } , [ ] ) ;
293298
294299 const initialState = useMemo ( ( ) => {
295- const coreState : GridInitialState = { density : 'standard' } ;
300+ const coreState : GridInitialState = { density : 'standard' , columns : { columnVisibilityModel } } ;
296301 return paginationType === 'none'
297302 ? coreState
298303 : {
@@ -304,7 +309,7 @@ export const Table = <T extends GridValidRowModel>({
304309 } ,
305310 } ,
306311 } ;
307- } , [ currentPage , pageSize , paginationType ] ) ;
312+ } , [ columnVisibilityModel , currentPage , pageSize , paginationType ] ) ;
308313
309314 const paginationModel =
310315 paginationType === 'none'
@@ -314,7 +319,7 @@ export const Table = <T extends GridValidRowModel>({
314319 pageSize : pageSize ,
315320 } ;
316321
317- const slotProps : GridSlotsComponentsProps = {
322+ const slotProps : GridSlotsComponentsProps & { toolbar : Partial < CustomToolbarProps > } = {
318323 basePopper : {
319324 style : {
320325 color : '#000000' ,
@@ -324,53 +329,52 @@ export const Table = <T extends GridValidRowModel>({
324329 variant : 'skeleton' ,
325330 noRowsVariant : 'skeleton' ,
326331 } ,
332+ toolbar : {
333+ searchTerm,
334+ onSearchChange : handleSearchChange ,
335+ onReset : handleResetFilters ,
336+ tableType : tableType ,
337+ apiRef : apiRef . current ?? undefined ,
338+ // totalUptime: totalUptime,
339+ } ,
327340 } ;
328341
329342 const defaultGetRowId : GridRowIdGetter < GridValidRowModel > = ( row ) => row . id ;
330343
331344 return (
332345 < StyledRoot >
333- { showToolbar && (
334- < CustomToolbar
335- searchTerm = { searchTerm }
336- onSearchChange = { handleSearchChange }
337- onSearch = { ( ) => { } }
338- onReset = { handleResetFilters }
339- tableType = { tableType }
340- apiRef = { apiRef . current ?? undefined }
341- totalUptime = { null }
346+ < StyledDataGridWrapper autoHeight = { autoHeight } >
347+ < StyledDataGrid
348+ apiRef = { apiRef }
349+ clickable = { ! ! onRowClick }
350+ columns = { ( columns as GridColDef < GridValidRowModel > [ ] ) . map ( ( col ) => ( {
351+ minWidth : col . width ?? 120 ,
352+ ...col ,
353+ } ) ) }
354+ disableColumnMenu
355+ disableRowSelectionOnClick
356+ filterMode = { paginationType === 'none' ? 'client' : 'server' }
357+ getRowId = { getRowId ?? defaultGetRowId }
358+ hideFooter
359+ initialState = { initialState }
360+ loading = { loading ?? context ?. loading }
361+ onFilterModelChange = { handleFilterModelChange }
362+ onPaginationModelChange = { handlePaginationChange }
363+ onRowClick = { onRowClick }
364+ onSortModelChange = { handleSortModelChange }
365+ pageSizeOptions = { [ 10 , 25 , 50 , 100 ] }
366+ // pagination
367+ paginationMode = { paginationType === 'none' ? undefined : 'server' }
368+ paginationModel = { paginationModel }
369+ processRowUpdate = { processRowUpdate }
370+ rowCount = { totalItems }
371+ rows = { data }
372+ showToolbar = { showToolbar }
373+ slots = { { toolbar : CustomToolbar as JSXElementConstructor < GridToolbarProps > } }
374+ slotProps = { slotProps }
375+ sortingMode = { paginationType === 'none' ? 'client' : 'server' }
342376 />
343- ) }
344- < StyledScrollWrapper >
345- < StyledDataGridWrapper autoHeight = { autoHeight } >
346- < StyledDataGrid
347- apiRef = { apiRef }
348- clickable = { ! ! onRowClick }
349- columns = { columns as GridColDef < GridValidRowModel > [ ] }
350- disableColumnMenu
351- disableRowSelectionOnClick
352- filterMode = { paginationType === 'none' ? 'client' : 'server' }
353- getRowId = { getRowId ?? defaultGetRowId }
354- hideFooter
355- initialState = { initialState }
356- loading = { loading ?? context ?. loading }
357- onFilterModelChange = { handleFilterModelChange }
358- onPaginationModelChange = { handlePaginationChange }
359- onRowClick = { onRowClick }
360- onSortModelChange = { handleSortModelChange }
361- pageSizeOptions = { [ 10 , 25 , 50 , 100 ] }
362- // pagination
363- paginationMode = { paginationType === 'none' ? undefined : 'server' }
364- paginationModel = { paginationModel }
365- processRowUpdate = { processRowUpdate }
366- rowCount = { totalItems }
367- rows = { data }
368- slots = { { } }
369- slotProps = { slotProps }
370- sortingMode = { paginationType === 'none' ? 'client' : 'server' }
371- />
372- </ StyledDataGridWrapper >
373- </ StyledScrollWrapper >
377+ </ StyledDataGridWrapper >
374378 { paginationType === 'none' ? null : (
375379 < CustomPagination
376380 page = { currentPage }
0 commit comments