delete functionality and do not display current role in modal (#1543)

This commit is contained in:
Jenny 2021-11-19 05:55:52 -05:00 committed by GitHub
parent 2c9a8657df
commit 0b95598411
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 54 deletions

View file

@ -68,7 +68,9 @@ export const AssociatedRolesModal = ({
params.search = searchParam; params.search = searchParam;
} }
return adminClient.roles.find(params); return (await adminClient.roles.find(params)).filter(
(item) => item.name !== name
);
}; };
const AliasRenderer = ({ id, name, clientId }: Role) => { const AliasRenderer = ({ id, name, clientId }: Role) => {
@ -91,10 +93,12 @@ export const AssociatedRolesModal = ({
clients.map(async (client) => { clients.map(async (client) => {
const roles = await adminClient.clients.listRoles({ id: client.id! }); const roles = await adminClient.clients.listRoles({ id: client.id! });
return roles.map<Role>((role) => ({ return roles
...role, .map<Role>((role) => ({
clientId: client.clientId, ...role,
})); clientId: client.clientId,
}))
.filter((item) => item.name !== name);
}) })
); );
@ -115,7 +119,7 @@ export const AssociatedRolesModal = ({
return { role, compositeRoles }; return { role, compositeRoles };
}, },
({ role, compositeRoles }) => { ({ role, compositeRoles }) => {
setName(role ? role.name! : t("createRole")); setName(role?.name!);
setCompositeRoles(compositeRoles); setCompositeRoles(compositeRoles);
}, },
[] []
@ -142,7 +146,9 @@ export const AssociatedRolesModal = ({
return ( return (
<Modal <Modal
data-testid="addAssociatedRole" data-testid="addAssociatedRole"
title={t("roles:associatedRolesModalTitle", { name })} title={
name ? t("roles:associatedRolesModalTitle", { name }) : t("addRole")
}
isOpen isOpen
onClose={toggleDialog} onClose={toggleDialog}
variant={ModalVariant.large} variant={ModalVariant.large}

View file

@ -204,53 +204,42 @@ export default function RealmRoleTabs() {
}, },
}); });
const dropdownItems = const dropdownItems = url.includes("associated-roles")
url.includes("associated-roles") && !realm?.defaultRole ? [
? [ <DropdownItem
<DropdownItem key="delete-all-associated"
key="delete-all-associated" component="button"
component="button" onClick={() => toggleDeleteAllAssociatedRolesDialog()}
onClick={() => toggleDeleteAllAssociatedRolesDialog()} >
> {t("roles:removeAllAssociatedRoles")}
{t("roles:removeAllAssociatedRoles")} </DropdownItem>,
</DropdownItem>, <DropdownItem
<DropdownItem key="delete-role"
key="delete-role" component="button"
component="button" onClick={() => {
onClick={() => { toggleDeleteDialog();
toggleDeleteDialog(); }}
}} >
> {t("deleteRole")}
{t("deleteRole")} </DropdownItem>,
</DropdownItem>, ]
] : [
: id && realm?.defaultRole && url.includes("associated-roles") <DropdownItem
? [ key="toggle-modal"
<DropdownItem data-testid="add-roles"
key="delete-all-associated" component="button"
component="button" onClick={() => toggleModal()}
onClick={() => toggleDeleteAllAssociatedRolesDialog()} >
> {t("addAssociatedRolesText")}
{t("roles:removeAllAssociatedRoles")} </DropdownItem>,
</DropdownItem>, <DropdownItem
] key="delete-role"
: [ component="button"
<DropdownItem onClick={() => toggleDeleteDialog()}
key="toggle-modal" >
data-testid="add-roles" {t("deleteRole")}
component="button" </DropdownItem>,
onClick={() => toggleModal()} ];
>
{t("addAssociatedRolesText")}
</DropdownItem>,
<DropdownItem
key="delete-role"
component="button"
onClick={() => toggleDeleteDialog()}
>
{t("deleteRole")}
</DropdownItem>,
];
const [ const [
toggleDeleteAllAssociatedRolesDialog, toggleDeleteAllAssociatedRolesDialog,