Skip to content

Commit ec05506

Browse files
authored
chore(netdata table): minor updates (#407)
* chore(netdata table): add support for cell and header cell styles * chore(netdata table): fix sort icons * v2.5.5
1 parent 3c655bd commit ec05506

File tree

3 files changed

+59
-37
lines changed

3 files changed

+59
-37
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.5.4",
3+
"version": "2.5.5",
44
"description": "netdata UI kit",
55
"main": "./lib/index.js",
66
"files": [

src/components/tableV2/core/base-table.js

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ const StyledHeaderCell = styled(Box)`
3434
}
3535
`
3636
const StyledSortIcon = styled(Icon)`
37-
position: absolute;
38-
top: 0;
39-
bottom: 0;
4037
height: 16px;
38+
margin: auto 4px;
4139
width: 16px;
42-
margin: auto;
4340
`
4441
const StyledPagination = styled(Flex)`
4542
height: 45px;
@@ -80,7 +77,10 @@ Table.HeadRow = forwardRef(({ children, ...props }, ref) => (
8077
))
8178

8279
Table.HeadCell = forwardRef(
83-
({ children, align = "left", width, maxWidth, minWidth, styles = {}, ...props }, ref) => (
80+
(
81+
{ align = "left", children, headStyles = {}, maxWidth, minWidth, width, styles = {}, ...rest },
82+
ref
83+
) => (
8484
<StyledHeaderCell
8585
width={{ max: maxWidth, base: width, min: minWidth }}
8686
ref={ref}
@@ -91,9 +91,10 @@ Table.HeadCell = forwardRef(
9191
position: "sticky",
9292
top: 0,
9393
...styles,
94+
...headStyles,
9495
}}
95-
{...props}
9696
as="th"
97+
{...rest}
9798
>
9899
{children}
99100
</StyledHeaderCell>
@@ -103,19 +104,20 @@ Table.HeadCell = forwardRef(
103104
Table.SortingHeadCell = forwardRef(
104105
(
105106
{
107+
align = "left",
106108
children,
107-
onSortClicked,
108-
setSortDirection,
109+
"data-testid": dataTestid,
110+
filter,
111+
headStyles = {},
109112
maxWidth,
110-
width,
111113
minWidth,
112-
sortDirection,
113-
filter,
114-
align = "left",
115-
"data-testid": dataTestid,
114+
onSortClicked,
115+
setSortDirection,
116116
"sortby-testid": sortbyTestid,
117+
sortDirection,
117118
styles = {},
118-
...props
119+
width,
120+
...rest
119121
},
120122
ref
121123
) => {
@@ -142,29 +144,34 @@ Table.SortingHeadCell = forwardRef(
142144
width={{ max: maxWidth, base: width, min: minWidth }}
143145
as="th"
144146
ref={ref}
145-
{...props}
147+
{...rest}
146148
sx={{
147149
textAlign: align,
148150
fontSize: "14px",
149151
height: "90px",
150152
position: "sticky",
151153
top: 0,
152154
...styles,
155+
...headStyles,
153156
}}
154157
data-testid={dataTestid}
155158
>
156-
<Box
159+
<Flex
160+
cursor="pointer"
161+
data-testid={sortbyTestid}
162+
onClick={onClick}
157163
onMouseEnter={onMouseEnter}
158164
onMouseLeave={onMouseLeave}
159-
onClick={onClick}
160165
position="relative"
161-
cursor="pointer"
162-
data-testid={sortbyTestid}
163166
>
164167
{children}
165168
<StyledSortIcon color="text" name={sortingIcons[sortDirection] ?? null} />
166-
{showHoveringIcon && <StyledSortIcon color="textLite" name={sortingIcons["indicator"]} />}
167-
</Box>
169+
{showHoveringIcon ? (
170+
<StyledSortIcon color="textLite" name={sortingIcons["indicator"]} />
171+
) : (
172+
<Box width={6} height={4} />
173+
)}
174+
</Flex>
168175
{filter}
169176
</StyledHeaderCell>
170177
)
@@ -178,21 +185,34 @@ Table.Body = forwardRef(({ children, ...props }, ref) => (
178185
))
179186

180187
Table.Cell = forwardRef(
181-
({ children, onClick, width, maxWidth, minWidth, align = "left", ...props }, ref) => {
188+
(
189+
{
190+
align = "left",
191+
cellStyles = {},
192+
children,
193+
maxWidth,
194+
minWidth,
195+
onClick,
196+
styles = {},
197+
width,
198+
...rest
199+
},
200+
ref
201+
) => {
182202
const handleClick = e => {
183203
e.persist()
184-
if (props.stopPropagation) e.stopPropagation()
204+
if (rest.stopPropagation) e.stopPropagation()
185205
onClick?.()
186206
}
187207
return (
188208
<Box
189209
width={{ max: maxWidth, base: width, min: minWidth }}
190210
padding={[3]}
191-
sx={{ textAlign: align, height: "80px" }}
211+
sx={{ textAlign: align, height: "80px", ...styles, ...cellStyles }}
192212
as="td"
193213
ref={ref}
194-
{...props}
195214
onClick={handleClick}
215+
{...rest}
196216
>
197217
{children}
198218
</Box>
@@ -217,7 +237,7 @@ Table.Row = forwardRef(
217237
onMouseEnter?.(event)
218238
}
219239

220-
const handleMousLeave = event => {
240+
const handleMouseLeave = event => {
221241
onMouseLeave?.(event)
222242
}
223243

@@ -227,7 +247,7 @@ Table.Row = forwardRef(
227247
return (
228248
<Box
229249
onMouseEnter={handleMouseEnter}
230-
onMouseLeave={handleMousLeave}
250+
onMouseLeave={handleMouseLeave}
231251
as={StyledRow}
232252
_hover={isRowClickable && { background: "borderSecondary" }}
233253
cursor={cursor}

src/components/tableV2/core/headCell.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react"
1+
import React from "react"
22

33
import ComparisonFilter from "../components/comparisonFilter"
44
import SelectFilter from "../components/selectFilter"
@@ -42,6 +42,7 @@ const makeHeadCell = ({ headers, enableSorting, testPrefix }) => {
4242
const HeadCell = headers.map(({ id, colSpan, getContext, isPlaceholder, column }) => {
4343
const { getCanSort, columnDef } = column
4444
const { meta } = columnDef
45+
const headStyles = meta?.headStyles || {}
4546
const styles = meta?.styles || {}
4647

4748
const selectedFilter = meta && meta?.filter?.component ? meta?.filter?.component : "default"
@@ -52,21 +53,22 @@ const makeHeadCell = ({ headers, enableSorting, testPrefix }) => {
5253
if (getCanSort() && enableSorting) {
5354
return (
5455
<Table.SortingHeadCell
55-
width={column.getSize()}
56-
minWidth={column.columnDef.minSize}
57-
maxWidth={column.columnDef.maxSize}
58-
data-testid={`netdata-table-head-cell${testPrefix}`}
59-
sortby-testid={`netdata-table-head-cell-sortyBy-${id}${testPrefix}`}
60-
sortDirection={column.getIsSorted()}
61-
onSortClicked={column.getToggleSortingHandler()}
6256
colSpan={colSpan}
63-
key={id}
57+
data-testid={`netdata-table-head-cell${testPrefix}`}
6458
filter={
6559
column.getCanFilter() && (
6660
<Filter column={column} testPrefix={testPrefix} {...filterOptions} />
6761
)
6862
}
63+
headStyles={headStyles}
64+
key={id}
65+
maxWidth={column.columnDef.maxSize}
66+
minWidth={column.columnDef.minSize}
67+
onSortClicked={column.getToggleSortingHandler()}
68+
sortby-testid={`netdata-table-head-cell-sortyBy-${id}${testPrefix}`}
69+
sortDirection={column.getIsSorted()}
6970
styles={styles}
71+
width={column.getSize()}
7072
>
7173
<Box position="absolute" right={0}>
7274
{tooltipText && (

0 commit comments

Comments
 (0)