@@ -3,6 +3,8 @@ import { Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerContentB
3
3
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView' ;
4
4
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable' ;
5
5
import { DataViewEventsProvider , EventTypes , useDataViewEventsContext } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext' ;
6
+ import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks' ;
7
+ import { ActionsColumn } from '@patternfly/react-table' ;
6
8
7
9
interface Repository {
8
10
name : string ;
@@ -64,25 +66,45 @@ interface RepositoriesTableProps {
64
66
selectedRepo ?: Repository ;
65
67
}
66
68
69
+ const rowActions = [
70
+ {
71
+ title : 'Some action' ,
72
+ onClick : ( ) => console . log ( 'clicked on Some action' ) // eslint-disable-line no-console
73
+ } ,
74
+ {
75
+ title : < div > Another action</ div > ,
76
+ onClick : ( ) => console . log ( 'clicked on Another action' ) // eslint-disable-line no-console
77
+ } ,
78
+ {
79
+ isSeparator : true
80
+ } ,
81
+ {
82
+ title : 'Third action' ,
83
+ onClick : ( ) => console . log ( 'clicked on Third action' ) // eslint-disable-line no-console
84
+ }
85
+ ] ;
86
+
67
87
const RepositoriesTable : React . FunctionComponent < RepositoriesTableProps > = ( { selectedRepo = undefined } ) => {
88
+ const selection = useDataViewSelection ( { matchOption : ( a , b ) => a . row [ 0 ] === b . row [ 0 ] } ) ;
68
89
const { trigger } = useDataViewEventsContext ( ) ;
69
90
const rows = useMemo ( ( ) => {
70
- const handleRowClick = ( repo : Repository | undefined ) => {
71
- trigger ( EventTypes . rowClick , repo ) ;
91
+ const handleRowClick = ( event , repo : Repository | undefined ) => {
92
+ // prevents drawer toggle on actions or checkbox click
93
+ event . target . matches ( 'td' ) && trigger ( EventTypes . rowClick , repo ) ;
72
94
} ;
73
95
74
96
return repositories . map ( repo => ( {
75
- row : Object . values ( repo ) ,
97
+ row : [ ... Object . values ( repo ) , { cell : < ActionsColumn items = { rowActions } /> , props : { isActionCell : true } } ] ,
76
98
props : {
77
99
isClickable : true ,
78
- onRowClick : ( ) => handleRowClick ( selectedRepo ?. name === repo . name ? undefined : repo ) ,
100
+ onRowClick : ( event ) => handleRowClick ( event , selectedRepo ?. name === repo . name ? undefined : repo ) ,
79
101
isRowSelected : selectedRepo ?. name === repo . name
80
102
}
81
103
} ) ) ;
82
104
} , [ selectedRepo ?. name , trigger ] ) ;
83
105
84
106
return (
85
- < DataView >
107
+ < DataView selection = { selection } >
86
108
< DataViewTable aria-label = 'Repositories table' ouiaId = { ouiaId } columns = { columns } rows = { rows } />
87
109
</ DataView >
88
110
) ;
0 commit comments