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

fix: #3239 by providing an ErrorSchemaBuilder class in @rjsf/utils #3307

Merged
merged 1 commit into from Dec 22, 2022

Conversation

heath-freenome
Copy link
Member

Reasons for making this change

fix: #3239 by providing a new ErrorSchemaBuilder class in @rjsf/utils

  • In @rjsf/utils added ErrorSchemaBuilder to facilitate building ErrorSchema objects without the need for fancy casting
    • Exported the new class as part of the main index.js
    • Added 100% unit tests
  • In @rjsf/validator-ajv6 and @rjsf/validator-ajv8 updated the toErrorSchema() function to use the ErrorSchemaBuilder to simplify the implementation
    • Also updated the tests to use the ErrorSchemaBuilder to replace the expected values that required doing as ErrorSchema casting
  • Updated the utility-functions.md file to document ErrorSchemaBuilder
  • Updated the CHANGELOG.md accordingly for this fix as well as PR fix(material-ui): fix RangeWidget onChange handler #2161 #3297

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

Copy link
Contributor

@nickgros nickgros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, much cleaner

});
});
it("setting error string list without a path replaces at the root", () => {
expect(builder.setErrors(SOME_ERRORS).ErrorSchema).toEqual({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am personally not a fan of relying on the order of the tests to validate behavior, and would rather we start from scratch in beforeEach

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the differences in behavior of the addErrors() and setErrors() it seemed easier to build the tests this way. Did you want me to change it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, I agree this is easier and less code for something simple like this builder. Just a feeler to see how strongly you might agree 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I'm ok with doing incremental testing like this when it makes sense. Your feeler has revealed I weakly agree with you :)

…/utils

fix: rjsf-team#3239 by providing a new `ErrorSchemaBuilder` class in `@rjsf/utils`
- In `@rjsf/utils` added `ErrorSchemaBuilder` to facilitate building `ErrorSchema` objects without the need for fancy casting
  - Exported the new class as part of the main `index.js`
  - Added 100% unit tests
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8` updated the `toErrorSchema()` function to use the `ErrorSchemaBuilder` to simplify the implementation
  - Also updated the tests to use the `ErrorSchemaBuilder` to replace the expected values that required doing `as ErrorSchema` casting
- Updated the `utility-functions.md` file to document `ErrorSchemaBuilder`
- Updated the `CHANGELOG.md` accordingly for this fix as well as PR rjsf-team#3297
@heath-freenome heath-freenome merged commit e35f61a into rjsf-team:main Dec 22, 2022
@heath-freenome heath-freenome deleted the fix-3239 branch December 22, 2022 18:06
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this pull request Jun 8, 2023
…/utils (rjsf-team#3307)

fix: rjsf-team#3239 by providing a new `ErrorSchemaBuilder` class in `@rjsf/utils`
- In `@rjsf/utils` added `ErrorSchemaBuilder` to facilitate building `ErrorSchema` objects without the need for fancy casting
  - Exported the new class as part of the main `index.js`
  - Added 100% unit tests
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8` updated the `toErrorSchema()` function to use the `ErrorSchemaBuilder` to simplify the implementation
  - Also updated the tests to use the `ErrorSchemaBuilder` to replace the expected values that required doing `as ErrorSchema` casting
- Updated the `utility-functions.md` file to document `ErrorSchemaBuilder`
- Updated the `CHANGELOG.md` accordingly for this fix as well as PR rjsf-team#3297
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this pull request Jun 8, 2023
…/utils (rjsf-team#3307)

fix: rjsf-team#3239 by providing a new `ErrorSchemaBuilder` class in `@rjsf/utils`
- In `@rjsf/utils` added `ErrorSchemaBuilder` to facilitate building `ErrorSchema` objects without the need for fancy casting
  - Exported the new class as part of the main `index.js`
  - Added 100% unit tests
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8` updated the `toErrorSchema()` function to use the `ErrorSchemaBuilder` to simplify the implementation
  - Also updated the tests to use the `ErrorSchemaBuilder` to replace the expected values that required doing `as ErrorSchema` casting
- Updated the `utility-functions.md` file to document `ErrorSchemaBuilder`
- Updated the `CHANGELOG.md` accordingly for this fix as well as PR rjsf-team#3297
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.

Broken ErrorSchema type-definition
2 participants