react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Converted the fields to Typescript

Open heath-freenome opened this issue 3 years ago • 0 comments
trafficstars

Reasons for making this change

  • Updated the @rjsf/utils types and functions based on necessary changes needed for the conversion as follows:
    • In types.ts some improvements and new types were discovered as follows:
      • Modified the RJSFSchema to add the non-standard enumNames property onto the JSONSchema7 to support the Fields
      • Added a new EnumOptionsType required for some of the fields
      • Added a new UnsupportedFieldProps type for the new UnsupportedFieldTemplate on TemplatesType
      • Removed the fields property on FieldTemplateProps since that data can be easily obtained from the registry
      • Added the rawErrors property to ArrayFieldTemplateProps since it was needed ArrayField
      • Added the missing T generic on a few uses of IdSchema properties on a few types
      • Updated the WidgetProps type to combine the options property with an additional, optional enumOptions property as needed by widgets
      • Updated the UIOptionsBaseType to have it combined with the TemplatesType making it require the T and F generics as well as adding the following new properties:
        • classNames was added as a breaking change (it used to simply be classNames in UiSchema but now it will be ui:classNames or ui:options: { classNames }
          • This makes classNames consistent with all the other ui options
        • orderable and removable were added to support the ArrayField
        • widget was added to support many of the Fields
      • Updated UIOptionsType to also take the T and F generics
      • Updated SchemaUtilsType.retrieveSchema() to make the formData parameter optional, like it already is on the wrapped function
    • Updated the getUiOptions() function to add the T and F generics to the return value type
    • Updated getWidget() to make the widget property optional, updating the tests accordingly
    • Updated isCustomWidget() to make uiSchema default to an empty object if missing, updating the tests accordingly
    • Updated optionsList to remove the enumNames hack and to return the new EnumOptionsType[] | undefined type
  • Updated FieldTemplate for antd to remove the commented out fields variable since it was removed from the FieldTemplateProps
  • Refactored ArrayField.js to ArrayField.tsx converting things to typescript
    • Made the FieldProps use the T[] generic based on the ArrayField's T generic since formData should always be an array
    • There were many places where type safety checks were required along with custom casts to deal with T vs T[] issues
    • Exported ArrayField cast as a Field to allow it to be used properly in the index.ts
  • Refactored BooleanField.js to BooleanField.tsx converting things to typescript
  • Refactored MultiSchemaField.js to MultiSchemaField.tsx converting things to typescript
  • Refactored NullField.js to NullField.tsx converting things to typescript
  • Refactored NumberField.js to NumberField.tsx converting things to typescript as well as making it a stateless functional component with useState() instead of a class
  • Refactored ObjectField.js to ObjectField.tsx converting things to typescript
  • Refactored SchemaField.js to SchemaField.tsx converting things to typescript
    • Updated the code to deal with the classNames now coming from ui: options, including updating tests accordingly adding a new one for the new case inside of ui:options
  • Refactored StringField.js to StringField.tsx converting things to typescript
  • Refactored fields/index.js to fields/index.ts adding the proper type for the returned object
  • Updated ArrayFieldTemplate to add the missing T and F generics required for getUiOptions()
  • Updated ObjectFieldTemplate to add the T and F generics onto getUiOptions()
  • Refactored fields/UnsupportedField.js to templates/UnsupportedField.tsx converting things to typescript
    • Added this to templates/index.ts as UnsupportedFieldTemplate
    • Also updated tests to use templates.UnsupportedFieldTemplate instead of fields.UnsupportedField
  • Updated getDefaultRegistry() to remove the cast on fields since they are now properly typed

NOTE: This PR is stacked on top of #3001, but will be rebased once it merges

Checklist

  • [ ] I'm updating documentation
  • [x] I'm adding or updating code
    • [x] I've added and/or updated tests. I've run npm run test:update to update snapshots, if needed.
    • [ ] I've updated docs if needed
    • [ ] I've updated the changelog with a description of the PR
  • [ ] I'm adding a new feature
    • [ ] I've updated the playground with an example use of the feature

heath-freenome avatar Aug 10 '22 01:08 heath-freenome