Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion js/libs/ui-shared/src/user-profile/OptionsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const OptionComponent = (props: UserProfileFieldProps) => {

const optionLabel =
(attribute.annotations?.["inputOptionLabels"] as OptionLabel) || {};
const prefix = attribute.annotations?.[
"inputOptionLabelsI18nPrefix"
] as string;

return (
<UserProfileGroup {...props}>
Expand All @@ -32,7 +35,7 @@ export const OptionComponent = (props: UserProfileFieldProps) => {
key={option}
id={option}
data-testid={option}
label={label(props.t, optionLabel[option], option)}
label={label(props.t, optionLabel[option], option, prefix)}
value={option}
isChecked={field.value.includes(option)}
onChange={() => {
Expand Down
5 changes: 4 additions & 1 deletion js/libs/ui-shared/src/user-profile/SelectComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ export const SelectComponent = (props: UserProfileFieldProps) => {

const optionLabel =
(attribute.annotations?.["inputOptionLabels"] as OptionLabel) || {};
const prefix = attribute.annotations?.[
"inputOptionLabelsI18nPrefix"
] as string;

const fetchLabel = (option: string) =>
label(props.t, optionLabel[option], option);
label(props.t, optionLabel[option], option, prefix);

const convertOptions = (selected: string) =>
options
Expand Down
2 changes: 2 additions & 0 deletions js/libs/ui-shared/src/user-profile/TextComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const TextComponent = (props: UserProfileFieldProps) => {
placeholder={label(
props.t,
attribute.annotations?.["inputTypePlaceholder"] as string,
attribute.name,
attribute.annotations?.["inputOptionLabelsI18nPrefix"] as string,
)}
readOnly={attribute.readOnly}
isRequired={isRequired}
Expand Down
8 changes: 7 additions & 1 deletion js/libs/ui-shared/src/user-profile/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export const label = (
t: TFunction,
text: string | undefined,
fallback?: string,
) => (isBundleKey(text) ? t(unWrap(text!)) : text) || fallback;
prefix?: string,
) => {
const value = text || fallback;
const bundleKey = isBundleKey(value) ? unWrap(value!) : value;
const key = prefix ? `${prefix}.${bundleKey}` : bundleKey;
return t(key || "");
};

export const labelAttribute = (
t: TFunction,
Expand Down