forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow selecting attributes from user profile when managing token mapp…
…ers (keycloak#26415) * Allow selecting attributes from user profile when managing token mappers closes keycloak#24250 Signed-off-by: mposolda <mposolda@gmail.com> Co-authored-by: Jon Koops <jonkoops@gmail.com>
- Loading branch information
Showing
16 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
js/apps/admin-ui/src/components/dynamic/UserProfileAttributeListComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type { UserProfileConfig } from "@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata"; | ||
import { FormGroup } from "@patternfly/react-core"; | ||
import { useState } from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
import { useTranslation } from "react-i18next"; | ||
import { HelpItem } from "ui-shared"; | ||
|
||
import { adminClient } from "../../admin-client"; | ||
import { useFetch } from "../../utils/useFetch"; | ||
import { KeySelect } from "../key-value-form/KeySelect"; | ||
import { convertToName } from "./DynamicComponents"; | ||
import type { ComponentProps } from "./components"; | ||
|
||
export const UserProfileAttributeListComponent = ({ | ||
name, | ||
label, | ||
helpText, | ||
required = false, | ||
}: ComponentProps) => { | ||
const { t } = useTranslation(); | ||
const { | ||
formState: { errors }, | ||
} = useFormContext(); | ||
|
||
const [config, setConfig] = useState<UserProfileConfig>(); | ||
const convertedName = convertToName(name!); | ||
|
||
useFetch( | ||
() => adminClient.users.getProfile(), | ||
(cfg) => setConfig(cfg), | ||
[], | ||
); | ||
|
||
const convert = (config?: UserProfileConfig) => { | ||
if (!config?.attributes) return []; | ||
|
||
return config.attributes.map((option) => ({ | ||
key: option.name!, | ||
label: option.name!, | ||
})); | ||
}; | ||
|
||
if (!config) return null; | ||
|
||
return ( | ||
<FormGroup | ||
label={t(label!)} | ||
isRequired={required} | ||
labelIcon={<HelpItem helpText={t(helpText!)} fieldLabelId={label!} />} | ||
fieldId={convertedName!} | ||
validated={errors[convertedName!] ? "error" : "default"} | ||
helperTextInvalid={t("required")} | ||
> | ||
<KeySelect | ||
name={convertedName} | ||
rules={required ? { required: true } : {}} | ||
selectItems={convert(config)} | ||
/> | ||
</FormGroup> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters