keycloak-scim/src/user-federation/ldap/LdapSettingsSearching.tsx

380 lines
12 KiB
TypeScript
Raw Normal View History

import {
FormGroup,
Select,
SelectOption,
2020-11-25 14:50:40 +00:00
SelectVariant,
Switch,
TextInput,
} from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import React, { useState } from "react";
import { HelpItem } from "../../components/help-enabler/HelpItem";
import { UseFormMethods, Controller } from "react-hook-form";
import { FormAccess } from "../../components/form-access/FormAccess";
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
export type LdapSettingsSearchingProps = {
form: UseFormMethods;
showSectionHeading?: boolean;
showSectionDescription?: boolean;
};
export const LdapSettingsSearching = ({
form,
showSectionHeading = false,
showSectionDescription = false,
}: LdapSettingsSearchingProps) => {
const { t } = useTranslation("user-federation");
2021-12-14 14:56:36 +00:00
const { t: helpText } = useTranslation("user-federation-help");
const [isSearchScopeDropdownOpen, setIsSearchScopeDropdownOpen] =
useState(false);
const [isEditModeDropdownOpen, setIsEditModeDropdownOpen] = useState(false);
2020-11-25 14:50:40 +00:00
return (
<>
{showSectionHeading && (
<WizardSectionHeader
title={t("ldapSearchingAndUpdatingSettings")}
description={helpText("ldapSearchingAndUpdatingSettingsDescription")}
showDescription={showSectionDescription}
/>
)}
2020-11-25 16:17:50 +00:00
<FormAccess role="manage-realm" isHorizontal>
<FormGroup
label={t("editMode")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:editModeLdapHelp"
fieldLabelId="user-federation:editMode"
/>
}
fieldId="kc-edit-mode"
isRequired
validated={form.errors.config?.editMode?.[0] ? "error" : "default"}
helperTextInvalid={form.errors.config?.editMode?.[0].message}
>
2020-11-25 14:50:40 +00:00
<Controller
name="config.editMode[0]"
2020-11-25 14:50:40 +00:00
defaultValue=""
control={form.control}
rules={{
required: { value: true, message: t("validateEditMode") },
}}
2020-11-25 14:50:40 +00:00
render={({ onChange, value }) => (
<Select
toggleId="kc-edit-mode"
required
onToggle={() =>
setIsEditModeDropdownOpen(!isEditModeDropdownOpen)
}
isOpen={isEditModeDropdownOpen}
onSelect={(_, value) => {
onChange(value.toString());
2020-11-25 14:50:40 +00:00
setIsEditModeDropdownOpen(false);
}}
selections={value}
variant={SelectVariant.single}
validated={
form.errors.config?.editMode?.[0] ? "error" : "default"
}
2020-11-25 14:50:40 +00:00
>
<SelectOption value="" isPlaceholder />
<SelectOption value="READ_ONLY" />
<SelectOption value="WRITABLE" />
<SelectOption value="UNSYNCED" />
2020-11-25 14:50:40 +00:00
</Select>
)}
/>
</FormGroup>
<FormGroup
label={t("usersDN")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:usersDNHelp"
fieldLabelId="user-federation:usersDn"
/>
}
fieldId="kc-console-users-dn"
isRequired
validated={form.errors.config?.usersDn?.[0] ? "error" : "default"}
helperTextInvalid={form.errors.config?.usersDn?.[0].message}
>
<TextInput
isRequired
type="text"
defaultValue=""
id="kc-console-users-dn"
2021-02-23 20:49:57 +00:00
data-testid="ldap-users-dn"
name="config.usersDn[0]"
ref={form.register({
required: {
value: true,
message: `${t("validateUsersDn")}`,
},
})}
validated={form.errors.config?.usersDn?.[0] ? "error" : "default"}
/>
</FormGroup>
<FormGroup
label={t("usernameLdapAttribute")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:usernameLdapAttributeHelp"
fieldLabelId="user-federation:usernameLdapAttribute"
/>
}
fieldId="kc-username-ldap-attribute"
isRequired
validated={
form.errors.config?.usernameLDAPAttribute?.[0] ? "error" : "default"
}
helperTextInvalid={
form.errors.config?.usernameLDAPAttribute?.[0].message
}
>
<TextInput
isRequired
type="text"
defaultValue="cn"
id="kc-username-ldap-attribute"
2021-02-23 20:49:57 +00:00
data-testid="ldap-username-attribute"
name="config.usernameLDAPAttribute[0]"
ref={form.register({
required: {
value: true,
message: `${t("validateUsernameLDAPAttribute")}`,
},
})}
validated={
form.errors.config?.usernameLDAPAttribute?.[0]
? "error"
: "default"
}
/>
</FormGroup>
<FormGroup
label={t("rdnLdapAttribute")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:rdnLdapAttributeHelp"
fieldLabelId="user-federation:rdnLdapAttribute"
/>
}
fieldId="kc-rdn-ldap-attribute"
isRequired
validated={
form.errors.config?.rdnLDAPAttribute?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.rdnLDAPAttribute?.[0].message}
>
<TextInput
isRequired
type="text"
defaultValue="cn"
id="kc-rdn-ldap-attribute"
2021-02-23 20:49:57 +00:00
data-testid="ldap-rdn-attribute"
name="config.rdnLDAPAttribute[0]"
ref={form.register({
required: {
value: true,
message: `${t("validateRdnLdapAttribute")}`,
},
})}
validated={
form.errors.config?.rdnLDAPAttribute?.[0] ? "error" : "default"
}
/>
</FormGroup>
<FormGroup
label={t("uuidLdapAttribute")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:uuidLdapAttributeHelp"
fieldLabelId="user-federation:uuidLdapAttribute"
/>
}
fieldId="kc-uuid-ldap-attribute"
isRequired
validated={
form.errors.config?.uuidLDAPAttribute?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.uuidLDAPAttribute?.[0].message}
>
<TextInput
isRequired
type="text"
defaultValue="objectGUID"
id="kc-uuid-ldap-attribute"
2021-02-23 20:49:57 +00:00
data-testid="ldap-uuid-attribute"
name="config.uuidLDAPAttribute[0]"
ref={form.register({
required: {
value: true,
message: `${t("validateUuidLDAPAttribute")}`,
},
})}
validated={
form.errors.config?.uuidLDAPAttribute?.[0] ? "error" : "default"
}
/>
</FormGroup>
<FormGroup
label={t("userObjectClasses")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:userObjectClassesHelp"
fieldLabelId="user-federation:userObjectClasses"
/>
}
fieldId="kc-user-object-classes"
isRequired
validated={
form.errors.config?.userObjectClasses?.[0] ? "error" : "default"
}
helperTextInvalid={form.errors.config?.userObjectClasses?.[0].message}
>
<TextInput
isRequired
type="text"
defaultValue="person, organizationalPerson, user"
id="kc-user-object-classes"
2021-02-23 20:49:57 +00:00
data-testid="ldap-user-object-classes"
name="config.userObjectClasses[0]"
ref={form.register({
required: {
value: true,
message: `${t("validateUserObjectClasses")}`,
},
})}
validated={
form.errors.config?.userObjectClasses?.[0] ? "error" : "default"
}
/>
</FormGroup>
<FormGroup
label={t("userLdapFilter")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:userLdapFilterHelp"
fieldLabelId="user-federation:userLdapFilter"
/>
}
fieldId="kc-user-ldap-filter"
validated={
form.errors.config?.customUserSearchFilter?.[0]
? "error"
: "default"
}
helperTextInvalid={
form.errors.config?.customUserSearchFilter?.[0].message
}
>
<TextInput
type="text"
id="kc-user-ldap-filter"
name="config.customUserSearchFilter[0]"
2021-02-23 20:49:57 +00:00
ref={form.register({
pattern: {
value: /(\(.*\))$/,
2021-02-23 20:49:57 +00:00
message: `${t("validateCustomUserSearchFilter")}`,
},
})}
validated={
form.errors.config?.customUserSearchFilter?.[0]
? "error"
: "default"
}
/>
</FormGroup>
<FormGroup
label={t("searchScope")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:searchScopeHelp"
fieldLabelId="user-federation:searchScope"
/>
}
fieldId="kc-search-scope"
>
2020-11-25 14:50:40 +00:00
<Controller
name="config.searchScope[0]"
2020-11-25 14:50:40 +00:00
defaultValue=""
control={form.control}
2020-11-25 14:50:40 +00:00
render={({ onChange, value }) => (
<Select
toggleId="kc-search-scope"
required
onToggle={() =>
setIsSearchScopeDropdownOpen(!isSearchScopeDropdownOpen)
}
isOpen={isSearchScopeDropdownOpen}
onSelect={(_, value) => {
onChange(value as string);
setIsSearchScopeDropdownOpen(false);
}}
selections={value}
variant={SelectVariant.single}
>
<SelectOption key={0} value="1" isPlaceholder>
{t("oneLevel")}
</SelectOption>
<SelectOption key={1} value="2">
{t("subtree")}
</SelectOption>
2020-11-25 14:50:40 +00:00
</Select>
)}
></Controller>
</FormGroup>
<FormGroup
label={t("readTimeout")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:readTimeoutHelp"
fieldLabelId="user-federation:readTimeout"
/>
}
fieldId="kc-read-timeout"
>
<TextInput
type="number"
2021-03-02 15:37:51 +00:00
min={0}
id="kc-read-timeout"
name="config.readTimeout[0]"
ref={form.register}
/>
</FormGroup>
<FormGroup
label={t("pagination")}
labelIcon={
<HelpItem
2021-12-14 14:56:36 +00:00
helpText="user-federation-help:paginationHelp"
fieldLabelId="user-federation:pagination"
/>
}
fieldId="kc-console-pagination"
hasNoPaddingTop
>
2020-11-25 14:50:40 +00:00
<Controller
name="config.pagination"
2021-02-19 23:13:07 +00:00
defaultValue={["false"]}
control={form.control}
2020-11-25 14:50:40 +00:00
render={({ onChange, value }) => (
<Switch
id={"kc-console-pagination"}
isDisabled={false}
onChange={(value) => onChange([`${value}`])}
isChecked={value[0] === "true"}
2020-11-25 14:50:40 +00:00
label={t("common:on")}
labelOff={t("common:off")}
/>
)}
></Controller>
</FormGroup>
2020-11-25 16:17:50 +00:00
</FormAccess>
</>
);
};