Skip to content

Commit 7d19568

Browse files
authored
Bug fixes refactor table (#393)
* make SeparateComponent for Bulk Action * add action with drodown to a saperate file * saparate features from netdataTable to components * move availalbe bulk actions inside bulk aciton compoonent * move bulk actions to saparate component * bulk actions * move row actions to saparate component * move everything to its folder * move base-table to core folder * minor change at yaml
1 parent daba5f9 commit 7d19568

18 files changed

Lines changed: 635 additions & 578 deletions

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
---
21
name: tests
32

43
on:
54
push:
6-
branches: [master]
5+
branches:
6+
- master
77
workflow_dispatch:
88

99
concurrency:
@@ -21,7 +21,7 @@ jobs:
2121

2222
- uses: actions/setup-node@v2
2323
with:
24-
node-version: "12.x"
24+
node-version: "16.10.0"
2525
cache: "yarn"
2626
- name: Install dependencies
2727
run: yarn
File renamed without changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React, { useRef } from "react"
2+
3+
import BulkAction from "./bulkAction"
4+
import ColumnsMenu from "./columnsMenu" //todo refactor this as right now is used only for the dropdown for column visibillity
5+
6+
const ActionWithDropdown = ({
7+
id,
8+
icon,
9+
handleAction,
10+
tooltipText,
11+
alwaysEnabled,
12+
isDisabled,
13+
isVisible,
14+
testPrefix,
15+
selectedRows,
16+
table,
17+
isOpen,
18+
onClose,
19+
...rest
20+
}) => {
21+
const actionRef = useRef()
22+
const disabled = typeof isDisabled === "function" ? isDisabled() : isDisabled
23+
const visible = typeof isVisible === "function" ? isVisible() : isVisible
24+
25+
return (
26+
<React.Fragment key={id}>
27+
<BulkAction
28+
ref={actionRef}
29+
testPrefix={`-bulk${testPrefix}`}
30+
visible={visible}
31+
id={id}
32+
icon={icon}
33+
handleAction={() => handleAction(selectedRows, table)}
34+
tooltipText={tooltipText}
35+
disabled={(!alwaysEnabled && selectedRows?.length < 1) || disabled}
36+
background="elementBackground"
37+
selectedRows={selectedRows}
38+
{...rest}
39+
/>
40+
<ColumnsMenu
41+
parentRef={actionRef}
42+
isOpen={isOpen}
43+
columns={table.getAllLeafColumns()}
44+
onClose={onClose}
45+
/>
46+
</React.Fragment>
47+
)
48+
}
49+
50+
export default ActionWithDropdown
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React, { useRef, forwardRef } from "react"
2+
import Action from "./action"
3+
4+
import { mergeRefs } from "src/utils"
5+
6+
const BulkAction = forwardRef(
7+
(
8+
{
9+
isDisabled,
10+
isVisible,
11+
testPrefix,
12+
id,
13+
icon,
14+
handleAction,
15+
selectedRows,
16+
table,
17+
tooltipText,
18+
alwaysEnabled,
19+
...rest
20+
},
21+
ref
22+
) => {
23+
const actionRef = useRef()
24+
const disabled = typeof isDisabled === "function" ? isDisabled() : isDisabled
25+
const visible = typeof isVisible === "function" ? isVisible() : isVisible
26+
27+
return (
28+
<Action
29+
ref={mergeRefs(actionRef, ref)}
30+
testPrefix={`-bulk${testPrefix}`}
31+
key={id}
32+
visible={visible}
33+
id={id}
34+
icon={icon}
35+
handleAction={() => handleAction(selectedRows, table)}
36+
tooltipText={tooltipText}
37+
disabled={(!alwaysEnabled && selectedRows?.length < 1) || disabled}
38+
background="elementBackground"
39+
selectedRows={selectedRows}
40+
{...rest}
41+
/>
42+
)
43+
}
44+
)
45+
46+
export default BulkAction
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import React from "react"
2+
3+
import ComparisonFilter from "../components/comparisonFilter"
4+
import SelectFilter from "../components/selectFilter"
5+
6+
import SearchInput from "src/components/search"
7+
import Box from "src/components/templates/box"
8+
import Tooltip from "src/components/drops/tooltip"
9+
import { Icon } from "src/components/icon"
10+
11+
import Table from "./base-table"
12+
13+
import { flexRender } from "@tanstack/react-table"
14+
15+
const SearchFilter = ({ column, testPrefix }) => {
16+
const columnFilterValue = column.getFilterValue()
17+
const { id = "" } = column
18+
return (
19+
<Box
20+
data-testid={`netdata-table-filter-${id}${testPrefix}`}
21+
as={SearchInput}
22+
width={{ max: 50 }}
23+
value={columnFilterValue ?? ""}
24+
placeholder={"...Search"}
25+
iconRight={<Icon name="magnify" />}
26+
onChange={e => column.setFilterValue(e.target.value)}
27+
/>
28+
)
29+
}
30+
31+
const availableFilters = {
32+
comparison: ComparisonFilter,
33+
select: SelectFilter,
34+
default: SearchFilter,
35+
}
36+
37+
const makeHeadCell = ({ headers, enableSorting, testPrefix }) => {
38+
const HeadCell = headers.map(({ id, colSpan, getContext, isPlaceholder, column }) => {
39+
const { getCanSort, columnDef } = column
40+
const { meta } = columnDef
41+
42+
const selectedFilter = meta && meta?.filter?.component ? meta?.filter?.component : "default"
43+
const filterOptions = meta && meta?.filter ? meta?.filter : {}
44+
const tooltipText = meta && meta?.tooltip ? meta?.tooltip : ""
45+
const Filter = availableFilters[selectedFilter]
46+
47+
if (getCanSort() && enableSorting) {
48+
return (
49+
<Table.SortingHeadCell
50+
width={column.getSize()}
51+
minWidth={column.columnDef.minSize}
52+
maxWidth={column.columnDef.maxSize}
53+
data-testid={`netdata-table-head-cell${testPrefix}`}
54+
sortby-testid={`netdata-table-head-cell-sortyBy-${id}${testPrefix}`}
55+
sortDirection={column.getIsSorted()}
56+
onSortClicked={column.getToggleSortingHandler()}
57+
colSpan={colSpan}
58+
key={id}
59+
filter={
60+
column.getCanFilter() && (
61+
<Filter column={column} testPrefix={testPrefix} {...filterOptions} />
62+
)
63+
}
64+
>
65+
<Box position="absolute" right={0}>
66+
{tooltipText && (
67+
<Tooltip align="bottom" content={tooltipText}>
68+
<Icon color="nodeBadgeColor" size="small" name="information"></Icon>
69+
</Tooltip>
70+
)}
71+
</Box>
72+
{isPlaceholder ? null : flexRender(column.columnDef.header, getContext())}{" "}
73+
</Table.SortingHeadCell>
74+
)
75+
}
76+
77+
return (
78+
<Table.HeadCell
79+
width={column.getSize()}
80+
minWidth={column.columnDef.minSize}
81+
maxWidth={column.columnDef.maxSize}
82+
data-testid={`netdata-table-head-cell${testPrefix}`}
83+
colSpan={colSpan}
84+
key={id}
85+
>
86+
{isPlaceholder ? null : flexRender(column.columnDef.header, getContext())}
87+
{column.getCanFilter() ? (
88+
<div>
89+
<Filter column={column} testPrefix={testPrefix} {...filterOptions} />
90+
</div>
91+
) : null}
92+
</Table.HeadCell>
93+
)
94+
})
95+
96+
return HeadCell
97+
}
98+
99+
export default makeHeadCell

0 commit comments

Comments
 (0)