2020-11-25 16:17:50 +00:00
|
|
|
import { FormGroup, Switch, 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 } 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";
|
|
|
|
import { useAdminClient } from "../../context/auth/AdminClient";
|
|
|
|
import { useParams } from "react-router-dom";
|
2020-10-30 20:15:37 +00:00
|
|
|
|
|
|
|
export const LdapSettingsSynchronization = () => {
|
|
|
|
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-10-30 20:15:37 +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);
|
|
|
|
} else {
|
|
|
|
setValue(entry[0], entry[1]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
const fetchedComponent = await adminClient.components.findOne({ id });
|
|
|
|
if (fetchedComponent) {
|
|
|
|
setupForm(fetchedComponent);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}, []);
|
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
|
2020-12-16 07:02:41 +00:00
|
|
|
hasNoPaddingTop
|
2020-10-30 20:15:37 +00:00
|
|
|
label={t("importUsers")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("importUsersHelp")}
|
|
|
|
forLabel={t("importUsers")}
|
|
|
|
forID="kc-import-users"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-import-users"
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.importEnabled"
|
2020-11-25 14:50:40 +00:00
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id={"kc-import-users"}
|
2020-12-16 07:02:41 +00:00
|
|
|
name="importEnabled"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value[0] === "true"}
|
2020-11-25 14:50:40 +00:00
|
|
|
isDisabled={false}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("batchSize")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("batchSizeHelp")}
|
|
|
|
forLabel={t("batchSize")}
|
|
|
|
forID="kc-batch-size"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-batch-size"
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-batch-size"
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.batchSizeForSync"
|
2020-11-25 14:50:40 +00:00
|
|
|
ref={register}
|
|
|
|
/>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
2020-12-16 07:02:41 +00:00
|
|
|
hasNoPaddingTop
|
2020-10-30 20:15:37 +00:00
|
|
|
label={t("periodicFullSync")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("periodicFullSyncHelp")}
|
|
|
|
forLabel={t("periodicFullSync")}
|
|
|
|
forID="kc-periodic-full-sync"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-periodic-full-sync"
|
|
|
|
>
|
2020-12-16 07:02:41 +00:00
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-batch-size"
|
|
|
|
name="config.fullSyncPeriod"
|
|
|
|
ref={register}
|
|
|
|
/>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("periodicChangedUsersSync")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("periodicChangedUsersSyncHelp")}
|
|
|
|
forLabel={t("periodicChangedUsersSync")}
|
|
|
|
forID="kc-periodic-changed-users-sync"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-periodic-changed-users-sync"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
2020-12-16 07:02:41 +00:00
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-batch-size"
|
|
|
|
name="config.changedSyncPeriod"
|
|
|
|
ref={register}
|
|
|
|
/>
|
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
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|