keycloak-scim/js/apps/admin-ui/src/user-federation/ldap/LdapSettingsSearching.tsx

414 lines
13 KiB
TypeScript
Raw Normal View History

import {
FormGroup,
Select,
SelectOption,
2020-11-25 14:50:40 +00:00
SelectVariant,
Switch,
} from "@patternfly/react-core";
import { useState } from "react";
import { Controller, UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { FormAccess } from "../../components/form-access/FormAccess";
2023-03-07 09:29:40 +00:00
import { HelpItem } from "ui-shared";
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
export type LdapSettingsSearchingProps = {
form: UseFormReturn;
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
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:editModeLdapHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="user-federation:editMode"
/>
}
fieldId="kc-edit-mode"
isRequired
validated={
(form.formState.errors.config as any)?.editMode?.[0]
? "error"
: "default"
}
helperTextInvalid={
(form.formState.errors.config as any)?.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") },
}}
render={({ field }) => (
2020-11-25 14:50:40 +00:00
<Select
toggleId="kc-edit-mode"
required
onToggle={() =>
setIsEditModeDropdownOpen(!isEditModeDropdownOpen)
}
isOpen={isEditModeDropdownOpen}
onSelect={(_, value) => {
field.onChange(value.toString());
2020-11-25 14:50:40 +00:00
setIsEditModeDropdownOpen(false);
}}
selections={field.value}
2020-11-25 14:50:40 +00:00
variant={SelectVariant.single}
validated={
(form.formState.errors.config as any)?.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
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:usersDNHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="user-federation:usersDn"
/>
}
fieldId="kc-ui-users-dn"
isRequired
validated={
(form.formState.errors.config as any)?.usersDn?.[0]
? "error"
: "default"
}
helperTextInvalid={
(form.formState.errors.config as any)?.usersDn?.[0].message
}
>
<KeycloakTextInput
isRequired
defaultValue=""
id="kc-ui-users-dn"
2021-02-23 20:49:57 +00:00
data-testid="ldap-users-dn"
validated={
(form.formState.errors.config as any)?.usersDn?.[0]
? "error"
: "default"
}
{...form.register("config.usersDn.0", {
required: {
value: true,
message: t("validateUsersDn").toString(),
},
})}
/>
</FormGroup>
<FormGroup
label={t("usernameLdapAttribute")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:usernameLdapAttributeHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="user-federation:usernameLdapAttribute"
/>
}
fieldId="kc-username-ldap-attribute"
isRequired
validated={
(form.formState.errors.config as any)?.usernameLDAPAttribute?.[0]
? "error"
: "default"
}
helperTextInvalid={
(form.formState.errors.config as any)?.usernameLDAPAttribute?.[0]
.message
}
>
<KeycloakTextInput
isRequired
defaultValue="cn"
id="kc-username-ldap-attribute"
2021-02-23 20:49:57 +00:00
data-testid="ldap-username-attribute"
validated={
(form.formState.errors.config as any)?.usernameLDAPAttribute?.[0]
? "error"
: "default"
}
{...form.register("config.usernameLDAPAttribute.0", {
required: {
value: true,
message: `${t("validateUsernameLDAPAttribute")}`,
},
})}
/>
</FormGroup>
<FormGroup
label={t("rdnLdapAttribute")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:rdnLdapAttributeHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="user-federation:rdnLdapAttribute"
/>
}
fieldId="kc-rdn-ldap-attribute"
isRequired
validated={
(form.formState.errors.config as any)?.rdnLDAPAttribute?.[0]
? "error"
: "default"
}
helperTextInvalid={
(form.formState.errors.config as any)?.rdnLDAPAttribute?.[0].message
}
>
<KeycloakTextInput
isRequired
defaultValue="cn"
id="kc-rdn-ldap-attribute"
2021-02-23 20:49:57 +00:00
data-testid="ldap-rdn-attribute"
validated={
(form.formState.errors.config as any)?.rdnLDAPAttribute?.[0]
? "error"
: "default"
}
{...form.register("config.rdnLDAPAttribute.0", {
required: {
value: true,
message: `${t("validateRdnLdapAttribute")}`,
},
})}
/>
</FormGroup>
<FormGroup
label={t("uuidLdapAttribute")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:uuidLdapAttributeHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="user-federation:uuidLdapAttribute"
/>
}
fieldId="kc-uuid-ldap-attribute"
isRequired
validated={
(form.formState.errors.config as any)?.uuidLDAPAttribute?.[0]
? "error"
: "default"
}
helperTextInvalid={
(form.formState.errors.config as any)?.uuidLDAPAttribute?.[0]
.message
}
>
<KeycloakTextInput
isRequired
defaultValue="objectGUID"
id="kc-uuid-ldap-attribute"
2021-02-23 20:49:57 +00:00
data-testid="ldap-uuid-attribute"
validated={
(form.formState.errors.config as any)?.uuidLDAPAttribute?.[0]
? "error"
: "default"
}
{...form.register("config.uuidLDAPAttribute.0", {
required: {
value: true,
message: `${t("validateUuidLDAPAttribute")}`,
},
})}
/>
</FormGroup>
<FormGroup
label={t("userObjectClasses")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:userObjectClassesHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="user-federation:userObjectClasses"
/>
}
fieldId="kc-user-object-classes"
isRequired
validated={
(form.formState.errors.config as any)?.userObjectClasses?.[0]
? "error"
: "default"
}
helperTextInvalid={
(form.formState.errors.config as any)?.userObjectClasses?.[0]
.message
}
>
<KeycloakTextInput
isRequired
defaultValue="person, organizationalPerson, user"
id="kc-user-object-classes"
2021-02-23 20:49:57 +00:00
data-testid="ldap-user-object-classes"
validated={
(form.formState.errors.config as any)?.userObjectClasses?.[0]
? "error"
: "default"
}
{...form.register("config.userObjectClasses.0", {
required: {
value: true,
message: t("validateUserObjectClasses").toString(),
},
})}
/>
</FormGroup>
<FormGroup
label={t("userLdapFilter")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:userLdapFilterHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="user-federation:userLdapFilter"
/>
}
fieldId="kc-user-ldap-filter"
validated={
(form.formState.errors.config as any)?.customUserSearchFilter?.[0]
? "error"
: "default"
}
helperTextInvalid={
(form.formState.errors.config as any)?.customUserSearchFilter?.[0]
.message
}
>
<KeycloakTextInput
id="kc-user-ldap-filter"
2022-04-08 09:47:14 +00:00
data-testid="user-ldap-filter"
validated={
(form.formState.errors.config as any)?.customUserSearchFilter?.[0]
? "error"
: "default"
}
{...form.register("config.customUserSearchFilter.0", {
pattern: {
value: /(\(.*\))$/,
message: t("validateCustomUserSearchFilter").toString(),
},
})}
/>
</FormGroup>
<FormGroup
label={t("searchScope")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:searchScopeHelp")}
2021-12-14 14:56:36 +00:00
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}
render={({ field }) => (
2020-11-25 14:50:40 +00:00
<Select
toggleId="kc-search-scope"
required
onToggle={() =>
setIsSearchScopeDropdownOpen(!isSearchScopeDropdownOpen)
}
isOpen={isSearchScopeDropdownOpen}
onSelect={(_, value) => {
field.onChange(value as string);
2020-11-25 14:50:40 +00:00
setIsSearchScopeDropdownOpen(false);
}}
selections={field.value}
2020-11-25 14:50:40 +00:00
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
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:readTimeoutHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="user-federation:readTimeout"
/>
}
fieldId="kc-read-timeout"
>
<KeycloakTextInput
type="number"
2021-03-02 15:37:51 +00:00
min={0}
id="kc-read-timeout"
2022-04-08 09:47:14 +00:00
data-testid="ldap-read-timeout"
{...form.register("config.readTimeout.0")}
/>
</FormGroup>
<FormGroup
label={t("pagination")}
labelIcon={
<HelpItem
2023-03-07 09:29:40 +00:00
helpText={t("user-federation-help:paginationHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="user-federation:pagination"
/>
}
fieldId="kc-ui-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}
render={({ field }) => (
2020-11-25 14:50:40 +00:00
<Switch
id="kc-ui-pagination"
data-testid="ui-pagination"
2020-11-25 14:50:40 +00:00
isDisabled={false}
onChange={(value) => field.onChange([`${value}`])}
isChecked={field.value[0] === "true"}
2020-11-25 14:50:40 +00:00
label={t("common:on")}
labelOff={t("common:off")}
aria-label={t("pagination")}
2020-11-25 14:50:40 +00:00
/>
)}
></Controller>
</FormGroup>
2020-11-25 16:17:50 +00:00
</FormAccess>
</>
);
};