Fix default values for group and role mappers (#1511)
* fixed defaults for group and role mappers * incorporate jon PR comments
This commit is contained in:
parent
0b95598411
commit
7105bb9917
1 changed files with 29 additions and 2 deletions
|
@ -8,6 +8,8 @@ import {
|
||||||
ValidatedOptions,
|
ValidatedOptions,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import type { UserFederationLdapMapperParams } from "../../routes/UserFederationLdapMapper";
|
||||||
import { HelpItem } from "../../../components/help-enabler/HelpItem";
|
import { HelpItem } from "../../../components/help-enabler/HelpItem";
|
||||||
import { Controller, UseFormMethods } from "react-hook-form";
|
import { Controller, UseFormMethods } from "react-hook-form";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
@ -32,6 +34,7 @@ export const LdapMapperRoleGroup = ({
|
||||||
useState(false);
|
useState(false);
|
||||||
const [isClientIdDropdownOpen, setIsClientIdDropdownOpen] = useState(false);
|
const [isClientIdDropdownOpen, setIsClientIdDropdownOpen] = useState(false);
|
||||||
const [clients, setClients] = useState<ClientRepresentation[]>([]);
|
const [clients, setClients] = useState<ClientRepresentation[]>([]);
|
||||||
|
const { id, mapperId } = useParams<UserFederationLdapMapperParams>();
|
||||||
|
|
||||||
let isRole = true;
|
let isRole = true;
|
||||||
const groupMapper = "group-ldap-mapper";
|
const groupMapper = "group-ldap-mapper";
|
||||||
|
@ -52,6 +55,29 @@ export const LdapMapperRoleGroup = ({
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useFetch(
|
||||||
|
async () => {
|
||||||
|
return await adminClient.components.findOne({ id });
|
||||||
|
},
|
||||||
|
(fetchedComponent) => {
|
||||||
|
if (fetchedComponent) {
|
||||||
|
const vendor = fetchedComponent.config?.vendor[0];
|
||||||
|
if (mapperId === "new" && vendor === "ad") {
|
||||||
|
form.setValue(
|
||||||
|
isRole
|
||||||
|
? "config.role-object-classes[0]"
|
||||||
|
: "config.group-object-classes[0]",
|
||||||
|
"group"
|
||||||
|
);
|
||||||
|
form.setValue("config.membership-user-ldap-attribute[0]", "cn");
|
||||||
|
}
|
||||||
|
} else if (id) {
|
||||||
|
throw new Error(t("common:notFound"));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
|
@ -143,7 +169,7 @@ export const LdapMapperRoleGroup = ({
|
||||||
type="text"
|
type="text"
|
||||||
id="kc-object-classes"
|
id="kc-object-classes"
|
||||||
data-testid="object-classes"
|
data-testid="object-classes"
|
||||||
defaultValue="group"
|
defaultValue="groupOfNames"
|
||||||
name={
|
name={
|
||||||
isRole
|
isRole
|
||||||
? "config.role-object-classes[0]"
|
? "config.role-object-classes[0]"
|
||||||
|
@ -290,7 +316,7 @@ export const LdapMapperRoleGroup = ({
|
||||||
type="text"
|
type="text"
|
||||||
id="kc-membership-user-ldap-attribute"
|
id="kc-membership-user-ldap-attribute"
|
||||||
data-testid="membership-user-ldap-attribute"
|
data-testid="membership-user-ldap-attribute"
|
||||||
defaultValue="cn"
|
defaultValue="uid"
|
||||||
name="config.membership-user-ldap-attribute[0]"
|
name="config.membership-user-ldap-attribute[0]"
|
||||||
ref={form.register}
|
ref={form.register}
|
||||||
/>
|
/>
|
||||||
|
@ -487,6 +513,7 @@ export const LdapMapperRoleGroup = ({
|
||||||
>
|
>
|
||||||
<Controller
|
<Controller
|
||||||
name="config.client-id[0]"
|
name="config.client-id[0]"
|
||||||
|
defaultValue=""
|
||||||
control={form.control}
|
control={form.control}
|
||||||
render={({ onChange, value }) => (
|
render={({ onChange, value }) => (
|
||||||
<Select
|
<Select
|
||||||
|
|
Loading…
Reference in a new issue