From 97641e51cbc3ae24c28c4df6afb774d67fb9533d Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Thu, 16 Dec 2021 17:24:22 +0100 Subject: [PATCH] changed to use Dynamic components instead (#1662) * changed to use Dynamic components instead * fixed merge errors * fixed PR review issues --- .../manage/providers/ProviderPage.ts | 62 +- .../ldap/mappers/LdapMapperDetails.tsx | 201 ++---- .../mappers/LdapMapperFullNameAttribute.tsx | 95 --- .../mappers/LdapMapperHardcodedAttribute.tsx | 60 -- .../LdapMapperHardcodedLdapAttribute.tsx | 60 -- .../mappers/LdapMapperHardcodedLdapGroup.tsx | 43 -- .../mappers/LdapMapperHardcodedLdapRole.tsx | 96 --- .../mappers/LdapMapperMsadUserAccount.tsx | 45 -- .../ldap/mappers/LdapMapperRoleGroup.tsx | 644 ------------------ .../ldap/mappers/LdapMapperUserAttribute.tsx | 219 ------ 10 files changed, 81 insertions(+), 1444 deletions(-) delete mode 100644 src/user-federation/ldap/mappers/LdapMapperFullNameAttribute.tsx delete mode 100644 src/user-federation/ldap/mappers/LdapMapperHardcodedAttribute.tsx delete mode 100644 src/user-federation/ldap/mappers/LdapMapperHardcodedLdapAttribute.tsx delete mode 100644 src/user-federation/ldap/mappers/LdapMapperHardcodedLdapGroup.tsx delete mode 100644 src/user-federation/ldap/mappers/LdapMapperHardcodedLdapRole.tsx delete mode 100644 src/user-federation/ldap/mappers/LdapMapperMsadUserAccount.tsx delete mode 100644 src/user-federation/ldap/mappers/LdapMapperRoleGroup.tsx delete mode 100644 src/user-federation/ldap/mappers/LdapMapperUserAttribute.tsx diff --git a/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts b/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts index 3ea79f6024..82508f61fe 100644 --- a/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts +++ b/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts @@ -37,16 +37,15 @@ export default class ProviderPage { private cachePolicyList = "#kc-cache-policy + ul"; // Mapper required input values - private userModelAttInput = "data-testid=mapper-userModelAttribute-fld"; - private ldapAttInput = "data-testid=mapper-ldapAttribute-fld"; - private userModelAttNameInput = - "data-testid=mapper-userModelAttributeName-fld"; - private attValueInput = "data-testid=mapper-attributeValue-fld"; - private ldapFullNameAttInput = "data-testid=mapper-fullNameAttribute-fld"; - private ldapAttNameInput = "data-testid=mapper-ldapAttributeName-fld"; - private ldapAttValueInput = "data-testid=mapper-ldapAttributeValue-fld"; - private groupInput = "data-testid=mapper-group-fld"; - private ldapDnInput = "data-testid=ldap-dn"; + private userModelAttInput = "user.model.attribute"; + private ldapAttInput = "ldap.attribute"; + private userModelAttNameInput = "user.model.attribute"; + private attValueInput = "attribute.value"; + private ldapFullNameAttInput = "ldap.full.name.attribute"; + private ldapAttNameInput = "ldap.attribute.name"; + private ldapAttValueInput = "ldap.attribute.value"; + private groupInput = "group"; + private ldapDnInput = "groups.dn"; // mapper types private msadUserAcctMapper = "msad-user-account-control-mapper"; @@ -247,29 +246,29 @@ export default class ProviderPage { break; case this.userAttLdapMapper: case this.certLdapMapper: - cy.get(`[${this.userModelAttInput}]`).type(userModelAttValue); - cy.get(`[${this.ldapAttInput}]`).type(ldapAttValue); + cy.findByTestId(this.userModelAttInput).type(userModelAttValue); + cy.findByTestId(this.ldapAttInput).type(ldapAttValue); break; case this.hcAttMapper: - cy.get(`[${this.userModelAttNameInput}]`).type(userModelAttValue); - cy.get(`[${this.attValueInput}]`).type(ldapAttValue); + cy.findByTestId(this.userModelAttNameInput).type(userModelAttValue); + cy.findByTestId(this.attValueInput).type(ldapAttValue); break; case this.fullNameLdapMapper: - cy.get(`[${this.ldapFullNameAttInput}]`).type(ldapAttValue); + cy.findByTestId(this.ldapFullNameAttInput).type(ldapAttValue); break; case this.hcLdapAttMapper: - cy.get(`[${this.ldapAttNameInput}]`).type(userModelAttValue); - cy.get(`[${this.ldapAttValueInput}]`).type(ldapAttValue); + cy.findByTestId(this.ldapAttNameInput).type(userModelAttValue); + cy.findByTestId(this.ldapAttValueInput).type(ldapAttValue); break; case this.hcLdapGroupMapper: - cy.get(`[${this.groupInput}]`).type(this.groupName); + cy.findByTestId(this.groupInput).type(this.groupName); break; case this.groupLdapMapper: - cy.get(`[${this.ldapDnInput}]`).type(ldapDnValue); + cy.findByTestId(this.ldapDnInput).type(ldapDnValue); break; case this.roleLdapMapper: - cy.get(`[${this.ldapDnInput}]`).type(ldapDnValue); + cy.findByTestId(this.ldapDnInput).type(ldapDnValue); // cy select clientID dropdown and choose clientName (var) cy.get(this.clientIdSelect).click(); cy.get("button").contains(this.clientName).click({ force: true }); @@ -303,26 +302,21 @@ export default class ProviderPage { break; case this.userAttLdapMapper: case this.certLdapMapper: - cy.get(`[${this.userModelAttInput}]`).clear(); - cy.get(`[${this.userModelAttInput}]`).type(userModelAttValue); - cy.get(`[${this.ldapAttInput}]`).clear(); - cy.get(`[${this.ldapAttInput}]`).type(ldapAttValue); + cy.findByTestId(this.userModelAttInput).clear().type(userModelAttValue); + cy.findByTestId(this.ldapAttInput).clear().type(ldapAttValue); break; case this.hcAttMapper: - cy.get(`[${this.userModelAttNameInput}]`).clear(); - cy.get(`[${this.userModelAttNameInput}]`).type(userModelAttValue); - cy.get(`[${this.attValueInput}]`).clear(); - cy.get(`[${this.attValueInput}]`).type(ldapAttValue); + cy.findByTestId(this.userModelAttNameInput) + .clear() + .type(userModelAttValue); + cy.findByTestId(this.attValueInput).clear().type(ldapAttValue); break; case this.fullNameLdapMapper: - cy.get(`[${this.ldapFullNameAttInput}]`).clear(); - cy.get(`[${this.ldapFullNameAttInput}]`).type(ldapAttValue); + cy.findByTestId(this.ldapFullNameAttInput).clear().type(ldapAttValue); break; case this.hcLdapAttMapper: - cy.get(`[${this.ldapAttNameInput}]`).clear(); - cy.get(`[${this.ldapAttNameInput}]`).type(userModelAttValue); - cy.get(`[${this.ldapAttValueInput}]`).clear; - cy.get(`[${this.ldapAttValueInput}]`).type(ldapAttValue); + cy.findByTestId(this.ldapAttNameInput).clear().type(userModelAttValue); + cy.findByTestId(this.ldapAttValueInput).clear().type(ldapAttValue); break; default: console.log("Invalid mapper name."); diff --git a/src/user-federation/ldap/mappers/LdapMapperDetails.tsx b/src/user-federation/ldap/mappers/LdapMapperDetails.tsx index d2972c30fc..3cc98fb82e 100644 --- a/src/user-federation/ldap/mappers/LdapMapperDetails.tsx +++ b/src/user-federation/ldap/mappers/LdapMapperDetails.tsx @@ -17,27 +17,22 @@ import type ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/de import { useAdminClient, useFetch } from "../../../context/auth/AdminClient"; import { ViewHeader } from "../../../components/view-header/ViewHeader"; import { useHistory, useParams } from "react-router-dom"; -import { Controller, useForm, useWatch } from "react-hook-form"; +import { Controller, FormProvider, useForm, useWatch } from "react-hook-form"; import { useAlerts } from "../../../components/alert/Alerts"; import { useTranslation } from "react-i18next"; import { HelpItem } from "../../../components/help-enabler/HelpItem"; import { FormAccess } from "../../../components/form-access/FormAccess"; -import { LdapMapperUserAttribute } from "./LdapMapperUserAttribute"; -import { LdapMapperMsadUserAccount } from "./LdapMapperMsadUserAccount"; -import { LdapMapperFullNameAttribute } from "./LdapMapperFullNameAttribute"; - -import { LdapMapperHardcodedLdapRole } from "./LdapMapperHardcodedLdapRole"; -import { LdapMapperHardcodedLdapGroup } from "./LdapMapperHardcodedLdapGroup"; -import { LdapMapperHardcodedLdapAttribute } from "./LdapMapperHardcodedLdapAttribute"; -import { LdapMapperHardcodedAttribute } from "./LdapMapperHardcodedAttribute"; - -import { LdapMapperRoleGroup } from "./LdapMapperRoleGroup"; +import type ComponentTypeRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentTypeRepresentation"; +import { DynamicComponents } from "../../../components/dynamic/DynamicComponents"; import { useRealm } from "../../../context/realm-context/RealmContext"; +import { KeycloakSpinner } from "../../../components/keycloak-spinner/KeycloakSpinner"; +import { toUserFederationLdap } from "../../routes/UserFederationLdap"; export default function LdapMapperDetails() { const form = useForm(); const [mapping, setMapping] = useState(); + const [components, setComponents] = useState(); const adminClient = useAdminClient(); const { id, mapperId } = useParams<{ id: string; mapperId: string }>(); @@ -50,21 +45,25 @@ export default function LdapMapperDetails() { useFetch( async () => { + const components = await adminClient.components.listSubComponents({ + id, + type: "org.keycloak.storage.ldap.mappers.LDAPStorageMapper", + }); if (mapperId && mapperId !== "new") { const fetchedMapper = await adminClient.components.findOne({ id: mapperId, }); - if (!fetchedMapper) { - throw new Error(t("common:notFound")); - } - return fetchedMapper; + return { components, fetchedMapper }; } + return { components }; }, - (fetchedMapper) => { + ({ components, fetchedMapper }) => { setMapping(fetchedMapper); - if (fetchedMapper) { - setupForm(fetchedMapper); - } + setComponents(components); + if (mapperId !== "new" && !fetchedMapper) + throw new Error(t("common:notFound")); + + if (fetchedMapper) setupForm(fetchedMapper); }, [] ); @@ -74,18 +73,27 @@ export default function LdapMapperDetails() { }; const save = async (mapper: ComponentRepresentation) => { - const map = convertFormValuesToObject(mapper); + const component: ComponentRepresentation = + convertFormValuesToObject(mapper); + const map = { + ...component, + config: Object.entries(component.config || {}).reduce( + (result, [key, value]) => { + result[key] = Array.isArray(value) ? value : [value]; + return result; + }, + {} as Record + ), + }; try { - if (mapperId) { - if (mapperId === "new") { - await adminClient.components.create(map); - history.push( - `/${realm}/user-federation/ldap/${mapper!.parentId}/mappers` - ); - } else { - await adminClient.components.update({ id: mapperId }, map); - } + if (mapperId === "new") { + await adminClient.components.create(map); + history.push( + toUserFederationLdap({ realm, id: mapper.parentId!, tab: "mappers" }) + ); + } else { + await adminClient.components.update({ id: mapperId }, map); } setupForm(map as ComponentRepresentation); addAlert( @@ -113,6 +121,10 @@ export default function LdapMapperDetails() { const isNew = mapperId === "new"; + if (!components) { + return ; + } + return ( <> - - - - - - - - - - - + {components.map((c) => ( + + ))} )} > )} - {/* When loading existing mappers, load forms based on providerId aka mapper type */} - {mapping - ? (mapping.providerId! === "certificate-ldap-mapper" || - mapping.providerId! === "user-attribute-ldap-mapper") && ( - - ) - : ""} - {mapping - ? mapping.providerId! === "msad-user-account-control-mapper" && ( - - ) - : ""} - {/* msad-lds-user-account-control-mapper does not need a component - because it is just id, name, and mapper type*/} - {mapping - ? mapping.providerId! === "full-name-ldap-mapper" && ( - - ) - : ""} - {mapping - ? mapping.providerId! === "hardcoded-ldap-role-mapper" && ( - - ) - : ""} - {mapping - ? mapping.providerId! === "hardcoded-ldap-group-mapper" && ( - - ) - : ""} - {mapping - ? mapping.providerId! === "hardcoded-ldap-attribute-mapper" && ( - - ) - : ""} - {mapping - ? mapping.providerId! === "hardcoded-attribute-mapper" && ( - - ) - : ""} - {mapping - ? (mapping.providerId! === "role-ldap-mapper" || - mapping.providerId! === "group-ldap-mapper") && ( - - ) - : ""} - {/* When creating new mappers, load forms based on dropdown selection */} - {isNew && mapperType - ? mapperType === "certificate-ldap-mapper" && ( - - ) - : ""} - {isNew && mapperType - ? mapperType === "user-attribute-ldap-mapper" && ( - - ) - : ""} - {isNew && mapperType - ? mapperType === "msad-user-account-control-mapper" && ( - - ) - : ""} - {isNew && mapperType - ? mapperType === "full-name-ldap-mapper" && ( - - ) - : ""} - {isNew && mapperType - ? mapperType === "hardcoded-ldap-role-mapper" && ( - - ) - : ""} - {isNew && mapperType - ? mapperType === "hardcoded-ldap-group-mapper" && ( - - ) - : ""} - {isNew && mapperType - ? mapperType === "hardcoded-ldap-attribute-mapper" && ( - - ) - : ""} - {isNew && mapperType - ? mapperType === "hardcoded-attribute-mapper" && ( - - ) - : ""} - {isNew && mapperType - ? mapperType === "role-ldap-mapper" && ( - - ) - : ""} - {isNew && mapperType - ? mapperType === "group-ldap-mapper" && ( - - ) - : ""} + + {!!mapperType && ( + c.id === mapperType)?.properties! + } + /> + )} +
save(form.getValues()))}> diff --git a/src/user-federation/ldap/mappers/LdapMapperFullNameAttribute.tsx b/src/user-federation/ldap/mappers/LdapMapperFullNameAttribute.tsx deleted file mode 100644 index 5a71c432cc..0000000000 --- a/src/user-federation/ldap/mappers/LdapMapperFullNameAttribute.tsx +++ /dev/null @@ -1,95 +0,0 @@ -import { FormGroup, Switch, TextInput } from "@patternfly/react-core"; -import React from "react"; -import { HelpItem } from "../../../components/help-enabler/HelpItem"; -import { Controller, UseFormMethods } from "react-hook-form"; -import { useTranslation } from "react-i18next"; - -export type LdapMapperFullNameAttributeProps = { - form: UseFormMethods; -}; - -export const LdapMapperFullNameAttribute = ({ - form, -}: LdapMapperFullNameAttributeProps) => { - const { t } = useTranslation("user-federation"); - - return ( - <> - - } - fieldId="kc-full-name-attribute" - isRequired - > - - - - } - fieldId="kc-read-only" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - - } - fieldId="kc-read-only" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - - ); -}; diff --git a/src/user-federation/ldap/mappers/LdapMapperHardcodedAttribute.tsx b/src/user-federation/ldap/mappers/LdapMapperHardcodedAttribute.tsx deleted file mode 100644 index 2ab2f74330..0000000000 --- a/src/user-federation/ldap/mappers/LdapMapperHardcodedAttribute.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import { FormGroup, TextInput } from "@patternfly/react-core"; -import React from "react"; -import { HelpItem } from "../../../components/help-enabler/HelpItem"; -import type { UseFormMethods } from "react-hook-form"; -import { useTranslation } from "react-i18next"; - -export type LdapMapperHardcodedAttributeProps = { - form: UseFormMethods; -}; - -export const LdapMapperHardcodedAttribute = ({ - form, -}: LdapMapperHardcodedAttributeProps) => { - const { t } = useTranslation("user-federation"); - - return ( - <> - - } - fieldId="kc-user-model-attribute" - isRequired - > - - - - } - fieldId="kc-attribute-value" - isRequired - > - - - - ); -}; diff --git a/src/user-federation/ldap/mappers/LdapMapperHardcodedLdapAttribute.tsx b/src/user-federation/ldap/mappers/LdapMapperHardcodedLdapAttribute.tsx deleted file mode 100644 index 46b5148f46..0000000000 --- a/src/user-federation/ldap/mappers/LdapMapperHardcodedLdapAttribute.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import { FormGroup, TextInput } from "@patternfly/react-core"; -import React from "react"; -import { HelpItem } from "../../../components/help-enabler/HelpItem"; -import type { UseFormMethods } from "react-hook-form"; -import { useTranslation } from "react-i18next"; - -export type LdapMapperHardcodedLdapAttributeProps = { - form: UseFormMethods; -}; - -export const LdapMapperHardcodedLdapAttribute = ({ - form, -}: LdapMapperHardcodedLdapAttributeProps) => { - const { t } = useTranslation("user-federation"); - - return ( - <> - - } - fieldId="kc-ldap-attribute-name" - isRequired - > - - - - } - fieldId="kc-ldap-attribute-value" - isRequired - > - - - - ); -}; diff --git a/src/user-federation/ldap/mappers/LdapMapperHardcodedLdapGroup.tsx b/src/user-federation/ldap/mappers/LdapMapperHardcodedLdapGroup.tsx deleted file mode 100644 index 6a28d263d1..0000000000 --- a/src/user-federation/ldap/mappers/LdapMapperHardcodedLdapGroup.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { FormGroup, TextInput, ValidatedOptions } from "@patternfly/react-core"; -import React from "react"; -import { HelpItem } from "../../../components/help-enabler/HelpItem"; -import type { UseFormMethods } from "react-hook-form"; -import { useTranslation } from "react-i18next"; - -export type LdapMapperHardcodedLdapGroupProps = { - form: UseFormMethods; -}; - -export const LdapMapperHardcodedLdapGroup = ({ - form, -}: LdapMapperHardcodedLdapGroupProps) => { - const { t } = useTranslation("user-federation"); - - return ( - - } - fieldId="kc-group" - isRequired - > - - - ); -}; diff --git a/src/user-federation/ldap/mappers/LdapMapperHardcodedLdapRole.tsx b/src/user-federation/ldap/mappers/LdapMapperHardcodedLdapRole.tsx deleted file mode 100644 index 6976c212c3..0000000000 --- a/src/user-federation/ldap/mappers/LdapMapperHardcodedLdapRole.tsx +++ /dev/null @@ -1,96 +0,0 @@ -import { - Button, - FormGroup, - TextInput, - ValidatedOptions, -} from "@patternfly/react-core"; -import React, { useState } from "react"; -import { HelpItem } from "../../../components/help-enabler/HelpItem"; -import type { UseFormMethods } from "react-hook-form"; -import { useTranslation } from "react-i18next"; - -import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation"; -import type RoleRepresentation from "@keycloak/keycloak-admin-client/lib/defs/roleRepresentation"; -import { AddRoleMappingModal } from "../../../components/role-mapping/AddRoleMappingModal"; -import "../../user-federation.css"; - -export type LdapMapperHardcodedLdapRoleProps = { - form: UseFormMethods; -}; - -export type CompositeRole = RoleRepresentation & { - parent: RoleRepresentation; -}; - -export type Row = { - client?: ClientRepresentation; - role: CompositeRole | RoleRepresentation; -}; - -export const LdapMapperHardcodedLdapRole = ({ - form, -}: LdapMapperHardcodedLdapRoleProps) => { - const { t } = useTranslation("user-federation"); - const [showAssign, setShowAssign] = useState(false); - - const selectRoles = async (rows: Row[]) => { - if (rows[0].client) { - form.setValue( - "config.role[0]", - `${rows[0].client.clientId}.${rows[0].role.name}` - ); - } else { - form.setValue("config.role[0]", `${rows[0].role.name}`); - } - }; - - return ( - <> - {showAssign && ( - setShowAssign(false)} - /> - )} - - - } - fieldId="kc-role" - isRequired - > -
- - -
-
- - ); -}; diff --git a/src/user-federation/ldap/mappers/LdapMapperMsadUserAccount.tsx b/src/user-federation/ldap/mappers/LdapMapperMsadUserAccount.tsx deleted file mode 100644 index 1bb3bce59b..0000000000 --- a/src/user-federation/ldap/mappers/LdapMapperMsadUserAccount.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { FormGroup, Switch } from "@patternfly/react-core"; -import React from "react"; -import { HelpItem } from "../../../components/help-enabler/HelpItem"; -import { Controller, UseFormMethods } from "react-hook-form"; -import { useTranslation } from "react-i18next"; - -export type LdapMapperMsadUserAccountProps = { - form: UseFormMethods; -}; - -export const LdapMapperMsadUserAccount = ({ - form, -}: LdapMapperMsadUserAccountProps) => { - const { t } = useTranslation("user-federation"); - - return ( - - } - fieldId="kc-der-formatted" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - ); -}; diff --git a/src/user-federation/ldap/mappers/LdapMapperRoleGroup.tsx b/src/user-federation/ldap/mappers/LdapMapperRoleGroup.tsx deleted file mode 100644 index 4f9f8722ac..0000000000 --- a/src/user-federation/ldap/mappers/LdapMapperRoleGroup.tsx +++ /dev/null @@ -1,644 +0,0 @@ -import { - FormGroup, - Select, - SelectOption, - SelectVariant, - Switch, - TextInput, - ValidatedOptions, -} from "@patternfly/react-core"; -import React, { useState } from "react"; -import { useParams } from "react-router-dom"; -import type { UserFederationLdapMapperParams } from "../../routes/UserFederationLdapMapper"; -import { HelpItem } from "../../../components/help-enabler/HelpItem"; -import { Controller, UseFormMethods } from "react-hook-form"; -import { useTranslation } from "react-i18next"; -import { useAdminClient, useFetch } from "../../../context/auth/AdminClient"; -import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation"; - -export type LdapMapperRoleGroupProps = { - form: UseFormMethods; - type: string; -}; - -export const LdapMapperRoleGroup = ({ - form, - type, -}: LdapMapperRoleGroupProps) => { - const { t } = useTranslation("user-federation"); - const adminClient = useAdminClient(); - const [isMbAttTypeDropdownOpen, setIsMbAttTypeDropdownOpen] = useState(false); - const [isModeDropdownOpen, setIsModeDropdownOpen] = useState(false); - const [isRetrieveStratDropdownOpen, setIsRetrieveStratDropdownOpen] = - useState(false); - const [isClientIdDropdownOpen, setIsClientIdDropdownOpen] = useState(false); - const [vendorType, setVendorType] = useState(); - const [clients, setClients] = useState([]); - const { id, mapperId } = useParams(); - - let isRole = true; - const groupMapper = "group-ldap-mapper"; - - if (type === groupMapper) { - isRole = false; - } - - useFetch( - async () => { - const clients = await adminClient.clients.find(); - if (clients) { - setClients(clients); - } - return clients; - }, - (clients) => setClients(clients), - [] - ); - - useFetch( - async () => { - return await adminClient.components.findOne({ id }); - }, - (fetchedComponent) => { - if (fetchedComponent) { - const vendor = fetchedComponent.config?.vendor[0]; - setVendorType(vendor); - if (mapperId === "new" && vendor === "ad") { - form.setValue( - isRole - ? "config.role.object.classes[0]" - : "config.group.object.classes[0]", - "group" - ); - form.setValue("config.membership.user.ldap.attribute[0]", "cn"); - } - } else if (id) { - throw new Error(t("common:notFound")); - } - }, - [] - ); - - return ( - <> - - } - fieldId="kc-ldap-dn" - isRequired - > - - - - } - fieldId="kc-name-attribute" - isRequired - > - - - - } - fieldId="kc-object-classes" - isRequired - > - - - {!isRole && ( - <> - - } - fieldId="kc-preserve-inheritance" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - - } - fieldId="kc-ignore-missing" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - - )} - - } - fieldId="kc-membership-ldap-attribute" - isRequired - > - - - - } - fieldId="kc-membership-attribute-type" - > - ( - - )} - > - - - } - fieldId="kc-membership-user-ldap-attribute" - isRequired - > - - - - } - fieldId="kc-ldap-filter" - > - - - - } - fieldId="kc-mode" - > - ( - - )} - > - - {isRole ? ( - - } - fieldId="kc-user-retrieve-strategy" - > - ( - - )} - > - - ) : ( - - } - fieldId="kc-user-retrieve-strategy" - > - ( - - )} - > - - )} - - } - fieldId="kc-member-of-attribute" - isRequired - > - - - {isRole && ( - <> - - } - fieldId="kc-use-realm-roles" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - - } - fieldId="kc-client-id" - > - ( - - )} - > - - - )} - {!isRole && ( - <> - - } - fieldId="kc-mapped-attributes" - > - - - - } - fieldId="kc-drop-nonexisting" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - - } - fieldId="kc-path" - isRequired - > - - - - )} - - ); -}; diff --git a/src/user-federation/ldap/mappers/LdapMapperUserAttribute.tsx b/src/user-federation/ldap/mappers/LdapMapperUserAttribute.tsx deleted file mode 100644 index b2e871a172..0000000000 --- a/src/user-federation/ldap/mappers/LdapMapperUserAttribute.tsx +++ /dev/null @@ -1,219 +0,0 @@ -import { FormGroup, Switch, TextInput } from "@patternfly/react-core"; -import React from "react"; -import { HelpItem } from "../../../components/help-enabler/HelpItem"; -import { Controller, UseFormMethods } from "react-hook-form"; -import { useTranslation } from "react-i18next"; - -export type LdapMapperUserAttributeProps = { - form: UseFormMethods; - mapperType: string | undefined; -}; - -export const LdapMapperUserAttribute = ({ - form, - mapperType, -}: LdapMapperUserAttributeProps) => { - const { t } = useTranslation("user-federation"); - - return ( - <> - - } - fieldId="kc-user-model-attribute" - isRequired - > - - - - } - fieldId="kc-ldap-attribute" - isRequired - > - - - - } - fieldId="kc-read-only" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - - } - fieldId="kc-always-read-value" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - - } - fieldId="kc-is-mandatory" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - - } - fieldId="kc-attribute-default-value" - > - - - - } - fieldId="kc-is-binary" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - {mapperType === "certificate-ldap-mapper" ? ( - - } - fieldId="kc-der-formatted" - hasNoPaddingTop - > - ( - onChange([`${value}`])} - isChecked={value[0] === "true"} - label={t("common:on")} - labelOff={t("common:off")} - /> - )} - > - - ) : null} - - ); -};