Skip to content

Commit

Permalink
Fix translation key and deep schema management. Add TU
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxouwell committed Mar 8, 2024
1 parent 4689ffd commit 3fd7031
Show file tree
Hide file tree
Showing 3 changed files with 299 additions and 39 deletions.
60 changes: 32 additions & 28 deletions packages/material-renderers/src/layouts/ExpandPanelRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
getI18nKeyPrefix,
Translator,
UISchemaElement,
EnumOption,
} from '@jsonforms/core';
import {
Accordion,
Expand Down Expand Up @@ -399,44 +400,47 @@ const computeChildLabel = (
) => {
const childData = Resolve.data(data, childPath);

if (childLabelProp) {
const currentValue = get(childData, childLabelProp, '');
if (!childLabelProp) return get(childData, getFirstPrimitiveProp(schema), '');

const childSchema = Resolve.schema(
schema,
`#/properties/${encode(childLabelProp)}`,
rootSchema
);
const currentValue = get(childData, childLabelProp, '');

if (hasEnumField(childSchema)) {
const enumChildLabel = enumToEnumOptionMapper(
currentValue,
translateFct,
getI18nKeyPrefix(schema, uiSchema, childPath)
);
const childSchema = Resolve.schema(
schema,
`#/properties/${childLabelProp
.split('.')
.map((p) => encode(p))
.join('/properties/')}`,
rootSchema
);

return enumChildLabel.label;
} else if (hasOneOfField(childSchema)) {
const oneOfArray = childSchema.oneOf as JsonSchema[];
const oneOfSchema = oneOfArray.find(
(e: JsonSchema) => e.const === currentValue
);
const fallbackI18nKey =
getI18nKeyPrefix(schema, uiSchema, childPath) +
'.' +
getI18nKeyPrefix(schema, uiSchema, childLabelProp);

if (oneOfSchema === undefined) return currentValue;
let enumOption: EnumOption = undefined;
if (hasEnumField(childSchema)) {
enumOption = enumToEnumOptionMapper(
currentValue,
translateFct,
fallbackI18nKey
);
} else if (hasOneOfField(childSchema)) {
const oneOfArray = childSchema.oneOf as JsonSchema[];
const oneOfSchema = oneOfArray.find(
(e: JsonSchema) => e.const === currentValue
);

const oneOfChildLabel = oneOfToEnumOptionMapper(
if (oneOfSchema) {
enumOption = oneOfToEnumOptionMapper(
oneOfSchema,
translateFct,
getI18nKeyPrefix(schema, uiSchema, childPath)
fallbackI18nKey
);

return oneOfChildLabel.label;
} else {
return currentValue;
}
} else {
return get(childData, getFirstPrimitiveProp(schema), '');
}

return enumOption ? enumOption.label : currentValue;
};

export const withJsonFormsExpandPanelProps = (
Expand Down
Loading

0 comments on commit 3fd7031

Please sign in to comment.