Skip to content

Commit c53c7f5

Browse files
Moved changes to CHANGELOG_v6.md
1 parent 01969f9 commit c53c7f5

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

CHANGELOG.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ should change the heading of the (upcoming) version to include a major version b
1616
1717
-->
1818

19-
# 6.0.0
20-
21-
## @rjsf/core
22-
23-
- Add support for `patternProperties` [#1944](https://github.com/rjsf-team/react-jsonschema-form/issues/1944)
24-
25-
## @rjsf/utils
26-
27-
- Add support for `patternProperties` [#1944](https://github.com/rjsf-team/react-jsonschema-form/issues/1944)
28-
2919
# 5.24.9
3020

3121
## @rjsf/antd

CHANGELOG_v6.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ should change the heading of the (upcoming) version to include a major version b
4848
- BREAKING CHANGE: Moved the addition of `Bootstrap 3` classes from the `SchemaField` to the `WrapIfAdditionalTemplate`, thereby affecting all the other themes, fixing [#2280](https://github.com/rjsf-team/react-jsonschema-form/issues/2280)
4949
- BREAKING CHANGE: Added `rjsf-` prefix onto the following marker classes used in the fields and templates:
5050
- `field`, `field-<schema.type>`, `field-error`, `field-hidden`, `field-array`, `field-array-of-<schema.type>`, `field-array-fixed-items`, `array-item`, `config-error`, `array-item-add`, `array-item-copy`, `array-item-move-down`, `array-item-move-up`, `array-item-remove`, `object-property-expand`
51+
- Added support for `patternProperties` [#1944](https://github.com/rjsf-team/react-jsonschema-form/issues/1944)
5152

5253
## @rjsf/daisyui
5354

@@ -111,6 +112,7 @@ should change the heading of the (upcoming) version to include a major version b
111112
- BREAKING CHANGE: Removed the deprecated `toErrorList()` function from the `ValidatorType` interface
112113
- BREAKING CHANGE: Removed the deprecated `RJSF_ADDITONAL_PROPERTIES_FLAG` constant
113114
- Updated the `WrapIfAdditionalTemplateProps` to include `hideError` and `rawErrors` in support of moving `Bootstrap 3` marker classes out of `SchemaField`
115+
- Added support for `patternProperties` [#1944](https://github.com/rjsf-team/react-jsonschema-form/issues/1944)
114116

115117
## @rjsf/validator-ajv6
116118

@@ -130,6 +132,7 @@ should change the heading of the (upcoming) version to include a major version b
130132
- Updated the `playground` to add a `Layout Grid` example and made the selected example now be part of the shared export
131133
- Replaced Lerna with Nx, updated all lerna commands to use the Nx CLI
132134
- BREAKING CHANGE: Updated all `peerDependencies` to change minimal `React` support to `>=18`
135+
- Added documentation and playground example for `patternProperties`
133136

134137
# 6.0.0-alpha.0
135138

packages/core/src/components/fields/ObjectField.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,14 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
195195
* @param schema - The schema element to which the new property is being added
196196
*/
197197
handleAddClick = (schema: S) => () => {
198-
if (!(schema.patternProperties || schema.additionalProperties)) {
198+
if (!(schema.additionalProperties || schema.patternProperties)) {
199199
return;
200200
}
201201
const { formData, onChange, registry } = this.props;
202202
const newFormData = { ...formData } as T;
203203
const newKey = this.getAvailableKey('newKey', newFormData);
204204
if (schema.patternProperties) {
205+
// Cast this to make the `set` work properly
205206
set(newFormData as GenericObjectType, newKey, null);
206207
} else {
207208
let type: RJSFSchema['type'] = undefined;

packages/utils/src/schema/retrieveSchema.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from '../types';
3636
import getFirstMatchingOption from './getFirstMatchingOption';
3737
import deepEquals from '../deepEquals';
38+
import isEmpty from 'lodash/isEmpty';
3839

3940
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
4041
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
@@ -187,6 +188,27 @@ export function getAllPermutationsOfXxxOf<S extends StrictRJSFSchema = RJSFSchem
187188
return allPermutations;
188189
}
189190

191+
/** Returns the subset of 'patternProperties' specifications that match the given 'key'
192+
*
193+
* @param schema - The schema whose 'patternProperties' are to be filtered
194+
* @param key - The key to match against the 'patternProperties' specifications
195+
* @returns - The subset of 'patternProperties' specifications that match the given 'key'
196+
*/
197+
export function getMatchingPatternProperties<S extends StrictRJSFSchema = RJSFSchema>(
198+
schema: S,
199+
key: string,
200+
): S['patternProperties'] {
201+
return Object.keys(schema.patternProperties!)
202+
.filter((pattern) => RegExp(pattern).test(key))
203+
.reduce(
204+
(obj, pattern) => {
205+
obj[pattern] = schema.patternProperties![pattern];
206+
return obj;
207+
},
208+
{} as S['patternProperties'],
209+
);
210+
}
211+
190212
/** Resolves references and dependencies within a schema and its 'allOf' children. Passes the `expandAllBranches` flag
191213
* down to the `retrieveSchemaInternal()`, `resolveReference()` and `resolveDependencies()` helper calls. If
192214
* `expandAllBranches` is true, then all possible dependencies and/or allOf branches are returned.
@@ -397,16 +419,11 @@ export function stubExistingAdditionalProperties<
397419
return;
398420
}
399421
if (PATTERN_PROPERTIES_KEY in schema) {
400-
const patternProperties = Object.keys(schema.patternProperties!)
401-
.filter((pattern) => RegExp(pattern).test(key))
402-
.reduce((obj, pattern) => {
403-
obj[pattern] = schema.patternProperties![pattern];
404-
return obj;
405-
}, {} as NonNullable<S['patternProperties']>);
406-
if (Object.keys(patternProperties).length > 0) {
422+
const matchingProperties = getMatchingPatternProperties(schema, key);
423+
if (!isEmpty(matchingProperties)) {
407424
schema.properties[key] = retrieveSchema<T, S, F>(
408425
validator,
409-
{ allOf: Object.values(patternProperties) } as S,
426+
{ allOf: Object.values(matchingProperties) } as S,
410427
rootSchema,
411428
formData as T,
412429
experimental_customMergeAllOf,
@@ -424,7 +441,7 @@ export function stubExistingAdditionalProperties<
424441
{ $ref: get(schema.additionalProperties, [REF_KEY]) } as S,
425442
rootSchema,
426443
formData as T,
427-
experimental_customMergeAllOf
444+
experimental_customMergeAllOf,
428445
);
429446
} else if ('type' in schema.additionalProperties!) {
430447
additionalProperties = { ...schema.additionalProperties };
@@ -545,27 +562,22 @@ export function retrieveSchemaInternal<
545562
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
546563
resolvedSchema = Object.keys(resolvedSchema.properties!).reduce(
547564
(schema, key) => {
548-
const patternProperties = Object.keys(schema.patternProperties!)
549-
.filter((pattern) => RegExp(pattern).test(key))
550-
.reduce((obj, pattern) => {
551-
obj[pattern] = schema.patternProperties![pattern];
552-
return obj;
553-
}, {} as NonNullable<S['patternProperties']>);
554-
if (Object.keys(patternProperties).length > 0) {
565+
const matchingProperties = getMatchingPatternProperties(schema, key);
566+
if (!isEmpty(matchingProperties)) {
555567
schema.properties[key] = retrieveSchema<T, S, F>(
556568
validator,
557-
{ allOf: [schema.properties[key], ...Object.values(patternProperties)] } as S,
569+
{ allOf: [schema.properties[key], ...Object.values(matchingProperties)] } as S,
558570
rootSchema,
559571
rawFormData as T,
560-
experimental_customMergeAllOf
572+
experimental_customMergeAllOf,
561573
);
562574
}
563575
return schema;
564576
},
565577
{
566578
...resolvedSchema,
567579
properties: { ...resolvedSchema.properties },
568-
}
580+
},
569581
);
570582
}
571583
const hasAdditionalProperties =

0 commit comments

Comments
 (0)