From 1763ee1a5089fa807544b69caf80e9bc3f96719d Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Thu, 7 Jan 2021 19:34:59 +0100 Subject: [PATCH] added delete client scope functionality (#272) * added delete client scope functionality * use error message from the response --- src/client-scopes/ClientScopesSection.tsx | 20 ++++++++++++++++++-- src/client-scopes/messages.json | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/client-scopes/ClientScopesSection.tsx b/src/client-scopes/ClientScopesSection.tsx index 3cffd374da..0dc07a6cb5 100644 --- a/src/client-scopes/ClientScopesSection.tsx +++ b/src/client-scopes/ClientScopesSection.tsx @@ -1,11 +1,12 @@ import React from "react"; import { useTranslation } from "react-i18next"; import { Link, useHistory, useRouteMatch } from "react-router-dom"; -import { Button, PageSection } from "@patternfly/react-core"; +import { AlertVariant, Button, PageSection } from "@patternfly/react-core"; import ClientScopeRepresentation from "keycloak-admin/lib/defs/clientScopeRepresentation"; import { useAdminClient } from "../context/auth/AdminClient"; import { ViewHeader } from "../components/view-header/ViewHeader"; +import { useAlerts } from "../components/alert/Alerts"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; export const ClientScopesSection = () => { @@ -14,6 +15,7 @@ export const ClientScopesSection = () => { const { url } = useRouteMatch(); const adminClient = useAdminClient(); + const { addAlert } = useAlerts(); const loader = async () => await adminClient.clientScopes.find(); @@ -47,7 +49,21 @@ export const ClientScopesSection = () => { }, { title: t("common:delete"), - onRowClick: () => {}, + onRowClick: async (clientScope) => { + try { + await adminClient.clientScopes.del({ id: clientScope.id! }); + addAlert(t("deletedSuccess"), AlertVariant.success); + return true; + } catch (error) { + addAlert( + t("deleteError", { + error: error.response.data?.errorMessage || error, + }), + AlertVariant.danger + ); + return false; + } + }, }, ]} columns={[ diff --git a/src/client-scopes/messages.json b/src/client-scopes/messages.json index 8759e168d9..ea712c290b 100644 --- a/src/client-scopes/messages.json +++ b/src/client-scopes/messages.json @@ -11,6 +11,8 @@ "type": "Type", "priority": "Priority", "protocol": "Protocol", + "deletedSuccess": "The client scope has been deleted", + "deleteError": "Could not delete client scope: {{error}}", "includeInTokenScope": "Include in token scope", "mappingDetails": "Mapper details", "mappingCreatedSuccess": "Mapping successfully created",