Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core to use utils and validator #2908

Conversation

heath-freenome
Copy link
Member

@heath-freenome heath-freenome commented Jul 5, 2022

Reasons for making this change

Partially fixes #2693 by updating core to use the new @rjsf/utils and @rjsf/validator-ajv6 (for tests)

Updated @rjsf/core to use the new utils and validator-ajv6 libraries

  • Updated package*.json to make changes consistent with pulling utils and validator-ajv6 libraries
    • Removed core-js-pure, json-schema-merge-allof, jsonpointer and react-is from dependencies in favor of @rjsf/utils
    • Moved ajv and @types/json-schema into the devDependencies
    • Added @rjsf/validator-ajv6, @types/lodash and tsdx
  • Converted ErrorList to typescript, pulling types from @rjsf/utils
  • Converted Form to typescript
    • Built FormProps and FormState props which are exported
    • Pulled in all the types from @rjsf/utils functions
    • Removed the additionalMetaSchemas and customFormats props in favor of the new, required validator: ValidatorType prop
    • Updated getStateFromProps() to create a SchemaUtilsType object and put it into both the state and the registry as schemaUtils
    • Switched to using the schemaUtils.getValidator() to access the validateFormData() and toErrorList() calls
    • Switched to using schemaUtils to access getDefaultFormState(), toIdSchema(), toPathSchema() and retrieveSchema()
  • Updated ArrayField to use the @rjsf/utils functions
    • Also, switched to the includes function from lodash
    • Pull the schemaUtils from the registry and used it for getDefaultFormState(), isMultiSelect(), isFilesArray(), retrieveSchema() and toIdSchema()
    • Switched from xxx.hadOwnProperty('y') to 'y' in xxx to remove an eslint warning
  • Updated BooleanField, NumberField, CheckboxWidget, DateTimeWidget, FileWidget, RangeWidget, and UpDownWidget to pull utility functions from @rjsf/utils
  • Updated MultiSchemaField to use the @rjsf/utils functions
    • Pulled the schemaUtils from the registry and used it for getDefaultFormState() and getMatchingOption()
    • Switched from xxx.hadOwnProperty('y') to 'y' in xxx to remove an eslint warning
  • Updated ObjectField to use the @rjsf/utils functions
    • Pulled the schemaUtils from the registry and used it for retrieveSchema()
    • Switched from xxx.hadOwnProperty('y') to 'y' in xxx to remove an eslint warning
  • Updated SchemaField to use the @rjsf/utils functions
    • Pulled the schemaUtils from the registry and used it for getDisplayLabel(), isSelect(), retrieveSchema() and toIdSchema()
    • Switched from xxx.hadOwnProperty('y') to 'y' in xxx to remove an eslint warning
  • Updated StringField to use the @rjsf/utils functions
    • Pulled the schemaUtils from the registry and used it for isSelect()
  • Updated AltDateWidget to use the @rjsf/utils functions
    • Removed prevState from componentDidUpdate() because it is not used, removing lint error
  • Updated SelectWidget to use the new processSelectValue() function from @rjsf/utils
  • Updated TextWidget to add bool as a type for the value to avoid a React error that failed tests
  • Converted SubmitButton to typescript, pulling types from @rjsf/utils and exporting it's props type
  • Converted getDefaultRegistry() to typescript, pulling types from @rjsf/utils
    • Changed the export to be default
    • Temporarily needing to cast fields and widgets to the proper type until they are converted
  • Converted withTheme() to typescript, pulling types from @rjsf/utils and the typescript Form
  • Converted the src/index.js file to Typescript, exporting both the Form and its types along with withTheme(), getDefaultRegistry()
  • Updated the types.js file to remove definitions and add in schemaUtils ffor the registry type.
  • Deleted the src/utils.js, src/validate.js files since they have been replaced with @rjsf/utils/ and @rjsf/validator-ajv6
    • Removed the utils_test.js file entirely and only kept the Form integration part of the validate_test.js
  • Updated the tests as follows to make things work with @rjsf/utils and @rjsf/validator-ajv6
    • Updated test_utils.js to import the default validator from @rjsf/validator-ajv6 and add it to the props for createFormComponent()
    • Updated the Form_test.js to import the default validator and the customizeValidator() function and passed validator into props for <Form>...</Form>
      • Updated the checking of onChangeProp to add schemaValidationErrors, schemaValidationErrorSchema and schemaUtils to the calledWith() check
      • Updated the checking of onError to add schemaValidationErrors, schemaValidationErrorSchema to the match
      • Deleted any tests that dealt with the now removed deprecated features
      • Replaced tests the used the customFormats or additionalMetaSchemas props with a customized validator with those values set on it
        • In one place, removed a piece of a test that was reverting the old props since they don't exist anymore
    • Updated the SchemaField_test.js file to check the registry in the received props to have schemaUtils instead of definitions
      • Fixed the import of getDefaultRegistry()
      • Also removed the test related to empty definitions since that isn't in the registry anymore
    • Updated the StringField_test.js to import the utility functions from @rjsf/utils
    • Updated the uiSchema_test.js file to deal with the removal of deprecated ui:widget: {component, options} feature in @rjsf/utils
      • Switched from warn to error for spying
      • Removed the deprecated ui:widget configurations in the tests, moving the options into the ui:options block instead`
      • Verified the proper error (instead of warning) is returned

NOTE: This PR will not pass tests because not all of the themes have yet to be converted

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • 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 heath-freenome force-pushed the update-core-to-use-utils-and-validator branch 8 times, most recently from efc1e4f to 74bcfed Compare July 8, 2022 22:10
- Removed the `index.d.ts` file since all the types are now exported in `@rjsf/utils`
- Updated `package*.json` to make changes consistent with pulling utils and validator-ajv6 libraries
  - Removed `core-js-pure`, `json-schema-merge-allof`, `jsonpointer` and `react-is` from `dependencies` in favor of `@rjsf/utils`
  - Moved `ajv` and `@types/json-schema` into the `devDependencies`
  - Added `@rjsf/validator-ajv6`, `@types/lodash` and `tsdx`
  - Also, removed all mentions of `index.d.ts`
- Converted `ErrorList` to typescript, pulling types from `@rjsf/utils`
- Converted `Form` to typescript
  - Built `FormProps` and `FormState` props which are exported
  - Pulled in all the types from `@rjsf/utils` functions
  - Removed the `additionalMetaSchemas` and `customFormats` props in favor of the new, required `validator: ValidatorType` prop
  - Updated `getStateFromProps()` to create a `SchemaUtilsType` object and put it into both the state and the registry as `schemaUtils`
  - Switched to using the `schemaUtils.getValidator()` to access the `validateFormData()` and `toErrorList()` calls
  - Switched to using `schemaUtils` to access `getDefaultFormState()`, `toIdSchema()`, `toPathSchema()` and `retrieveSchema()`
- Updated `ArrayField` to use the `@rjsf/utils` functions
  - Also, switched to the `includes` function from `lodash`
  - Pull the `schemaUtils` from the `registry` and used it for `getDefaultFormState()`, `isMultiSelect()`, `isFilesArray()`, `retrieveSchema()` and `toIdSchema()`
  - Switched from `xxx.hadOwnProperty('y')` to `'y' in xxx` to remove an eslint warning
- Updated `BooleanField`, `NumberField`, `CheckboxWidget`, `DateTimeWidget`, `FileWidget`, `RangeWidget`, `SelectWidget` and `UpDownWidget` to pull utility functions from `@rjsf/utils`
- Updated `MultiSchemaField` to use the `@rjsf/utils` functions
  - Pulled the `schemaUtils` from the `registry` and used it for `getDefaultFormState()` and `getMatchingOption()`
  - Switched from `xxx.hadOwnProperty('y')` to `'y' in xxx` to remove an eslint warning
- Updated `ObjectField` to use the `@rjsf/utils` functions
  - Pulled the `schemaUtils` from the `registry` and used it for `retrieveSchema()`
  - Switched from `xxx.hadOwnProperty('y')` to `'y' in xxx` to remove an eslint warning
- Updated `SchemaField` to use the `@rjsf/utils` functions
  - Pulled the `schemaUtils` from the `registry` and used it for `getDisplayLabel()`, `isSelect()`, `retrieveSchema()` and `toIdSchema()`
  - Switched from `xxx.hadOwnProperty('y')` to `'y' in xxx` to remove an eslint warning
- Updated `StringField` to use the `@rjsf/utils` functions
  - Pulled the `schemaUtils` from the `registry` and used it for `isSelect()`
- Updated `AltDateWidget` to use the `@rjsf/utils` functions
  - Removed `prevState` from `componentDidUpdate()` because it is not used, removing lint error
- Updated `TextWidget` to add `bool` as a type for the value to avoid a React error that failed tests
- Converted `SubmitButton` to typescript, pulling types from `@rjsf/utils` and exporting it's props type
- Converted `getDefaultRegistry()` to typescript, pulling types from `@rjsf/utils`
  - Changed the export to be `default`
  - Temporarily needing to cast `fields` and `widgets` to the proper type until they are converted
- Converted `withTheme()` to typescript, pulling types from `@rjsf/utils` and the typescript `Form`
- Converted the `src/index.js` file to Typescript, exporting both the `Form` and its types along with `withTheme()`, `getDefaultRegistry()`
- Updated the `types.js` file to remove `definitions` and add in `schemaUtils` ffor the `registry` type.
- Deleted the `src/utils.js`, `src/validate.js` files since they have been replaced with `@rjsf/utils/` and `@rjsf/validator-ajv6`
  - Removed the `utils_test.js` file entirely and only kept the `Form` integration part of the `validate_test.js`
- Updated the tests as follows to make things work with `@rjsf/utils` and `@rjsf/validator-ajv6`
  - Updated `test_utils.js` to import the default `validator` from `@rjsf/validator-ajv6` and add it to the props for `createFormComponent()`
  - Updated the `Form_test.js` to import the default `validator` and the `customizeValidator()` function and passed `validator` into props for `<Form>...</Form>`
    - Updated the checking of `onChangeProp` to add `schemaValidationErrors`, `schemaValidationErrorSchema` and `schemaUtils` to the `calledWith()` check
    - Updated the checking of `onError` to add `schemaValidationErrors`, `schemaValidationErrorSchema` to the match
    - Deleted any tests that dealt with the now removed deprecated features
    - Replaced tests the used the `customFormats` or `additionalMetaSchemas` props with a customized validator with those values set on it
      - In one place, removed a piece of a test that was reverting the old props since they don't exist anymore
  - Updated the `SchemaField_test.js` file to check the `registry` in the received props to have `schemaUtils` instead of `definitions`
    - Fixed the import of `getDefaultRegistry()`
    - Also removed the test related to `empty definitions` since that isn't in the registry anymore
  - Updated the `StringField_test.js` to import the utility functions from `@rjsf/utils`
  - Updated the `uiSchema_test.js` file to deal with the removal of deprecated `ui:widget: {component, options}` feature in `@rjsf/utils`
    - Switched from `warn` to `error` for spying
    - Removed the deprecated `ui:widget` configurations in the tests, moving the options into the `ui:options` block instead`
    - Verified the proper error (instead of warning) is returned
- Switched `SubmitButton` to use `WidgetProps`
- Removed `schemaUtils` as a param for `getDefaultRegistry()`
- Set generic defaults on `WithThemeProps`
- Fixed cast of `SubmitButton` in `Form`
@nickgros
Copy link
Contributor

Looks like the lockfile went back to version 1, can you keep it at version 2? Think it has to do with your local version of node/npm

@heath-freenome
Copy link
Member Author

heath-freenome commented Jul 13, 2022

Looks like the lockfile went back to version 1, can you keep it at version 2? Think it has to do with your local version of node/npm

@nickgros I am planning on getting node 16 working in the v5 release, which would involve updating all the package-lock.json files with the latest NPM... is it ok to defer restoring the package-lock.json until then?

@nickgros
Copy link
Contributor

Sounds good.

@heath-freenome
Copy link
Member Author

Closing because these changes were merged as part of #2920

@heath-freenome heath-freenome deleted the update-core-to-use-utils-and-validator branch July 28, 2022 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants