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

View file

@ -204,8 +204,7 @@ export default function RealmRoleTabs() {
},
});
const dropdownItems =
url.includes("associated-roles") && !realm?.defaultRole
const dropdownItems = url.includes("associated-roles")
? [
<DropdownItem
key="delete-all-associated"
@ -224,16 +223,6 @@ export default function RealmRoleTabs() {
{t("deleteRole")}
</DropdownItem>,
]
: id && realm?.defaultRole && url.includes("associated-roles")
? [
<DropdownItem
key="delete-all-associated"
component="button"
onClick={() => toggleDeleteAllAssociatedRolesDialog()}
>
{t("roles:removeAllAssociatedRoles")}
</DropdownItem>,
]
: [
<DropdownItem
key="toggle-modal"