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

151 lines
4.6 KiB
TypeScript
Raw Normal View History

2020-11-25 14:50:40 +00:00
import {
FormGroup,
Select,
SelectOption,
SelectVariant,
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";
2021-02-19 23:13:07 +00:00
import { useRealm } from "../../context/realm-context/RealmContext";
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
export type LdapSettingsGeneralProps = {
form: UseFormMethods;
showSectionHeading?: boolean;
showSectionDescription?: boolean;
};
export const LdapSettingsGeneral = ({
form,
showSectionHeading = false,
showSectionDescription = false,
}: LdapSettingsGeneralProps) => {
const { t } = useTranslation("user-federation");
const helpText = useTranslation("user-federation-help").t;
2021-02-19 23:13:07 +00:00
const { realm } = useRealm();
const [isVendorDropdownOpen, setIsVendorDropdownOpen] = useState(false);
2020-11-25 14:50:40 +00:00
return (
<>
{showSectionHeading && (
<WizardSectionHeader
title={t("generalOptions")}
description={helpText("ldapGeneralOptionsSettingsDescription")}
showDescription={showSectionDescription}
/>
)}
2020-11-25 16:17:50 +00:00
<FormAccess role="manage-realm" isHorizontal>
<FormGroup
label={t("consoleDisplayName")}
labelIcon={
<HelpItem
helpText={helpText("consoleDisplayNameHelp")}
forLabel={t("consoleDisplayName")}
forID="kc-console-display-name"
/>
}
fieldId="kc-console-display-name"
isRequired
>
{/* These hidden fields are required so data object written back matches data retrieved */}
<TextInput
hidden
type="text"
id="kc-console-provider-id"
name="providerId"
2021-02-19 23:13:07 +00:00
defaultValue="ldap"
ref={form.register}
/>
<TextInput
hidden
type="text"
id="kc-console-provider-type"
name="providerType"
2021-02-19 23:13:07 +00:00
defaultValue="org.keycloak.storage.UserStorageProvider"
ref={form.register}
/>
<TextInput
hidden
type="text"
id="kc-console-parentId"
name="parentId"
2021-02-19 23:13:07 +00:00
defaultValue={realm}
ref={form.register}
/>
2021-02-19 23:13:07 +00:00
<TextInput
isRequired
type="text"
id="kc-console-display-name"
name="name"
ref={form.register({
required: {
value: true,
message: `${t("validateName")}`,
},
})}
2021-02-23 20:49:57 +00:00
data-testid="ldap-name"
2021-02-19 23:13:07 +00:00
/>
{form.errors.name && (
<div className="error">{form.errors.name.message}</div>
)}
</FormGroup>
<FormGroup
label={t("vendor")}
labelIcon={
<HelpItem
helpText={helpText("vendorHelp")}
forLabel={t("vendor")}
forID="kc-vendor"
/>
}
fieldId="kc-vendor"
isRequired
>
2020-11-25 14:50:40 +00:00
<Controller
name="config.vendor[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-vendor"
required
onToggle={() => setIsVendorDropdownOpen(!isVendorDropdownOpen)}
isOpen={isVendorDropdownOpen}
onSelect={(_, value) => {
onChange(value as string);
setIsVendorDropdownOpen(false);
}}
selections={value}
variant={SelectVariant.single}
2021-02-23 20:49:57 +00:00
// data-testid="ldap-vendor"
2020-11-25 14:50:40 +00:00
>
<SelectOption key={0} value="ad" isPlaceholder>
Active Directory
</SelectOption>
<SelectOption key={1} value="rhds">
Red Hat Directory Server
</SelectOption>
<SelectOption key={2} value="tivoli">
Tivoli
</SelectOption>
<SelectOption key={3} value="edirectory">
Novell eDirectory
</SelectOption>
<SelectOption key={4} value="other">
Other
</SelectOption>
2020-11-25 14:50:40 +00:00
</Select>
)}
></Controller>
</FormGroup>
2020-11-25 16:17:50 +00:00
</FormAccess>
</>
);
};