-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The 'Delete' modal functionality must be adapted to work with the User groups data. Signed-off-by: Carla Martinez <[email protected]>
- Loading branch information
Showing
4 changed files
with
127 additions
and
172 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
115 changes: 115 additions & 0 deletions
115
src/components/MemberOf/MemberOfDeleteModalUserGroups.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React from "react"; | ||
// PatternFly | ||
import { | ||
TextContent, | ||
Text, | ||
TextVariants, | ||
Button, | ||
Modal, | ||
Form, | ||
FormGroup, | ||
} from "@patternfly/react-core"; | ||
// Tables | ||
import MemberOfDeletedGroupsTable from "src/components/MemberOf/MemberOfDeletedGroupsTable"; | ||
// Data types | ||
import { UserGroup } from "src/utils/datatypes/globalDataTypes"; | ||
|
||
interface PropsToDelete { | ||
showModal: boolean; | ||
onCloseModal: () => void; | ||
tabName: string; | ||
groupNamesToDelete: string[]; | ||
groupRepository: UserGroup[]; | ||
updateGroupRepository: (args: UserGroup[]) => void; | ||
updateGroupNamesToDelete: (args: string[]) => void; | ||
} | ||
|
||
const MemberOfDeleteModal = (props: PropsToDelete) => { | ||
// Given a single group name, obtain full info to be sent and shown on the deletion table | ||
const getGroupInfoByName = (groupName: string) => { | ||
const res = props.groupRepository.filter( | ||
(group) => group.name === groupName | ||
); | ||
return res[0]; | ||
}; | ||
|
||
// Obtain full info of groups to delete | ||
const getListOfGroupsToDelete = () => { | ||
const groupsToDelete: UserGroup[] = []; | ||
props.groupNamesToDelete.map((groupName) => | ||
groupsToDelete.push(getGroupInfoByName(groupName)) | ||
); | ||
return groupsToDelete; | ||
}; | ||
|
||
// Groups to delete list | ||
const groupsToDelete: UserGroup[] = getListOfGroupsToDelete(); | ||
|
||
// Delete groups | ||
const deleteGroups = () => { | ||
let generalUpdatedGroupList = props.groupRepository; | ||
props.groupNamesToDelete.map((groupName) => { | ||
const updatedGroupList = generalUpdatedGroupList.filter( | ||
(grp) => grp.name !== groupName | ||
); | ||
// If not empty, replace groupList by new array | ||
if (updatedGroupList) { | ||
generalUpdatedGroupList = updatedGroupList; | ||
} | ||
}); | ||
props.updateGroupRepository(generalUpdatedGroupList); | ||
props.updateGroupNamesToDelete([]); | ||
props.onCloseModal(); | ||
}; | ||
|
||
// Modal actions | ||
const modalActionsDelete: JSX.Element[] = [ | ||
<Button | ||
key="delete-groups" | ||
variant="danger" | ||
onClick={deleteGroups} | ||
form="active-users-remove-groups-modal" | ||
> | ||
Delete | ||
</Button>, | ||
<Button | ||
key="cancel-remove-group" | ||
variant="link" | ||
onClick={props.onCloseModal} | ||
> | ||
Cancel | ||
</Button>, | ||
]; | ||
|
||
return ( | ||
<Modal | ||
variant={"medium"} | ||
position={"top"} | ||
positionOffset={"76px"} | ||
title={"Remove " + props.tabName} | ||
isOpen={props.showModal} | ||
onClose={props.onCloseModal} | ||
actions={modalActionsDelete} | ||
aria-label="Delete member modal" | ||
> | ||
<Form id={"is-member-of-delete-modal"}> | ||
<FormGroup key={"question-text"} fieldId={"question-text"}> | ||
<TextContent> | ||
<Text component={TextVariants.p}> | ||
Are you sure you want to remove the selected entries from the | ||
list? | ||
</Text> | ||
</TextContent> | ||
</FormGroup> | ||
<FormGroup key={"deleted-users-table"} fieldId={"deleted-users-table"}> | ||
<MemberOfDeletedGroupsTable | ||
groupsToDelete={groupsToDelete} | ||
tabName={props.tabName} | ||
/> | ||
</FormGroup> | ||
</Form> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default MemberOfDeleteModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters