@@ -3,6 +3,8 @@ import { Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerContentB
33import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView' ;
44import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable' ;
55import { 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' ;
68
79interface Repository {
810 name : string ;
@@ -64,25 +66,45 @@ interface RepositoriesTableProps {
6466 selectedRepo ?: Repository ;
6567}
6668
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+
6787const RepositoriesTable : React . FunctionComponent < RepositoriesTableProps > = ( { selectedRepo = undefined } ) => {
88+ const selection = useDataViewSelection ( { matchOption : ( a , b ) => a . row [ 0 ] === b . row [ 0 ] } ) ;
6889 const { trigger } = useDataViewEventsContext ( ) ;
6990 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 ) ;
7294 } ;
7395
7496 return repositories . map ( repo => ( {
75- row : Object . values ( repo ) ,
97+ row : [ ... Object . values ( repo ) , { cell : < ActionsColumn items = { rowActions } /> , props : { isActionCell : true } } ] ,
7698 props : {
7799 isClickable : true ,
78- onRowClick : ( ) => handleRowClick ( selectedRepo ?. name === repo . name ? undefined : repo ) ,
100+ onRowClick : ( event ) => handleRowClick ( event , selectedRepo ?. name === repo . name ? undefined : repo ) ,
79101 isRowSelected : selectedRepo ?. name === repo . name
80102 }
81103 } ) ) ;
82104 } , [ selectedRepo ?. name , trigger ] ) ;
83105
84106 return (
85- < DataView >
107+ < DataView selection = { selection } >
86108 < DataViewTable aria-label = 'Repositories table' ouiaId = { ouiaId } columns = { columns } rows = { rows } />
87109 </ DataView >
88110 ) ;
0 commit comments