From 37bf82bb995926d921c7351106e5ab48a066f518 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 11 May 2022 10:33:23 +0200 Subject: [PATCH] Added delete action to the details screen (#2601) --- .../ldap/mappers/LdapMapperDetails.tsx | 31 +++++++++++++++++++ .../routes/UserFederationLdap.ts | 4 ++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/user-federation/ldap/mappers/LdapMapperDetails.tsx b/src/user-federation/ldap/mappers/LdapMapperDetails.tsx index 1ba2bab170..f0b03ac8e5 100644 --- a/src/user-federation/ldap/mappers/LdapMapperDetails.tsx +++ b/src/user-federation/ldap/mappers/LdapMapperDetails.tsx @@ -3,6 +3,8 @@ import { ActionGroup, AlertVariant, Button, + ButtonVariant, + DropdownItem, Form, FormGroup, PageSection, @@ -28,6 +30,7 @@ import { useRealm } from "../../../context/realm-context/RealmContext"; import { KeycloakSpinner } from "../../../components/keycloak-spinner/KeycloakSpinner"; import { KeycloakTextInput } from "../../../components/keycloak-text-input/KeycloakTextInput"; import { toUserFederationLdap } from "../../routes/UserFederationLdap"; +import { useConfirmDialog } from "../../../components/confirm-dialog/ConfirmDialog"; export default function LdapMapperDetails() { const form = useForm(); @@ -114,6 +117,24 @@ export default function LdapMapperDetails() { } }; + const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ + titleKey: "common:deleteMappingTitle", + messageKey: "common:deleteMappingConfirm", + continueButtonLabel: "common:delete", + continueButtonVariant: ButtonVariant.danger, + onConfirm: async () => { + try { + await adminClient.components.del({ + id: mapping!.id!, + }); + addAlert(t("common:mappingDeletedSuccess"), AlertVariant.success); + history.push(toUserFederationLdap({ id, realm, tab: "mappers" })); + } catch (error) { + addError("common:mappingDeletedError", error); + } + }, + }); + const mapperType = useWatch({ control: form.control, name: "providerId", @@ -127,8 +148,18 @@ export default function LdapMapperDetails() { return ( <> + + {t("common:delete")} + , + ] + } /> diff --git a/src/user-federation/routes/UserFederationLdap.ts b/src/user-federation/routes/UserFederationLdap.ts index b7767c6749..5c3b5d0ebe 100644 --- a/src/user-federation/routes/UserFederationLdap.ts +++ b/src/user-federation/routes/UserFederationLdap.ts @@ -3,10 +3,12 @@ import { lazy } from "react"; import { generatePath } from "react-router-dom"; import type { RouteDef } from "../../route-config"; +type UserFederationLdapTab = "settings" | "mappers"; + export type UserFederationLdapParams = { realm: string; id: string; - tab?: string; + tab?: UserFederationLdapTab; }; export const UserFederationLdapRoute: RouteDef = {