You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixesrjsf-team#2944, rjsf-team#3236, rjsf-team#2978 and possibly others
- In `@rjsf/utils`, added new `getClosestMatchingOption()`, `getFirstMatchingOption()` and `sanitizeDataForNewSchema()` schema-based utility functions
- Deprecated `getMatchingOption()` and updated all calls to it in other utility functions to use `getFirstMatchingOption()`
- Added 100% unit tests for all new functions, renaming the old `getMatchingOptionsTest.ts` file to `getFirstMatchingOptionsTest.ts`
- Updated `createSchemaUtils()` and it's associated type to add the three new functions
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated the `schema.tests.ts` to add the new tests for the new schema-based utility functions
- In `@rjsf/core`, updated the `MultiSchemaField` to use the new `getClosestMatchingOption()` and `sanitizeDataForNewSchema()` utility functions
- Also updated the render to properly pass props to the widget and the schema field
- In `@rjsf/playground`, updated `onFormDataEdited()` to only change the formData in the state if the `JSON.stringify()` of the old and new values are different
- Also updated the `npm start` command to add the `--force` option to avoid issues where changes made to other packages weren't getting picked up due to `vite` caching
- Updated the `utility-functions.md` file to document the new schema-based functions and to fix up incorrect strike-through caused by the unescaped `<S>` generic
- Updated the `5.x upgrade guide.md` file to document the new utility functions and the deprecation of `getMatchingOption()`
Copy file name to clipboardExpand all lines: CHANGELOG.md
+14
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,20 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
15
15
should change the heading of the (upcoming) version to include a major version bump.
16
16
17
17
-->
18
+
# 5.0.0-beta-18
19
+
20
+
# @rjsf/core
21
+
- Updated `MultiSchemaField` to utilize the new `getClosestMatchingOption()` and `sanitizeDataForNewSchema()` functions, fixing [#2944](https://github.com/rjsf-team/react-jsonschema-form/issues/2944), [#3236](https://github.com/rjsf-team/react-jsonschema-form/issues/3236), [#2978](https://github.com/rjsf-team/react-jsonschema-form/issues/2978), and probably others
22
+
23
+
# @rjsf/utils
24
+
- Added new `getClosestMatchingOption()`, `getFirstMatchingOption()` and `sanitizeDataForNewSchema()` schema-based utility functions
25
+
- Deprecated `getMatchingOption()` and updated all calls to it in other utility functions to use `getFirstMatchingOption()`
26
+
27
+
## Dev / docs / playground
28
+
- Updated the playground to `onFormDataEdited()` to only change the formData in the state if the `JSON.stringify()` of the old and new values are different, partially fixing [#3236](https://github.com/rjsf-team/react-jsonschema-form/issues/3236)
29
+
- Updated the playground `npm start` command to always use the `--force` option to avoid issues where changes made to other packages weren't getting picked up due to `vite` caching
30
+
- Updated the documentation for `utility-functions` and the `5.x upgrade guide` to add the new utility functions and to document the deprecation of `getMatchingOption()`
Copy file name to clipboardExpand all lines: docs/5.x upgrade guide.md
+7-1
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Unfortunately, there is required work pending to properly support React 18, so u
27
27
There are four new packages added in RJSF version 5:
28
28
29
29
-`@rjsf/utils`: All of the [utility functions](https://react-jsonschema-form.readthedocs.io/en/stable/api-reference/utiltity-functions) previously imported from `@rjsf/core/utils` as well as the Typescript types for RJSF version 5.
30
-
- The following new utility functions were added: `createSchemaUtils()`, `getInputProps()`, `mergeValidationData()` and`processSelectValue()`
30
+
- The following new utility functions were added: `ariaDescribedByIds()`, `createSchemaUtils()`, `descriptionId()`, `enumOptionsDeselectValue()`, `enumOptionsSelectValue()`, `errorId()`, `examplesId()`, `getClosestMatchingOption()`, `getFirstMatchingOption()`, `getInputProps()`, `helpId()`, `mergeValidationData()`, `optionId()`,`processSelectValue()`, `sanitizeDataForNewSchema()` and `titleId()`
31
31
-`@rjsf/validator-ajv6`: The [ajv](https://github.com/ajv-validator/ajv)-v6-based validator refactored out of `@rjsf/[email protected]`, that implements the `ValidatorType` interface defined in `@rjsf/utils`.
32
32
-`@rjsf/validator-ajv8`: The [ajv](https://github.com/ajv-validator/ajv)-v8-based validator that is an upgrade of the `@rjsf/validator-ajv6`, that implements the `ValidatorType` interface defined in `@rjsf/utils`. See the ajv 6 to 8 [migration guide](https://ajv.js.org/v6-to-v8-migration.html) for more information.
33
33
-`@rjsf/mui`: Previously `@rjsf/material-ui/v5`, now provided as its own theme.
@@ -231,6 +231,7 @@ render((
231
231
In version 5, all the utility functions that were previously accessed via `import { utils } from '@rjsf/core';` are now available via `import utils from '@rjsf/utils';`.
232
232
Because of the decoupling of validation from `@rjsf/core` there is a breaking change for all the [validator-based utility functions](https://react-jsonschema-form.readthedocs.io/en/stable/api-reference/utiltity-functions#validator-based-utility-functions), since they now require an additional `ValidatorType` parameter.
233
233
More over, one previously exported function `resolveSchema()` is no longer exposed in the `@rjsf/utils`, so use `retrieveSchema()` instead.
234
+
Finally, one previously exported function `getMatchingOption()` deprecated in favor of `getFirstMatchingOption()`.
234
235
235
236
If you have built custom fields or widgets that utilized any of these breaking-change functions, don't worry, there is a quick and easy solution for you.
236
237
The `registry` has a breaking-change which removes the previously deprecated `definitions` property while adding the new `schemaUtils` property.
@@ -399,6 +402,9 @@ From v5, the child fields will correctly use the parent id when generating its o
399
402
400
403
#### Deprecations added in v5
401
404
405
+
##### getMatchingOption()
406
+
The utility function `getMatchingOption()` was deprecated in favor of the more aptly named `getFirstMatchingOption()` which has the exact same implementation.
407
+
402
408
##### Non-standard `enumNames` property
403
409
404
410
`enumNames` is a non-standard JSON Schema field that was deprecated in version 5.
- RJSFSchema: The schema having its conditions, additional properties, references and dependencies resolved
591
624
625
+
### sanitizeDataForNewSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>()
626
+
Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`.
627
+
If the new schema does not contain any properties, then `undefined` is returned to clear all the form data.
628
+
Due to the nature of schemas, this sanitization happens recursively for nested objects of data.
629
+
Also, any properties in the old schema that are non-existent in the new schema are set to `undefined`.
630
+
631
+
#### Parameters
632
+
- validator: ValidatorType<T, S, F> - An implementation of the `ValidatorType` interface that will be used when necessary
633
+
- rootSchema: S - The root JSON schema of the entire form
634
+
-[newSchema]: S - The new schema for which the data is being sanitized
635
+
-[oldSchema]: S - The old schema from which the data originated
636
+
-[data={}]: any - The form data associated with the schema, defaulting to an empty object when undefined
637
+
638
+
#### Returns
639
+
- T: The new form data, with all the fields uniquely associated with the old schema set to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
640
+
592
641
### toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>()
593
642
Generates an `IdSchema` object for the `schema`, recursively
0 commit comments