Skip to content

Commit c76d34c

Browse files
authored
fix(netdata table): update for functions support (#395)
* chore(table): update table head cells for custom styles * fix(ND table): column visibility option * Display column visibility action when no other bulk actions are defined * Fix typo on visibility * Replace visible key with isVisible on makeColumnVisibilityAction * fix(ND table): update table container to full width of context * fix(ND table): update column visibilty dropdown to be scrollable * fix(netdata table): update return for non available bulk actions * v2.4.3
1 parent debdb26 commit c76d34c

6 files changed

Lines changed: 75 additions & 74 deletions

File tree

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

src/components/tableV2/components/actionWithDropdown.js

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

33
import BulkAction from "./bulkAction"
4-
import ColumnsMenu from "./columnsMenu" //todo refactor this as right now is used only for the dropdown for column visibillity
4+
import ColumnsMenu from "./columnsMenu" //todo refactor this as right now is used only for the dropdown for column visibility
55

66
const ActionWithDropdown = ({
77
id,
@@ -23,7 +23,7 @@ const ActionWithDropdown = ({
2323
const visible = typeof isVisible === "function" ? isVisible() : isVisible
2424

2525
return (
26-
<React.Fragment key={id}>
26+
<>
2727
<BulkAction
2828
ref={actionRef}
2929
testPrefix={`-bulk${testPrefix}`}
@@ -43,7 +43,7 @@ const ActionWithDropdown = ({
4343
columns={table.getAllLeafColumns()}
4444
onClose={onClose}
4545
/>
46-
</React.Fragment>
46+
</>
4747
)
4848
}
4949

src/components/tableV2/components/columnsMenu.js

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,60 @@ import { Text, ListItem } from "src/components/typography"
44
import { Checkbox } from "src/components/checkbox"
55
import Flex from "src/components/templates/flex"
66

7-
import styled from "styled-components"
8-
9-
const Dropdown = styled(Flex)`
10-
box-shadow: 0px 10px 18px rgba(9, 30, 66, 0.15), 0px 0px 1px rgba(9, 30, 66, 0.31);
11-
`
12-
137
const ColumnsMenu = ({ parentRef, isOpen, columns, onClose }) => {
8+
console.log({ isOpen, parentRefCurrent: parentRef.current })
149
if (parentRef.current && isOpen)
1510
return (
16-
<Drop target={parentRef.current} onClickOutside={onClose}>
17-
<Dropdown background="dropdown" column round={1} width={50}>
18-
<Flex column>
19-
<Flex
20-
padding={[2]}
21-
border={{
22-
size: "1px",
23-
type: "solid",
24-
side: "bottom",
25-
color: "borderSecondary",
26-
}}
27-
>
28-
<Text strong>Columns</Text>
29-
</Flex>
11+
<Drop
12+
background="dropdown"
13+
height={{ max: "100vh" }}
14+
onClickOutside={onClose}
15+
overflow={{ vertical: "auto" }}
16+
round={1}
17+
target={parentRef.current}
18+
width={50}
19+
>
20+
<>
21+
<Flex
22+
padding={[2]}
23+
border={{
24+
size: "1px",
25+
type: "solid",
26+
side: "bottom",
27+
color: "borderSecondary",
28+
}}
29+
>
30+
<Text strong>Columns</Text>
31+
</Flex>
3032

31-
{columns.map(column => {
32-
{
33-
return (
34-
column.getCanHide() && (
35-
<Flex
36-
padding={[2]}
37-
as={ListItem}
38-
alignItems="center"
39-
justifyContent="between"
40-
key={column.id}
41-
border={{
42-
size: "1px",
43-
type: "solid",
44-
side: "bottom",
45-
color: "borderSecondary",
46-
}}
47-
>
48-
<Checkbox
49-
checked={column.getIsVisible()}
50-
onChange={column.getToggleVisibilityHandler()}
51-
label={column.id}
52-
/>
53-
</Flex>
54-
)
33+
{columns.map(column => {
34+
{
35+
return (
36+
column.getCanHide() && (
37+
<Flex
38+
padding={[2]}
39+
as={ListItem}
40+
alignItems="center"
41+
justifyContent="between"
42+
key={column.id}
43+
border={{
44+
size: "1px",
45+
type: "solid",
46+
side: "bottom",
47+
color: "borderSecondary",
48+
}}
49+
>
50+
<Checkbox
51+
checked={column.getIsVisible()}
52+
onChange={column.getToggleVisibilityHandler()}
53+
label={column.id}
54+
/>
55+
</Flex>
5556
)
56-
}
57-
})}
58-
</Flex>
59-
</Dropdown>
57+
)
58+
}
59+
})}
60+
</>
6061
</Drop>
6162
)
6263

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const Table = forwardRef(
6767
ref
6868
) => {
6969
return (
70-
<Flex width="100%" height="100%" column>
70+
<Flex width={{ base: "100%", min: "fit-content" }} height="100%" column>
7171
<StyledTableControls>
7272
{handleSearch && (
7373
<Box width={{ max: 50 }}>
@@ -114,11 +114,11 @@ Table.HeadRow = forwardRef(({ children, ...props }, ref) => (
114114
))
115115

116116
Table.HeadCell = forwardRef(
117-
({ children, align = "left", width, maxWidth, minWidth, ...props }, ref) => (
117+
({ children, align = "left", width, maxWidth, minWidth, styles = {}, ...props }, ref) => (
118118
<StyledHeaderCell
119119
width={{ max: maxWidth, base: width, min: minWidth }}
120120
ref={ref}
121-
sx={{ textAlign: align, fontSize: "14px" }}
121+
sx={{ textAlign: align, fontSize: "14px", ...styles }}
122122
{...props}
123123
as="th"
124124
>
@@ -141,6 +141,7 @@ Table.SortingHeadCell = forwardRef(
141141
align = "left",
142142
"data-testid": dataTestid,
143143
"sortby-testid": sortbyTestid,
144+
styles = {},
144145
...props
145146
},
146147
ref
@@ -169,7 +170,7 @@ Table.SortingHeadCell = forwardRef(
169170
as="th"
170171
ref={ref}
171172
{...props}
172-
sx={{ textAlign: align, fontSize: "14px" }}
173+
sx={{ textAlign: align, fontSize: "14px", ...styles }}
173174
data-testid={dataTestid}
174175
>
175176
<Box

src/components/tableV2/core/headCell.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const makeHeadCell = ({ headers, enableSorting, testPrefix }) => {
3838
const HeadCell = headers.map(({ id, colSpan, getContext, isPlaceholder, column }) => {
3939
const { getCanSort, columnDef } = column
4040
const { meta } = columnDef
41+
const styles = meta?.styles || {}
4142

4243
const selectedFilter = meta && meta?.filter?.component ? meta?.filter?.component : "default"
4344
const filterOptions = meta && meta?.filter ? meta?.filter : {}
@@ -61,11 +62,12 @@ const makeHeadCell = ({ headers, enableSorting, testPrefix }) => {
6162
<Filter column={column} testPrefix={testPrefix} {...filterOptions} />
6263
)
6364
}
65+
styles={styles}
6466
>
6567
<Box position="absolute" right={0}>
6668
{tooltipText && (
6769
<Tooltip align="bottom" content={tooltipText}>
68-
<Icon color="nodeBadgeColor" size="small" name="information"></Icon>
70+
<Icon color="nodeBadgeColor" size="small" name="information" />
6971
</Tooltip>
7072
)}
7173
</Box>
@@ -82,6 +84,7 @@ const makeHeadCell = ({ headers, enableSorting, testPrefix }) => {
8284
data-testid={`netdata-table-head-cell${testPrefix}`}
8385
colSpan={colSpan}
8486
key={id}
87+
styles={styles}
8588
>
8689
{isPlaceholder ? null : flexRender(column.columnDef.header, getContext())}
8790
{column.getCanFilter() ? (

src/components/tableV2/features/bulkActions.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export const supportedBulkActions = {
2121
userSettings: { icon: "user", confirmation: false, tooltipText: "User Settings" },
2222
addEntry: { icon: "plus", alwaysEnabled: true, flavour: "default", iconColor: "white" },
2323
remove: { icon: "removeNode", confirmation: true, confirmLabel: "Yes", declineLabel: "No" },
24-
columnVisibillity: { icon: "gear", alwaysEnabled: true },
24+
columnVisibility: { icon: "gear", alwaysEnabled: true },
2525
}
2626

27-
//TODO THIS NEEDS TO BE REFACTORED NOW IS WORKING ONLY FOR COLUMN VISIBILLITY
27+
//TODO THIS NEEDS TO BE REFACTORED NOW IS WORKING ONLY FOR COLUMN VISIBILITY
2828
const renderActionWithDropdown = ({
2929
actions,
3030
table,
@@ -33,7 +33,7 @@ const renderActionWithDropdown = ({
3333
isOpen,
3434
onClose,
3535
}) => {
36-
if (!actions || !actions.length) return <Box aria-hidden as="span" />
36+
if (!actions || !actions.length) return []
3737
return actions.map(
3838
({ id, icon, handleAction, tooltipText, alwaysEnabled, isDisabled, isVisible, ...rest }) => {
3939
return (
@@ -57,17 +57,13 @@ const renderActionWithDropdown = ({
5757
)
5858
}
5959

60-
const makeColumnVisibillityAction = ({ handleAction, visible }) => {
61-
const prepareColumnVisibilityAction = {
62-
id: "columnVisibillity",
63-
handleAction,
64-
visible,
65-
icon: "gear",
66-
alwaysEnabled: true,
67-
}
68-
69-
return prepareColumnVisibilityAction
70-
}
60+
const makeColumnVisibilityAction = ({ handleAction, visible }) => ({
61+
id: "columnVisibility",
62+
handleAction,
63+
isVisible: visible,
64+
icon: "gear",
65+
alwaysEnabled: true,
66+
})
7167

7268
const makeBulkActions = ({
7369
bulkActions,
@@ -76,9 +72,9 @@ const makeBulkActions = ({
7672
selectedRows,
7773
columnVisibilityOptions,
7874
}) => {
79-
const columnVisibillity = makeColumnVisibillityAction({ ...columnVisibilityOptions })
75+
const columnVisibility = makeColumnVisibilityAction({ ...columnVisibilityOptions })
8076
const actionsWithDropdown = renderActionWithDropdown({
81-
actions: [columnVisibillity],
77+
actions: [columnVisibility],
8278
...columnVisibilityOptions,
8379
testPrefix,
8480
table,
@@ -122,7 +118,7 @@ const makeBulkActions = ({
122118
return acc
123119
}, [])
124120

125-
if (!availableBulkActions || !availableBulkActions.length) return []
121+
if (!availableBulkActions || !availableBulkActions.length) return actionsWithDropdown
126122
const actions = availableBulkActions.map(
127123
({ id, icon, handleAction, tooltipText, alwaysEnabled, isDisabled, isVisible, ...rest }) => {
128124
return (

0 commit comments

Comments
 (0)