added delete client scope functionality (#272)

* added delete client scope functionality

* use error message from the response
This commit is contained in:
Erik Jan de Wit 2021-01-07 19:34:59 +01:00 committed by GitHub
parent e6fa093925
commit 1763ee1a50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -1,11 +1,12 @@
import React from "react"; import React from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Link, useHistory, useRouteMatch } from "react-router-dom"; 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 ClientScopeRepresentation from "keycloak-admin/lib/defs/clientScopeRepresentation";
import { useAdminClient } from "../context/auth/AdminClient"; import { useAdminClient } from "../context/auth/AdminClient";
import { ViewHeader } from "../components/view-header/ViewHeader"; import { ViewHeader } from "../components/view-header/ViewHeader";
import { useAlerts } from "../components/alert/Alerts";
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
export const ClientScopesSection = () => { export const ClientScopesSection = () => {
@ -14,6 +15,7 @@ export const ClientScopesSection = () => {
const { url } = useRouteMatch(); const { url } = useRouteMatch();
const adminClient = useAdminClient(); const adminClient = useAdminClient();
const { addAlert } = useAlerts();
const loader = async () => await adminClient.clientScopes.find(); const loader = async () => await adminClient.clientScopes.find();
@ -47,7 +49,21 @@ export const ClientScopesSection = () => {
}, },
{ {
title: t("common:delete"), 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={[ columns={[

View file

@ -11,6 +11,8 @@
"type": "Type", "type": "Type",
"priority": "Priority", "priority": "Priority",
"protocol": "Protocol", "protocol": "Protocol",
"deletedSuccess": "The client scope has been deleted",
"deleteError": "Could not delete client scope: {{error}}",
"includeInTokenScope": "Include in token scope", "includeInTokenScope": "Include in token scope",
"mappingDetails": "Mapper details", "mappingDetails": "Mapper details",
"mappingCreatedSuccess": "Mapping successfully created", "mappingCreatedSuccess": "Mapping successfully created",