Skip to content

Commit dcd23e4

Browse files
authored
fix(netdata table): sticky position of actions (#397)
* fix(netdata table): sticky position of actions * chore(netdata table): remove forgotten console * chore(netdata table): fix typo for initial column visibility * fix(netdata table): update table head for no bulk actions
1 parent c76d34c commit dcd23e4

3 files changed

Lines changed: 47 additions & 35 deletions

File tree

src/components/tableV2/components/columnsMenu.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Checkbox } from "src/components/checkbox"
55
import Flex from "src/components/templates/flex"
66

77
const ColumnsMenu = ({ parentRef, isOpen, columns, onClose }) => {
8-
console.log({ isOpen, parentRefCurrent: parentRef.current })
98
if (parentRef.current && isOpen)
109
return (
1110
<Drop

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

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const StyledTableControls = styled(Flex)`
5656
const Table = forwardRef(
5757
(
5858
{
59+
hasBulkActions,
5960
handleSearch,
6061
children,
6162
searchPlaceholder = "Search",
@@ -67,26 +68,28 @@ const Table = forwardRef(
6768
ref
6869
) => {
6970
return (
70-
<Flex width={{ base: "100%", min: "fit-content" }} height="100%" column>
71-
<StyledTableControls>
72-
{handleSearch && (
73-
<Box width={{ max: 50 }}>
74-
<SearchInput
75-
data-testid="table-global-search-filter"
76-
data-ga={`${dataGa}::search::table-filter`}
77-
onChange={debounce(300, e => {
78-
e.persist()
79-
handleSearch(e.target.value)
80-
})}
81-
placeholder={searchPlaceholder}
82-
iconRight={<Icon name="magnify" color="textLite" />}
83-
/>
84-
</Box>
85-
)}
86-
<Flex gap={1} data-testid="bulk-actions" width="100%" justifyContent="end">
87-
{bulkActions && bulkActions()}
88-
</Flex>
89-
</StyledTableControls>
71+
<Flex width={{ base: "100%", min: "fit-content" }} column>
72+
{(hasBulkActions || handleSearch) && (
73+
<StyledTableControls>
74+
{handleSearch && (
75+
<Box width={{ max: 50 }}>
76+
<SearchInput
77+
data-testid="table-global-search-filter"
78+
data-ga={`${dataGa}::search::table-filter`}
79+
onChange={debounce(300, e => {
80+
e.persist()
81+
handleSearch(e.target.value)
82+
})}
83+
placeholder={searchPlaceholder}
84+
iconRight={<Icon name="magnify" color="textLite" />}
85+
/>
86+
</Box>
87+
)}
88+
<Flex gap={1} data-testid="bulk-actions" width="100%" justifyContent="end">
89+
{bulkActions && bulkActions()}
90+
</Flex>
91+
</StyledTableControls>
92+
)}
9093
<Box sx={{ borderCollapse: "separate" }} ref={ref} as="table" {...props}>
9194
{children}
9295
</Box>
@@ -96,16 +99,23 @@ const Table = forwardRef(
9699
}
97100
)
98101

99-
Table.Head = forwardRef(({ children, ...props }, ref) => (
100-
<Box
101-
ref={ref}
102-
sx={{ whiteSpace: "nowrap", position: "sticky", top: "50px", zIndex: "10" }}
103-
as="thead"
104-
{...props}
105-
>
106-
{children}
107-
</Box>
108-
))
102+
Table.Head = forwardRef(({ hasBulkActions, children, ...props }, ref) => {
103+
return (
104+
<Box
105+
ref={ref}
106+
sx={{
107+
whiteSpace: "nowrap",
108+
position: "sticky",
109+
top: hasBulkActions ? "50px" : "0",
110+
zIndex: "10",
111+
}}
112+
as="thead"
113+
{...props}
114+
>
115+
{children}
116+
</Box>
117+
)
118+
})
109119

110120
Table.HeadRow = forwardRef(({ children, ...props }, ref) => (
111121
<StyledHeaderRow ref={ref} {...props}>

src/components/tableV2/netdataTable.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ const NetdataTable = ({
3939
pageIndex: 0,
4040
pageSize: 100,
4141
},
42-
columnVisibility: intialColumnVisibility,
42+
columnVisibility: initialColumnVisibility,
4343
testPrefix = "",
4444
sortBy = [],
4545
testPrefixCallback,
4646
dataGa,
4747
enableColumnVisibility = false,
4848
}) => {
4949
const [isColumnDropdownVisible, setIsColumnDropdownVisible] = useState(false)
50-
const [columnVisibility, setColumnVisibility] = useState(intialColumnVisibility)
50+
const [columnVisibility, setColumnVisibility] = useState(initialColumnVisibility)
5151

5252
const [originalSelectedRows, setOriginalSelectedRow] = useState([])
5353
const [sorting, setSorting] = useState(sortBy)
@@ -174,18 +174,21 @@ const NetdataTable = ({
174174

175175
const headers = table.getFlatHeaders()
176176

177+
const hasBulkActions = enableColumnVisibility || !!Object.keys(bulkActions).length
178+
177179
return (
178180
<Table
179181
selectedRows={originalSelectedRows}
180-
bulkActions={() => renderBulkActions()}
182+
hasBulkActions={hasBulkActions}
183+
bulkActions={renderBulkActions}
181184
Pagination={enablePagination && makePagination({ table })}
182185
handleSearch={onGlobalSearchChange ? handleGlobalSearch : null}
183186
ref={tableRef}
184187
data-testid={`netdata-table${testPrefix}`}
185188
testPrefix={testPrefix}
186189
dataGa={dataGa}
187190
>
188-
<Table.Head data-testid={`netdata-table-head${testPrefix}`}>
191+
<Table.Head hasBulkActions={hasBulkActions} data-testid={`netdata-table-head${testPrefix}`}>
189192
<Table.HeadRow data-testid={`netdata-table-headRow${testPrefix}`}>
190193
{makeHeadCell({ headers, enableSorting, testPrefix })}
191194
</Table.HeadRow>

0 commit comments

Comments
 (0)