From be000ff08c0c6b0b175f4a9a3fe4bd9754c33dda Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 30 May 2022 11:23:12 +0200 Subject: [PATCH] Mappers are now sorted (#2700) --- public/resources/en/dynamic.json | 1 + src/identity-providers/add/AddMapper.tsx | 48 +++++++++++--------- src/identity-providers/add/AddMapperForm.tsx | 36 +++++++-------- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/public/resources/en/dynamic.json b/public/resources/en/dynamic.json index 115170f593..c21ad1a61e 100644 --- a/public/resources/en/dynamic.json +++ b/public/resources/en/dynamic.json @@ -1,6 +1,7 @@ { "addMultivaluedLabel": "Add {{fieldLabel}}", "selectARole": "Select a role", + "selectGroup": "Select group", "usermodel": { "prop": { "label": "Property", diff --git a/src/identity-providers/add/AddMapper.tsx b/src/identity-providers/add/AddMapper.tsx index 328b019202..2f50897c23 100644 --- a/src/identity-providers/add/AddMapper.tsx +++ b/src/identity-providers/add/AddMapper.tsx @@ -35,6 +35,7 @@ import { KeycloakSpinner } from "../../components/keycloak-spinner/KeycloakSpinn import type { AttributeForm } from "../../components/key-value-form/AttributeForm"; import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput"; import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog"; +import useLocaleSort, { mapByKey } from "../../utils/useLocaleSort"; export type IdPMapperRepresentationWithAttributes = IdentityProviderMapperRepresentation & AttributeForm; @@ -52,6 +53,7 @@ export default function AddMapper() { const { handleSubmit, register, errors } = form; const { addAlert, addError } = useAlerts(); const history = useHistory(); + const localeSort = useLocaleSort(); const { realm } = useRealm(); const adminClient = useAdminClient(); @@ -60,11 +62,10 @@ export default function AddMapper() { const { id } = useParams(); const [mapperTypes, setMapperTypes] = - useState>(); - const [mapperType, setMapperType] = useState(); + useState(); const [currentMapper, setCurrentMapper] = - useState(); + useState(); const save = async (idpMapper: IdentityProviderMapperRepresentation) => { const mapper = convertFormValuesToObject( @@ -148,15 +149,17 @@ export default function AddMapper() { adminClient.identityProviders.findMapperTypes({ alias }), ]), ([mapper, mapperTypes]) => { + const mappers = localeSort(Object.values(mapperTypes), mapByKey("name")); if (mapper) { - setCurrentMapper(mapper); + setCurrentMapper( + mappers.find(({ id }) => id === mapper.identityProviderMapper) + ); setupForm(mapper); - setMapperType(mapper.identityProviderMapper!); } else { - setMapperType(Object.keys(mapperTypes)[0]); + setCurrentMapper(mappers[0]); } - setMapperTypes(mapperTypes); + setMapperTypes(mappers); }, [] ); @@ -167,7 +170,7 @@ export default function AddMapper() { form.setValue("config.claims", JSON.parse(mapper.config.claims)); }; - if (!mapperTypes) { + if (!mapperTypes || !currentMapper) { return ; } @@ -216,7 +219,7 @@ export default function AddMapper() { )} - - - {mapperType && mapperTypes[mapperType].properties && ( - + - )} - + + + {" "} + + )} +