@@ -20,8 +20,8 @@ import { Theme } from "@mui/material/styles";
2020import createStyles from "@mui/styles/createStyles" ;
2121import withStyles from "@mui/styles/withStyles" ;
2222import Grid from "@mui/material/Grid" ;
23- import { LinearProgress } from "@mui/material" ;
24- import { AddIcon , GroupsIcon , UsersIcon } from "../../../icons" ;
23+ import { LinearProgress , Box } from "@mui/material" ;
24+ import { AddIcon , GroupsIcon , UsersIcon , DeleteIcon , IAMPoliciesIcon } from "../../../icons" ;
2525import { setErrorSnackMessage } from "../../../actions" ;
2626import { GroupsList } from "./types" ;
2727import { stringSort } from "../../../utils/sortFunctions" ;
@@ -79,12 +79,12 @@ const styles = (theme: Theme) =>
7979 } ) ;
8080
8181const Groups = ( { classes, setErrorSnackMessage, history } : IGroupsProps ) => {
82- const [ selectedGroup , setSelectedGroup ] = useState < any > ( null ) ;
8382 const [ deleteOpen , setDeleteOpen ] = useState < boolean > ( false ) ;
8483 const [ loading , isLoading ] = useState < boolean > ( false ) ;
8584 const [ records , setRecords ] = useState < any [ ] > ( [ ] ) ;
8685 const [ filter , setFilter ] = useState < string > ( "" ) ;
8786 const [ policyOpen , setPolicyOpen ] = useState < boolean > ( false ) ;
87+ const [ checkedGroups , setCheckedGroups ] = useState < string [ ] > ( [ ] ) ;
8888
8989 useEffect ( ( ) => {
9090 isLoading ( true ) ;
@@ -106,6 +106,24 @@ const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => {
106106 IAM_SCOPES . ADMIN_GET_GROUP ,
107107 ] ) ;
108108
109+ const selectionChanged = ( e : React . ChangeEvent < HTMLInputElement > ) => {
110+ const { target : { value = "" , checked = false } = { } } = e ;
111+
112+ let elements : string [ ] = [ ...checkedGroups ] ; // We clone the checkedUsers array
113+
114+ if ( checked ) {
115+ // If the user has checked this field we need to push this to checkedUsersList
116+ elements . push ( value ) ;
117+ } else {
118+ // User has unchecked this field, we need to remove it from the list
119+ elements = elements . filter ( ( element ) => element !== value ) ;
120+ }
121+
122+ setCheckedGroups ( elements ) ;
123+
124+ return elements ;
125+ } ;
126+
109127 useEffect ( ( ) => {
110128 if ( loading ) {
111129 if ( displayGroups ) {
@@ -134,7 +152,7 @@ const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => {
134152
135153 const closeDeleteModalAndRefresh = ( refresh : boolean ) => {
136154 setDeleteOpen ( false ) ;
137-
155+ setCheckedGroups ( [ ] ) ;
138156 if ( refresh ) {
139157 isLoading ( true ) ;
140158 }
@@ -148,10 +166,6 @@ const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => {
148166 history . push ( `${ IAM_PAGES . GROUPS } /${ group } ` ) ;
149167 } ;
150168
151- const deleteAction = ( group : any ) => {
152- setDeleteOpen ( true ) ;
153- setSelectedGroup ( group ) ;
154- } ;
155169
156170 const tableActions = [
157171 {
@@ -160,25 +174,26 @@ const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => {
160174 disableButtonFunction : ( ) => ! getGroup ,
161175 } ,
162176 {
163- type : "delete " ,
164- onClick : deleteAction ,
165- disableButtonFunction : ( ) => ! deleteGroup ,
177+ type : "edit " ,
178+ onClick : viewAction ,
179+ disableButtonFunction : ( ) => ! getGroup ,
166180 } ,
167181 ] ;
168182
183+
169184 return (
170185 < React . Fragment >
171186 { deleteOpen && (
172187 < DeleteGroup
173188 deleteOpen = { deleteOpen }
174- selectedGroup = { selectedGroup }
189+ selectedGroups = { checkedGroups }
175190 closeDeleteModalAndRefresh = { closeDeleteModalAndRefresh }
176191 />
177192 ) }
178- { setPolicyOpen && (
193+ { policyOpen && (
179194 < SetPolicy
180195 open = { policyOpen }
181- selectedGroup = { selectedGroup }
196+ selectedGroup = { checkedGroups [ 0 ] }
182197 selectedUser = { null }
183198 closeModalAndRefresh = { ( ) => {
184199 setPolicyOpen ( false ) ;
@@ -189,19 +204,67 @@ const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => {
189204
190205 < PageLayout >
191206 < Grid item xs = { 12 } className = { classes . actionsTray } >
207+
192208 < SecureComponent
193209 resource = { CONSOLE_UI_RESOURCE }
194210 scopes = { [ IAM_SCOPES . ADMIN_LIST_GROUPS ] }
195211 errorProps = { { disabled : true } }
196- >
212+ >
197213 < SearchBox
198214 placeholder = { "Search Groups" }
199215 onChange = { setFilter }
200216 overrideClass = { classes . searchField }
201217 value = { filter }
202218 />
203- </ SecureComponent >
204-
219+ </ SecureComponent >
220+ < Box
221+ sx = { {
222+ display : "flex" ,
223+ } }
224+ >
225+ { " " }
226+ < SecureComponent
227+ resource = { CONSOLE_UI_RESOURCE }
228+ scopes = { [
229+ IAM_SCOPES . ADMIN_ATTACH_USER_OR_GROUP_POLICY
230+ ] }
231+ matchAll
232+ errorProps = { { disabled : true } }
233+ >
234+ < RBIconButton
235+ tooltip = { "Select Policy" }
236+ onClick = { ( ) => {
237+ setPolicyOpen ( true ) ;
238+ } }
239+ text = { "Assign Policy" }
240+ icon = { < IAMPoliciesIcon /> }
241+ color = "primary"
242+ disabled = { checkedGroups . length !== 1 }
243+ variant = { "outlined" }
244+ />
245+
246+ </ SecureComponent >
247+ < SecureComponent
248+ resource = { CONSOLE_UI_RESOURCE }
249+ scopes = { [
250+ IAM_SCOPES . ADMIN_REMOVE_USER_FROM_GROUP
251+ ] }
252+ matchAll
253+ errorProps = { { disabled : true } }
254+ >
255+ < RBIconButton
256+ tooltip = { "Delete Selected" }
257+ onClick = { ( ) => {
258+ setDeleteOpen ( true ) ;
259+ } }
260+ text = { "Delete Selected" }
261+ icon = { < DeleteIcon /> }
262+ color = "secondary"
263+ disabled = { checkedGroups . length === 0 }
264+ variant = { "outlined" }
265+ />
266+
267+ </ SecureComponent >
205268 < SecureComponent
206269 resource = { CONSOLE_UI_RESOURCE }
207270 scopes = { [
@@ -222,6 +285,7 @@ const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => {
222285 } }
223286 />
224287 </ SecureComponent >
288+ </ Box >
225289 </ Grid >
226290 { loading && < LinearProgress /> }
227291 { ! loading && (
@@ -238,6 +302,8 @@ const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => {
238302 itemActions = { tableActions }
239303 columns = { [ { label : "Name" , elementKey : "" } ] }
240304 isLoading = { loading }
305+ selectedItems = { checkedGroups }
306+ onSelect = { deleteGroup ? selectionChanged : undefined }
241307 records = { filteredRecords }
242308 entityName = "Groups"
243309 idField = ""
0 commit comments