From 0b955984114fc6b7f813c931dde496ccfc2cb9d7 Mon Sep 17 00:00:00 2001 From: Jenny <32821331+jenny-s51@users.noreply.github.com> Date: Fri, 19 Nov 2021 05:55:52 -0500 Subject: [PATCH] delete functionality and do not display current role in modal (#1543) --- src/realm-roles/AssociatedRolesModal.tsx | 20 ++++-- src/realm-roles/RealmRoleTabs.tsx | 83 ++++++++++-------------- 2 files changed, 49 insertions(+), 54 deletions(-) diff --git a/src/realm-roles/AssociatedRolesModal.tsx b/src/realm-roles/AssociatedRolesModal.tsx index 801a551897..875d30bb9a 100644 --- a/src/realm-roles/AssociatedRolesModal.tsx +++ b/src/realm-roles/AssociatedRolesModal.tsx @@ -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, - clientId: client.clientId, - })); + return roles + .map((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 ( toggleDeleteAllAssociatedRolesDialog()} - > - {t("roles:removeAllAssociatedRoles")} - , - { - toggleDeleteDialog(); - }} - > - {t("deleteRole")} - , - ] - : id && realm?.defaultRole && url.includes("associated-roles") - ? [ - toggleDeleteAllAssociatedRolesDialog()} - > - {t("roles:removeAllAssociatedRoles")} - , - ] - : [ - toggleModal()} - > - {t("addAssociatedRolesText")} - , - toggleDeleteDialog()} - > - {t("deleteRole")} - , - ]; + const dropdownItems = url.includes("associated-roles") + ? [ + toggleDeleteAllAssociatedRolesDialog()} + > + {t("roles:removeAllAssociatedRoles")} + , + { + toggleDeleteDialog(); + }} + > + {t("deleteRole")} + , + ] + : [ + toggleModal()} + > + {t("addAssociatedRolesText")} + , + toggleDeleteDialog()} + > + {t("deleteRole")} + , + ]; const [ toggleDeleteAllAssociatedRolesDialog,