Skip to content

Commit

Permalink
fix: Fix #3391 and #3393 (#3408)
Browse files Browse the repository at this point in the history
* fix: Fix 3391 by restoring creation of empty root objects
Fixes #3391 by adding the `excludeObjectChildren` third parameter to the main `getDefaultFormState()`

* - Fixes #3393 by properly deduplicating when `schema.default` exists in `schema.examples`

* - Fix security warning to add newer versions and to unsupport old ones
  • Loading branch information
heath-freenome committed Jan 27, 2023
1 parent 87a9bec commit 2e96fe2
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 25 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Expand Up @@ -17,8 +17,32 @@ should change the heading of the (upcoming) version to include a major version b
-->
# 5.0.0

## @rjsf/antd
- Fixed `schema.examples` to deduplicate when `schema.default` exists in the examples, fixing [#3393](https://github.com/rjsf-team/react-jsonschema-form/issues/3393)

## @rjsf/bootstrap-4
- Fixed `schema.examples` to deduplicate when `schema.default` exists in the examples, fixing [#3393](https://github.com/rjsf-team/react-jsonschema-form/issues/3393)

## @rjsf/chakra-ui
- Fixed `schema.examples` to deduplicate when `schema.default` exists in the examples, fixing [#3393](https://github.com/rjsf-team/react-jsonschema-form/issues/3393)

## @rjsf/core
- Updated `MultiSchemaField` to pass `undefined` as the value to the widget when the `selectedOption` is -1, supporting `SelectWidget` implementations that allow the user to clear the selected value of the `anyOf`/`oneOf` field.
- Updated `Form` to support receiving an optional `ref` prop.
- Updated `Form` to restore providing empty root level objects, fixing [#3391](https://github.com/rjsf-team/react-jsonschema-form/issues/3391)
- Fixed `schema.examples` to deduplicate when `schema.default` exists in the examples, fixing [#3393](https://github.com/rjsf-team/react-jsonschema-form/issues/3393)

## @rjsf/fluent-ui
- Fixed `schema.examples` to deduplicate when `schema.default` exists in the examples, fixing [#3393](https://github.com/rjsf-team/react-jsonschema-form/issues/3393)

## @rjsf/material-ui
- Fixed `schema.examples` to deduplicate when `schema.default` exists in the examples, fixing [#3393](https://github.com/rjsf-team/react-jsonschema-form/issues/3393)

## @rjsf/mui
- Fixed `schema.examples` to deduplicate when `schema.default` exists in the examples, fixing [#3393](https://github.com/rjsf-team/react-jsonschema-form/issues/3393)

## @rjsf/semantic-ui
- Fixed `schema.examples` to deduplicate when `schema.default` exists in the examples, fixing [#3393](https://github.com/rjsf-team/react-jsonschema-form/issues/3393)

# 5.0.0-beta.19

Expand Down
9 changes: 6 additions & 3 deletions SECURITY.md
Expand Up @@ -3,9 +3,12 @@
## Supported Versions

| Version | Supported |
| ------- | ------------------ |
| 2.x | :white_check_mark: |
| 1.x | :white_check_mark: |
|---------|--------------------|
| 5.x | :white_check_mark: |
| 4.x | :warning: |
| 3.x | :x: |
| 2.x | :x: |
| 1.x | :x: |


## Reporting a Vulnerability
Expand Down
8 changes: 6 additions & 2 deletions packages/antd/src/templates/BaseInputTemplate/index.tsx
Expand Up @@ -91,10 +91,14 @@ export default function BaseInputTemplate<
return (
<>
{input}
{schema.examples && (
{Array.isArray(schema.examples) && (
<datalist id={examplesId<T>(id)}>
{(schema.examples as string[])
.concat(schema.default ? ([schema.default] as string[]) : [])
.concat(
schema.default && !schema.examples.includes(schema.default)
? ([schema.default] as string[])
: []
)
.map((example) => {
return <option key={example} value={example} />;
})}
Expand Down
Expand Up @@ -67,10 +67,14 @@ export default function BaseInputTemplate<
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
/>
{children}
{schema.examples ? (
{Array.isArray(schema.examples) ? (
<datalist id={examplesId<T>(id)}>
{(schema.examples as string[])
.concat(schema.default ? ([schema.default] as string[]) : [])
.concat(
schema.default && !schema.examples.includes(schema.default)
? ([schema.default] as string[])
: []
)
.map((example: any) => {
return <option key={example} value={example} />;
})}
Expand Down
Expand Up @@ -80,10 +80,14 @@ export default function BaseInputTemplate<
list={schema.examples ? examplesId<T>(id) : undefined}
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
/>
{schema.examples ? (
{Array.isArray(schema.examples) ? (
<datalist id={examplesId<T>(id)}>
{(schema.examples as string[])
.concat(schema.default ? ([schema.default] as string[]) : [])
.concat(
schema.default && !schema.examples.includes(schema.default)
? ([schema.default] as string[])
: []
)
.map((example: any) => {
return <option key={example} value={example} />;
})}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/components/Form.tsx
Expand Up @@ -321,7 +321,8 @@ export default class Form<
}
const formData: T = schemaUtils.getDefaultFormState(
schema,
inputFormData
inputFormData,
"excludeObjectChildren"
) as T;
const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);

Expand Down
16 changes: 9 additions & 7 deletions packages/core/src/components/templates/BaseInputTemplate.tsx
Expand Up @@ -92,13 +92,15 @@ export default function BaseInputTemplate<
/>
{Array.isArray(schema.examples) && (
<datalist key={`datalist_${id}`} id={examplesId<T>(id)}>
{[
...new Set(
schema.examples.concat(schema.default ? [schema.default] : [])
),
].map((example: any) => (
<option key={example} value={example} />
))}
{(schema.examples as string[])
.concat(
schema.default && !schema.examples.includes(schema.default)
? ([schema.default] as string[])
: []
)
.map((example: any) => {
return <option key={example} value={example} />;
})}
</datalist>
)}
</>
Expand Down
Expand Up @@ -111,10 +111,14 @@ export default function BaseInputTemplate<
{...uiProps}
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
/>
{schema.examples && (
{Array.isArray(schema.examples) && (
<datalist id={examplesId<T>(id)}>
{(schema.examples as string[])
.concat(schema.default ? ([schema.default] as string[]) : [])
.concat(
schema.default && !schema.examples.includes(schema.default)
? ([schema.default] as string[])
: []
)
.map((example: any) => {
return <option key={example} value={example} />;
})}
Expand Down
Expand Up @@ -86,10 +86,14 @@ export default function BaseInputTemplate<
{...(textFieldProps as TextFieldProps)}
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
/>
{schema.examples && (
{Array.isArray(schema.examples) && (
<datalist id={examplesId<T>(id)}>
{(schema.examples as string[])
.concat(schema.default ? ([schema.default] as string[]) : [])
.concat(
schema.default && !schema.examples.includes(schema.default)
? ([schema.default] as string[])
: []
)
.map((example: any) => {
return <option key={example} value={example} />;
})}
Expand Down
8 changes: 6 additions & 2 deletions packages/mui/src/BaseInputTemplate/BaseInputTemplate.tsx
Expand Up @@ -86,10 +86,14 @@ export default function BaseInputTemplate<
{...(textFieldProps as TextFieldProps)}
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
/>
{schema.examples && (
{Array.isArray(schema.examples) && (
<datalist id={examplesId<T>(id)}>
{(schema.examples as string[])
.concat(schema.default ? ([schema.default] as string[]) : [])
.concat(
schema.default && !schema.examples.includes(schema.default)
? ([schema.default] as string[])
: []
)
.map((example: any) => {
return <option key={example} value={example} />;
})}
Expand Down
Expand Up @@ -78,10 +78,14 @@ export default function BaseInputTemplate<
onFocus={_onFocus}
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
/>
{schema.examples && (
{Array.isArray(schema.examples) && (
<datalist id={examplesId<T>(id)}>
{(schema.examples as string[])
.concat(schema.default ? ([schema.default] as string[]) : [])
.concat(
schema.default && !schema.examples.includes(schema.default)
? ([schema.default] as string[])
: []
)
.map((example) => {
return <option key={example} value={example} />;
})}
Expand Down

0 comments on commit 2e96fe2

Please sign in to comment.