use inputOptionsLabels when they exist (#22451)
* use inputOptionsLabels when they exist fixes: #22432 * fixed type
This commit is contained in:
parent
e07abbdf9d
commit
2a6b4d1210
1 changed files with 9 additions and 2 deletions
|
@ -9,9 +9,10 @@ import {
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { Options } from "../UserProfileFields";
|
import { Options } from "../UserProfileFields";
|
||||||
import { fieldName } from "../utils";
|
import { fieldName, unWrap } from "../utils";
|
||||||
import { UserProfileFieldsProps, UserProfileGroup } from "./UserProfileGroup";
|
import { UserProfileFieldsProps, UserProfileGroup } from "./UserProfileGroup";
|
||||||
|
|
||||||
|
type OptionLabel = Record<string, string> | undefined;
|
||||||
export const SelectComponent = (attribute: UserProfileFieldsProps) => {
|
export const SelectComponent = (attribute: UserProfileFieldsProps) => {
|
||||||
const { t } = useTranslation("users");
|
const { t } = useTranslation("users");
|
||||||
const { control } = useFormContext();
|
const { control } = useFormContext();
|
||||||
|
@ -42,6 +43,12 @@ export const SelectComponent = (attribute: UserProfileFieldsProps) => {
|
||||||
const options =
|
const options =
|
||||||
(attribute.validations?.options as Options | undefined)?.options || [];
|
(attribute.validations?.options as Options | undefined)?.options || [];
|
||||||
|
|
||||||
|
const optionLabel = attribute.annotations?.[
|
||||||
|
"inputOptionLabels"
|
||||||
|
] as OptionLabel;
|
||||||
|
const label = (label: string) =>
|
||||||
|
optionLabel ? t(unWrap(optionLabel[label])) : label;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserProfileGroup {...attribute}>
|
<UserProfileGroup {...attribute}>
|
||||||
<Controller
|
<Controller
|
||||||
|
@ -79,7 +86,7 @@ export const SelectComponent = (attribute: UserProfileFieldsProps) => {
|
||||||
key={option}
|
key={option}
|
||||||
value={option}
|
value={option}
|
||||||
>
|
>
|
||||||
{option}
|
{label(option)}
|
||||||
</SelectOption>
|
</SelectOption>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
|
Loading…
Reference in a new issue