@@ -10,11 +10,12 @@ import { useIntl } from 'react-intl';
10
10
import { GroupAdd } from '@mui/icons-material' ;
11
11
import { GridButton , GridButtonDelete , GridTable , GridTableRef } from '../../components/Grid' ;
12
12
import { GroupInfos , UserAdminSrv , UserInfos } from '../../services' ;
13
- import { ColDef , GetRowIdParams , RowClickedEvent , SelectionChangedEvent , TextFilterParams } from 'ag-grid-community' ;
13
+ import { ColDef , GetRowIdParams , RowClickedEvent , TextFilterParams } from 'ag-grid-community' ;
14
14
import { useSnackMessage } from '@gridsuite/commons-ui' ;
15
15
import DeleteConfirmationDialog from '../common/delete-confirmation-dialog' ;
16
16
import { defaultColDef , defaultRowSelection } from '../common/table-config' ;
17
17
import MultiChipCellRenderer from '../common/multi-chip-cell-renderer' ;
18
+ import { useTableSelection } from '../../utils/hooks' ;
18
19
19
20
export interface GroupsTableProps {
20
21
gridRef : RefObject < GridTableRef < GroupInfos > > ;
@@ -26,18 +27,13 @@ const GroupsTable: FunctionComponent<GroupsTableProps> = (props) => {
26
27
const intl = useIntl ( ) ;
27
28
const { snackError } = useSnackMessage ( ) ;
28
29
29
- const [ rowsSelection , setRowsSelection ] = useState < GroupInfos [ ] > ( [ ] ) ;
30
+ const { rowsSelection, onSelectionChanged , onFilterChanged } = useTableSelection < GroupInfos > ( ) ;
30
31
const [ showDeletionDialog , setShowDeletionDialog ] = useState ( false ) ;
31
32
32
33
function getRowId ( params : GetRowIdParams < GroupInfos > ) : string {
33
34
return params . data . name ;
34
35
}
35
36
36
- const onSelectionChanged = useCallback (
37
- ( event : SelectionChangedEvent < GroupInfos , { } > ) => setRowsSelection ( event . api . getSelectedRows ( ) ?? [ ] ) ,
38
- [ setRowsSelection ]
39
- ) ;
40
-
41
37
const onAddButton = useCallback ( ( ) => props . setOpenAddGroupDialog ( true ) , [ props ] ) ;
42
38
43
39
const deleteGroups = useCallback ( ( ) : Promise < void > | undefined => {
@@ -114,6 +110,7 @@ const GroupsTable: FunctionComponent<GroupsTableProps> = (props) => {
114
110
rowSelection = { defaultRowSelection }
115
111
onRowClicked = { props . onRowClicked }
116
112
onSelectionChanged = { onSelectionChanged }
113
+ onFilterChanged = { onFilterChanged }
117
114
>
118
115
< GridButton
119
116
labelId = "groups.table.toolbar.add.label"
0 commit comments