ui-components
ui-components copied to clipboard
fix(schema-form): fix oneof titles [KFE-2686]
This pull request introduces improvements to the schema normalization logic for forms in the react-ui-components package, specifically focusing on how oneOf enums with titles are handled. The changes separate enum titles into the uiSchema (using ui:enumNames), simplify the schema structure, and update the component logic to merge normalized and user-provided uiSchema. Additionally, the pull request adds testing support with Vitest.
Schema normalization and form rendering improvements:
- Refactored the
normalizeEnumsandnormalizeSchemautilities inschema-form.tsto convertoneOfconstructs with{ title, const }into a flatenumarray in the schema, storing the titles in the correspondinguiSchemaasui:enumNames. This reduces schema nesting and improves compatibility with form libraries. - Updated
KvSchemaForminSchemaForm.tsxto use the newnormalizeSchemareturn structure, merging the normalizeduiSchemawith any user-provideduiSchemato ensure both system and custom UI options are respected. [1] [2] - Removed the legacy logic for handling custom enum titles (
x-titles) from the SelectWidget utilities, since enum titles are now handled viaui:enumNamesinuiSchema. [1] [2]
Dependency and tooling updates:
- Added
vitestas a dev dependency in the rootpackage.jsonand introduced atestscript inreact-ui-components/package.jsonto enable and standardize testing. [1] [2]
Other code quality improvements:
- Added missing
mergeimport fromlodashto support merging ofuiSchemaobjects inSchemaForm.tsx.