Merge pull request #21439 from nabiltntn/change-enum-review-display

Display enum label from enumNames in review if used
This commit is contained in:
Ben Lambert
2023-11-27 10:42:11 +01:00
committed by GitHub
3 changed files with 80 additions and 0 deletions
@@ -136,4 +136,70 @@ describe('ReviewState', () => {
expect(getByRole('row', { name: 'Name lols' })).toBeInTheDocument();
});
it('should display enum label from enumNames', async () => {
const formState = {
name: 'type2',
};
const schemas: ParsedTemplateSchema[] = [
{
mergedSchema: {
type: 'object',
properties: {
name: {
type: 'string',
default: 'type1',
enum: ['type1', 'type2', 'type3'],
enumNames: ['Label-type1', 'Label-type2', 'Label-type3'],
},
},
},
schema: {},
title: 'test',
uiSchema: {},
description: 'asd',
},
];
const { queryByRole } = render(
<ReviewState formState={formState} schemas={schemas} />,
);
expect(
queryByRole('row', { name: 'Name Label-type2' }),
).toBeInTheDocument();
});
it('should display enum value if no corresponding enumNames', async () => {
const formState = {
name: 'type4',
};
const schemas: ParsedTemplateSchema[] = [
{
mergedSchema: {
type: 'object',
properties: {
name: {
type: 'string',
default: 'type1',
enum: ['type1', 'type2', 'type3', 'type4'],
enumNames: ['Label-type1', 'Label-type2', 'Label-type3'],
},
},
},
schema: {},
title: 'test',
uiSchema: {},
description: 'asd',
},
];
const { queryByRole } = render(
<ReviewState formState={formState} schemas={schemas} />,
);
expect(queryByRole('row', { name: 'Name type4' })).toBeInTheDocument();
});
});
@@ -57,6 +57,15 @@ export const ReviewState = (props: ReviewStateProps) => {
if (definitionInSchema['ui:widget'] === 'password') {
return [key, '******'];
}
if (definitionInSchema.enum && definitionInSchema.enumNames) {
return [
key,
definitionInSchema.enumNames[
definitionInSchema.enum.indexOf(value)
] || value,
];
}
}
}
return [key, value];