delete functionality and do not display current role in modal (#1543)
This commit is contained in:
parent
2c9a8657df
commit
0b95598411
2 changed files with 49 additions and 54 deletions
|
@ -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) => ({
|
||||
...role,
|
||||
clientId: client.clientId,
|
||||
}));
|
||||
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}
|
||||
|
|
|
@ -204,53 +204,42 @@ export default function RealmRoleTabs() {
|
|||
},
|
||||
});
|
||||
|
||||
const dropdownItems =
|
||||
url.includes("associated-roles") && !realm?.defaultRole
|
||||
? [
|
||||
<DropdownItem
|
||||
key="delete-all-associated"
|
||||
component="button"
|
||||
onClick={() => toggleDeleteAllAssociatedRolesDialog()}
|
||||
>
|
||||
{t("roles:removeAllAssociatedRoles")}
|
||||
</DropdownItem>,
|
||||
<DropdownItem
|
||||
key="delete-role"
|
||||
component="button"
|
||||
onClick={() => {
|
||||
toggleDeleteDialog();
|
||||
}}
|
||||
>
|
||||
{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"
|
||||
data-testid="add-roles"
|
||||
component="button"
|
||||
onClick={() => toggleModal()}
|
||||
>
|
||||
{t("addAssociatedRolesText")}
|
||||
</DropdownItem>,
|
||||
<DropdownItem
|
||||
key="delete-role"
|
||||
component="button"
|
||||
onClick={() => toggleDeleteDialog()}
|
||||
>
|
||||
{t("deleteRole")}
|
||||
</DropdownItem>,
|
||||
];
|
||||
const dropdownItems = url.includes("associated-roles")
|
||||
? [
|
||||
<DropdownItem
|
||||
key="delete-all-associated"
|
||||
component="button"
|
||||
onClick={() => toggleDeleteAllAssociatedRolesDialog()}
|
||||
>
|
||||
{t("roles:removeAllAssociatedRoles")}
|
||||
</DropdownItem>,
|
||||
<DropdownItem
|
||||
key="delete-role"
|
||||
component="button"
|
||||
onClick={() => {
|
||||
toggleDeleteDialog();
|
||||
}}
|
||||
>
|
||||
{t("deleteRole")}
|
||||
</DropdownItem>,
|
||||
]
|
||||
: [
|
||||
<DropdownItem
|
||||
key="toggle-modal"
|
||||
data-testid="add-roles"
|
||||
component="button"
|
||||
onClick={() => toggleModal()}
|
||||
>
|
||||
{t("addAssociatedRolesText")}
|
||||
</DropdownItem>,
|
||||
<DropdownItem
|
||||
key="delete-role"
|
||||
component="button"
|
||||
onClick={() => toggleDeleteDialog()}
|
||||
>
|
||||
{t("deleteRole")}
|
||||
</DropdownItem>,
|
||||
];
|
||||
|
||||
const [
|
||||
toggleDeleteAllAssociatedRolesDialog,
|
||||
|
|
Loading…
Reference in a new issue