Fixing how translatable fields are set and ignoring formatting for root user attributes

Closes #40497

Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
This commit is contained in:
Pedro Igor
2025-06-25 17:13:20 -03:00
parent 8624101701
commit 5894ab663b
3 changed files with 20 additions and 2 deletions

View File

@@ -34,6 +34,7 @@ type AddTranslationsDialogProps = {
translationKey: string;
fieldName: string;
toggleDialog: () => void;
predefinedAttributes?: string[];
};
export const AddTranslationsDialog = ({
@@ -41,6 +42,7 @@ export const AddTranslationsDialog = ({
translationKey,
fieldName,
toggleDialog,
predefinedAttributes,
}: AddTranslationsDialogProps) => {
const { adminClient } = useAdminClient();
const { t } = useTranslation();
@@ -155,7 +157,11 @@ export const AddTranslationsDialog = ({
label={t("translationKey")}
data-testid="translation-key"
isDisabled
value={t(orgKey) !== orgKey ? `\${${orgKey}}` : translationKey}
value={
predefinedAttributes?.includes(orgKey)
? `\${${orgKey}}`
: `\${${translationKey}}`
}
/>
</FormGroup>
<FlexItem>

View File

@@ -126,6 +126,12 @@ export const AttributeGeneralSettings = () => {
attributeName="name"
prefix="profile.attributes"
fieldName="displayName"
predefinedAttributes={[
"username",
"email",
"firstName",
"lastName",
]}
/>
</FormGroup>
<DefaultSwitchControl

View File

@@ -67,6 +67,7 @@ type TranslatableFieldProps = {
attributeName: string;
prefix: string;
fieldName: string;
predefinedAttributes?: string[];
};
function hasTranslation(value: string, t: TFunction) {
@@ -85,6 +86,7 @@ export const TranslatableField = ({
attributeName,
prefix,
fieldName,
predefinedAttributes,
}: TranslatableFieldProps) => {
const { t } = useTranslation();
const { realmRepresentation: realm } = useRealm();
@@ -98,7 +100,10 @@ export const TranslatableField = ({
const requiredTranslationName = `${translationPrefix}.0.value`;
useEffect(() => {
if (realm?.internationalizationEnabled && !value) {
if (predefinedAttributes?.includes(value)) {
return;
}
if (realm?.internationalizationEnabled && value) {
setValue(fieldName, `\${${prefix}.${value}}`);
}
}, [value]);
@@ -117,6 +122,7 @@ export const TranslatableField = ({
orgKey={value}
translationKey={`${prefix}.${value}`}
fieldName={fieldName}
predefinedAttributes={predefinedAttributes}
toggleDialog={toggle}
/>
)}