-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
731 additions
and
39 deletions.
There are no files selected for viewing
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
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
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,24 @@ | ||
import React from 'react'; | ||
|
||
import { IconButton } from '@material-ui/core'; | ||
import Delete from '@mui/icons-material/Delete'; | ||
|
||
type DeleteRoleProps = { | ||
openDialog: (name: string) => void; | ||
roleName: string; | ||
}; | ||
|
||
const DeleteRole = ({ openDialog, roleName }: DeleteRoleProps) => ( | ||
<span data-testid="delete-role"> | ||
<IconButton | ||
onClick={() => openDialog(roleName)} | ||
aria-label="Delete" | ||
disabled={false} | ||
title="Delete Role" | ||
> | ||
<Delete /> | ||
</IconButton> | ||
</span> | ||
); | ||
|
||
export default DeleteRole; |
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,101 @@ | ||
import React from 'react'; | ||
|
||
import { DismissableBanner } from '@backstage/core-components'; | ||
import { useApi } from '@backstage/core-plugin-api'; | ||
|
||
import { | ||
Box, | ||
Button, | ||
createStyles, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
IconButton, | ||
makeStyles, | ||
Theme, | ||
} from '@material-ui/core'; | ||
import CloseIcon from '@material-ui/icons/Close'; | ||
|
||
import { rbacApiRef } from '../api/RBACBackendClient'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
titleContainer: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: theme.spacing(1), | ||
}, | ||
closeButton: { | ||
position: 'absolute', | ||
right: theme.spacing(1), | ||
top: theme.spacing(1), | ||
color: theme.palette.grey[500], | ||
}, | ||
}), | ||
); | ||
|
||
type DeleteRoleDialogProps = { | ||
open: boolean; | ||
closeDialog: () => void; | ||
roleName: string; | ||
}; | ||
|
||
const DeleteRoleDialog = ({ | ||
open, | ||
closeDialog, | ||
roleName, | ||
}: DeleteRoleDialogProps) => { | ||
const classes = useStyles(); | ||
const [error, setError] = React.useState<string>(); | ||
|
||
const rbacApi = useApi(rbacApiRef); | ||
|
||
const deleteRole = async () => { | ||
try { | ||
await rbacApi.deleteRole(roleName); | ||
} catch (err: any) { | ||
setError(err instanceof Error ? err.message : `${err}`); | ||
} | ||
closeDialog(); | ||
}; | ||
|
||
return ( | ||
<Dialog maxWidth="xl" fullWidth open={open} onClose={closeDialog}> | ||
<DialogTitle id="delete-role" title="Delete Role"> | ||
<Box className={classes.titleContainer}> | ||
Delete Role | ||
<IconButton | ||
aria-label="close" | ||
className={classes.closeButton} | ||
onClick={closeDialog} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</Box> | ||
</DialogTitle> | ||
<DialogContent> | ||
Do you want to delete the role{' '} | ||
<span style={{ fontWeight: 'bold' }}>{roleName}</span> ? | ||
</DialogContent> | ||
{error && ( | ||
<DismissableBanner | ||
message={error} | ||
variant="error" | ||
fixed={false} | ||
id="delete-role-error" | ||
/> | ||
)} | ||
<DialogActions> | ||
<Button color="primary" onClick={deleteRole}> | ||
OK | ||
</Button> | ||
<Button color="primary" onClick={closeDialog}> | ||
Cancel | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default DeleteRoleDialog; |
Oops, something went wrong.