@@ -46,85 +46,95 @@ const HeadCell = ({
4646 testPrefix,
4747 ...rest
4848} ) =>
49- headers . map ( ( { id, colSpan, getContext, isPlaceholder, column, getResizeHandler, getSize } ) => {
50- const { getCanSort, columnDef, getCanResize, getIsResizing } = column
51- const { meta, tableMeta } = columnDef
52- const headStyles = {
53- verticalAlign : "baseline" ,
54- ...( tableMeta ?. headStyles || { } ) ,
55- ...( meta ?. headStyles || { } ) ,
56- ...pinnedStyles ,
57- }
58- const styles = meta ?. styles || { }
59-
60- const selectedFilter = meta && meta ?. filter ?. component ? meta ?. filter ?. component : "default"
61- const filterOptions = meta && meta ?. filter ? meta ?. filter : { }
62- const tooltipText = meta && meta ?. tooltip ? meta ?. tooltip : ""
63- const Filter = availableFilters [ selectedFilter ]
64-
65- const resizeFuntions =
66- enableResize && getCanResize ( )
67- ? {
68- onMouseDown : getResizeHandler ( ) ,
69- onTouchStart : getResizeHandler ( ) ,
70- getIsResizing,
71- deltaOffset : table . getState ( ) . columnSizingInfo . deltaOffset ,
72- }
73- : { }
49+ headers . map (
50+ ( { id, colSpan, getContext, isPlaceholder, column, getResizeHandler, getSize } , index ) => {
51+ const { getCanSort, columnDef, getCanResize, getIsResizing } = column
52+
53+ const tableMeta =
54+ typeof columnDef . tableMeta === "function"
55+ ? columnDef . tableMeta ( { } , column , index )
56+ : columnDef . tableMeta
57+
58+ const meta =
59+ typeof columnDef . meta === "function" ? columnDef . meta ( { } , column , index ) : columnDef . meta
60+
61+ const headStyles = {
62+ verticalAlign : "baseline" ,
63+ ...( tableMeta ?. headStyles || { } ) ,
64+ ...( meta ?. headStyles || { } ) ,
65+ ...pinnedStyles ,
66+ }
67+ const styles = meta ?. styles || { }
68+
69+ const selectedFilter = meta && meta ?. filter ?. component ? meta ?. filter ?. component : "default"
70+ const filterOptions = meta && meta ?. filter ? meta ?. filter : { }
71+ const tooltipText = meta && meta ?. tooltip ? meta ?. tooltip : ""
72+ const Filter = availableFilters [ selectedFilter ]
73+
74+ const resizeFuntions =
75+ enableResize && getCanResize ( )
76+ ? {
77+ onMouseDown : getResizeHandler ( ) ,
78+ onTouchStart : getResizeHandler ( ) ,
79+ getIsResizing,
80+ deltaOffset : table . getState ( ) . columnSizingInfo . deltaOffset ,
81+ }
82+ : { }
83+
84+ const headWidth = getSize ( )
7485
75- const headWidth = getSize ( )
86+ if ( getCanSort ( ) && enableSorting ) {
87+ return (
88+ < Table . SortingHeadCell
89+ colSpan = { colSpan }
90+ data-testid = { `netdata-table-head-cell${ testPrefix } ` }
91+ filter = {
92+ column . getCanFilter ( ) && (
93+ < Filter column = { column } testPrefix = { testPrefix } { ...filterOptions } />
94+ )
95+ }
96+ headStyles = { headStyles }
97+ key = { id }
98+ id = { id }
99+ maxWidth = { column . columnDef . maxSize }
100+ minWidth = { column . columnDef . minSize }
101+ onSortClicked = { column . getToggleSortingHandler ( ) }
102+ sortby-testid = { `netdata-table-head-cell-sortyBy-${ id } ${ testPrefix } ` }
103+ sortDirection = { column . getIsSorted ( ) }
104+ styles = { styles }
105+ tooltipText = { tooltipText }
106+ width = { headWidth }
107+ { ...resizeFuntions }
108+ { ...rest }
109+ >
110+ { isPlaceholder ? null : flexRender ( column . columnDef . header , getContext ( ) ) } { " " }
111+ </ Table . SortingHeadCell >
112+ )
113+ }
76114
77- if ( getCanSort ( ) && enableSorting ) {
78115 return (
79- < Table . SortingHeadCell
80- colSpan = { colSpan }
116+ < Table . HeadCell
81117 data-testid = { `netdata-table-head-cell${ testPrefix } ` }
82118 filter = {
83119 column . getCanFilter ( ) && (
84120 < Filter column = { column } testPrefix = { testPrefix } { ...filterOptions } />
85121 )
86122 }
87123 headStyles = { headStyles }
88- key = { id }
89- id = { id }
90124 maxWidth = { column . columnDef . maxSize }
91125 minWidth = { column . columnDef . minSize }
92- onSortClicked = { column . getToggleSortingHandler ( ) }
93- sortby-testid = { `netdata-table-head-cell-sortyBy-${ id } ${ testPrefix } ` }
94- sortDirection = { column . getIsSorted ( ) }
126+ key = { id }
127+ id = { id }
95128 styles = { styles }
96129 tooltipText = { tooltipText }
97130 width = { headWidth }
98131 { ...resizeFuntions }
99132 { ...rest }
100133 >
101- { isPlaceholder ? null : flexRender ( column . columnDef . header , getContext ( ) ) } { " " }
102- </ Table . SortingHeadCell >
134+ { isPlaceholder ? null : flexRender ( column . columnDef . header , getContext ( ) ) }
135+ </ Table . HeadCell >
103136 )
104137 }
105-
106- return (
107- < Table . HeadCell
108- data-testid = { `netdata-table-head-cell${ testPrefix } ` }
109- filter = {
110- column . getCanFilter ( ) && (
111- < Filter column = { column } testPrefix = { testPrefix } { ...filterOptions } />
112- )
113- }
114- headStyles = { headStyles }
115- maxWidth = { column . columnDef . maxSize }
116- minWidth = { column . columnDef . minSize }
117- key = { id }
118- id = { id }
119- styles = { styles }
120- tooltipText = { tooltipText }
121- width = { headWidth }
122- { ...resizeFuntions }
123- { ...rest }
124- >
125- { isPlaceholder ? null : flexRender ( column . columnDef . header , getContext ( ) ) }
126- </ Table . HeadCell >
127- )
128- } )
138+ )
129139
130140export default HeadCell
0 commit comments