2020-11-25 14:50:40 +00:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
TextInput,
|
|
|
|
} from "@patternfly/react-core";
|
2020-10-30 20:15:37 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2020-12-16 07:02:41 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
2020-11-25 14:50:40 +00:00
|
|
|
import { useForm, Controller } from "react-hook-form";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { convertToFormValues } from "../../util";
|
2020-11-25 14:50:40 +00:00
|
|
|
import ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
2021-01-05 13:39:27 +00:00
|
|
|
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { useParams } from "react-router-dom";
|
2020-10-30 20:15:37 +00:00
|
|
|
|
|
|
|
export const LdapSettingsGeneral = () => {
|
|
|
|
const { t } = useTranslation("user-federation");
|
|
|
|
const helpText = useTranslation("user-federation-help").t;
|
2020-12-16 07:02:41 +00:00
|
|
|
const adminClient = useAdminClient();
|
|
|
|
const { register, control, setValue } = useForm<ComponentRepresentation>();
|
|
|
|
const { id } = useParams<{ id: string }>();
|
2020-11-25 14:50:40 +00:00
|
|
|
const [isVendorDropdownOpen, setIsVendorDropdownOpen] = useState(false);
|
2020-11-25 16:17:50 +00:00
|
|
|
|
2020-12-16 07:02:41 +00:00
|
|
|
const setupForm = (component: ComponentRepresentation) => {
|
|
|
|
Object.entries(component).map((entry) => {
|
|
|
|
if (entry[0] === "config") {
|
|
|
|
convertToFormValues(entry[1], "config", setValue);
|
|
|
|
if (entry[1].vendor) {
|
|
|
|
setValue("config.vendor", convertVendorNames(entry[1].vendor[0]));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setValue(entry[0], entry[1]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-01-05 13:39:27 +00:00
|
|
|
return useFetch(
|
|
|
|
() => adminClient.components.findOne({ id }),
|
|
|
|
(fetchedComponent) => setupForm(fetchedComponent)
|
|
|
|
);
|
2020-12-16 07:02:41 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
const convertVendorNames = (vendorName: string) => {
|
|
|
|
switch (vendorName) {
|
|
|
|
case "ad":
|
|
|
|
return "Active Directory";
|
|
|
|
case "rhds":
|
|
|
|
return "Red Hat Directory Server";
|
|
|
|
case "tivoli":
|
|
|
|
return "Tivoli";
|
|
|
|
case "edirectory":
|
|
|
|
return "Novell eDirectory";
|
|
|
|
case "other":
|
|
|
|
return "Other";
|
|
|
|
default:
|
|
|
|
return t("common:choose");
|
|
|
|
}
|
|
|
|
};
|
2020-11-25 14:50:40 +00:00
|
|
|
|
2020-10-30 20:15:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2020-11-25 16:17:50 +00:00
|
|
|
<FormAccess role="manage-realm" isHorizontal>
|
2020-10-30 20:15:37 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("consoleDisplayName")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("consoleDisplayNameHelp")}
|
|
|
|
forLabel={t("consoleDisplayName")}
|
|
|
|
forID="kc-console-display-name"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-console-display-name"
|
|
|
|
isRequired
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
isRequired
|
|
|
|
type="text"
|
|
|
|
id="kc-console-display-name"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="name"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
</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
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.vendor"
|
2020-11-25 14:50:40 +00:00
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
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}
|
|
|
|
>
|
2020-12-16 07:02:41 +00:00
|
|
|
<SelectOption
|
|
|
|
key={0}
|
|
|
|
value={t("common:choose")}
|
|
|
|
isPlaceholder
|
|
|
|
/>
|
2020-11-25 14:50:40 +00:00
|
|
|
<SelectOption key={1} value="Active Directory" />
|
|
|
|
<SelectOption key={2} value="Red Hat Directory Server" />
|
|
|
|
<SelectOption key={3} value="Tivoli" />
|
|
|
|
<SelectOption key={4} value="Novell eDirectory" />
|
|
|
|
<SelectOption key={5} value="Other" />
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
2020-11-25 16:17:50 +00:00
|
|
|
</FormAccess>
|
2020-10-30 20:15:37 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|