ui-components icon indicating copy to clipboard operation
ui-components copied to clipboard

fix(schema-form): fix oneof titles [KFE-2686]

Open ricardogoncalves89 opened this issue 1 month ago • 0 comments

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 normalizeEnums and normalizeSchema utilities in schema-form.ts to convert oneOf constructs with { title, const } into a flat enum array in the schema, storing the titles in the corresponding uiSchema as ui:enumNames. This reduces schema nesting and improves compatibility with form libraries.
  • Updated KvSchemaForm in SchemaForm.tsx to use the new normalizeSchema return structure, merging the normalized uiSchema with any user-provided uiSchema to 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 via ui:enumNames in uiSchema. [1] [2]

Dependency and tooling updates:

  • Added vitest as a dev dependency in the root package.json and introduced a test script in react-ui-components/package.json to enable and standardize testing. [1] [2]

Other code quality improvements:

  • Added missing merge import from lodash to support merging of uiSchema objects in SchemaForm.tsx.

ricardogoncalves89 avatar Nov 21 '25 18:11 ricardogoncalves89