Added delete action to the details screen (#2601)

This commit is contained in:
Erik Jan de Wit 2022-05-11 10:33:23 +02:00 committed by GitHub
parent ccdd762d6d
commit 37bf82bb99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View file

@ -3,6 +3,8 @@ import {
ActionGroup, ActionGroup,
AlertVariant, AlertVariant,
Button, Button,
ButtonVariant,
DropdownItem,
Form, Form,
FormGroup, FormGroup,
PageSection, PageSection,
@ -28,6 +30,7 @@ import { useRealm } from "../../../context/realm-context/RealmContext";
import { KeycloakSpinner } from "../../../components/keycloak-spinner/KeycloakSpinner"; import { KeycloakSpinner } from "../../../components/keycloak-spinner/KeycloakSpinner";
import { KeycloakTextInput } from "../../../components/keycloak-text-input/KeycloakTextInput"; import { KeycloakTextInput } from "../../../components/keycloak-text-input/KeycloakTextInput";
import { toUserFederationLdap } from "../../routes/UserFederationLdap"; import { toUserFederationLdap } from "../../routes/UserFederationLdap";
import { useConfirmDialog } from "../../../components/confirm-dialog/ConfirmDialog";
export default function LdapMapperDetails() { export default function LdapMapperDetails() {
const form = useForm<ComponentRepresentation>(); const form = useForm<ComponentRepresentation>();
@ -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({ const mapperType = useWatch({
control: form.control, control: form.control,
name: "providerId", name: "providerId",
@ -127,8 +148,18 @@ export default function LdapMapperDetails() {
return ( return (
<> <>
<DeleteConfirm />
<ViewHeader <ViewHeader
titleKey={mapping ? mapping.name! : t("common:createNewMapper")} titleKey={mapping ? mapping.name! : t("common:createNewMapper")}
dropdownItems={
isNew
? undefined
: [
<DropdownItem key="delete" onClick={toggleDeleteDialog}>
{t("common:delete")}
</DropdownItem>,
]
}
/> />
<PageSection variant="light" isFilled> <PageSection variant="light" isFilled>
<FormAccess role="manage-realm" isHorizontal> <FormAccess role="manage-realm" isHorizontal>

View file

@ -3,10 +3,12 @@ import { lazy } from "react";
import { generatePath } from "react-router-dom"; import { generatePath } from "react-router-dom";
import type { RouteDef } from "../../route-config"; import type { RouteDef } from "../../route-config";
type UserFederationLdapTab = "settings" | "mappers";
export type UserFederationLdapParams = { export type UserFederationLdapParams = {
realm: string; realm: string;
id: string; id: string;
tab?: string; tab?: UserFederationLdapTab;
}; };
export const UserFederationLdapRoute: RouteDef = { export const UserFederationLdapRoute: RouteDef = {