1
- import React , { Fragment } from 'react' ;
1
+ import React , { Fragment , ReactNode } from 'react' ;
2
2
import { useIntl } from 'react-intl' ;
3
3
import messages from '../../Messages' ;
4
4
import { TableVariant , Table , Thead , Tr , Th , Tbody , Td } from '@patternfly/react-table' ;
@@ -10,14 +10,18 @@ import Toolbar, { paginationBuilder } from './toolbar';
10
10
import EmptyWithAction from './empty-state' ;
11
11
import './table-toolbar-view.scss' ;
12
12
import { ISortBy , OnSort } from '@patternfly/react-table' ;
13
- import { CellObject } from '../../smart-components/user/user-table-helpers' ;
13
+ import { CellObject , CellType , SelectCell } from '../../smart-components/user/user-table-helpers' ;
14
14
15
15
interface FilterProps {
16
16
username ?: string ;
17
17
email ?: string ;
18
18
status ?: string [ ] ;
19
19
}
20
20
21
+ function isSelectCell ( cell : any ) : cell is SelectCell {
22
+ return typeof cell === 'object' && typeof cell . select !== 'undefined' ;
23
+ }
24
+
21
25
interface FetchDataProps {
22
26
limit ?: number ;
23
27
offset ?: number ;
@@ -54,7 +58,9 @@ interface MainTableProps {
54
58
setFilterValue : ( value : FilterProps ) => void ;
55
59
pagination : { limit ?: number ; offset ?: number ; count ?: number ; noBottom ?: boolean } ;
56
60
fetchData : ( config : FetchDataProps ) => void ;
57
- toolbarButtons ?: ( ) => ( React . JSX . Element | React . ReactNode ) [ ] ;
61
+ toolbarButtons ?: ( ) => ( React . JSX . Element | { label : string ; props : unknown ; onClick : ( ) => void } ) [ ] ;
62
+ setCheckedItems ?: ( callback : ( selected : unknown [ ] ) => void ) => void ;
63
+ checkedRows ?: unknown [ ] ;
58
64
filterPlaceholder ?: string ;
59
65
filters : Array < {
60
66
value : string | number | Array < unknown > ;
@@ -90,13 +96,14 @@ const MainTable = ({
90
96
isSelectable,
91
97
isLoading,
92
98
noData,
93
- data,
94
99
title,
95
100
filterValue,
96
101
setFilterValue,
97
102
pagination,
98
103
fetchData,
99
104
toolbarButtons,
105
+ setCheckedItems,
106
+ checkedRows,
100
107
filterPlaceholder,
101
108
filters,
102
109
isFilterable,
@@ -125,10 +132,12 @@ const MainTable = ({
125
132
< Toolbar
126
133
isSelectable = { isSelectable }
127
134
isLoading = { isLoading || noData }
128
- data = { data }
135
+ data = { rows }
129
136
titleSingular = { title . singular }
130
137
filterValue = { filterValue }
131
138
setFilterValue = { setFilterValue }
139
+ setCheckedItems = { setCheckedItems }
140
+ checkedRows = { checkedRows }
132
141
sortBy = { orderBy }
133
142
pagination = { pagination }
134
143
fetchData = { fetchData }
@@ -167,10 +176,10 @@ const MainTable = ({
167
176
{ rows ?. length > 0 ? (
168
177
rows ?. map ( ( row , i ) => (
169
178
< Tr key = { i } >
170
- { row . cells . map ( ( cell : CellObject , j : number ) => (
171
- < Td key = { j } dataLabel = { columns [ j ] . title } >
179
+ { row . cells . map ( ( cell : CellType , j : number ) => (
180
+ < Td key = { j } dataLabel = { columns [ j ] . title } { ... ( isSelectCell ( cell ) && cell ) } >
172
181
{ /* TODO: make more general */ }
173
- { isCellObject ( cell ) ? ( cell . title as string ) : ( cell as unknown as React . ReactNode ) }
182
+ { isCellObject ( cell ) ? ( cell . title as string ) : isSelectCell ( cell ) ? null : ( cell as unknown as React . ReactNode ) }
174
183
</ Td >
175
184
) ) }
176
185
</ Tr >
@@ -240,6 +249,8 @@ export const TableComposableToolbarView = ({
240
249
isLoading,
241
250
emptyFilters,
242
251
setFilterValue,
252
+ setCheckedItems,
253
+ checkedRows,
243
254
isSelectable = false ,
244
255
fetchData,
245
256
emptyProps,
@@ -272,11 +283,12 @@ export const TableComposableToolbarView = ({
272
283
intl . formatMessage ( messages . toConfigureUserAccess ) ,
273
284
intl . formatMessage ( messages . createAtLeastOneItem , { item : title . singular } ) ,
274
285
] }
275
- actions = { toolbarButtons ? toolbarButtons ( ) [ 0 ] : false }
286
+ actions = { toolbarButtons ? ( toolbarButtons ( ) [ 0 ] as ReactNode ) : false }
276
287
{ ...( typeof emptyProps === 'object' ? emptyProps : { } ) }
277
288
/>
278
289
) : (
279
290
< MainTable
291
+ setCheckedItems = { setCheckedItems }
280
292
columns = { columns }
281
293
isSelectable = { isSelectable }
282
294
isLoading = { isLoading }
@@ -307,6 +319,7 @@ export const TableComposableToolbarView = ({
307
319
ouiaId = { ouiaId }
308
320
noDataDescription = { noDataDescription }
309
321
emptyFilters = { emptyFilters }
322
+ checkedRows = { checkedRows }
310
323
/>
311
324
) }
312
325
</ Fragment >
0 commit comments