Skip to content

Commit e1aa673

Browse files
Feature - Prep work for new feature in 4736 (#4776)
* Fix 4772 by always generating the outer grid regardless of the number of properties Fixed #4772 by always genering the outer grid - Updated `chakra-ui`'s `ObjectFieldTemplate` to render the outer `Grid` regardless of the number of properties - Updated the `CHANGELOG.md` accordingly * Feature - Prep work for new feature in 4736 Breaking change refactoring in preparation for the feature in 4736 - In `@rjsf/utils`: - Added new `GlobalFormOptions`, refactoring the `experimental_componentUpdateStrategy` from `Registry` and `idPrefix` & `idSeparator` from `FieldProps` - Replaced the `experimental_componentUpdateStrategy` prop in `Registry` with `readonly globalFormOptions?: GlobalFormOptions` - Updated `FieldProps` to remove `idPrefix` and `idSeparator` - In `@rjsf/core`: - Updated `Form` to add the `globalFormOptions` to the registry if there are any `GlobalFormOptions` values provided - Updated `ArrayField`, `LayoutGridField`, `ObjectField` and `SchemaField` to get `idPrefix`, `idSeparator` from the `registry.globalFormOptions`, no longer passing them on `FieldProps` - Updated `SchemaField` to get `experimental_componentUpdateStrategy` from the `registry.globalFormOptions` as well - Updated the `SchemaField` tests as needed - In `@rjsf/daisy` updated the snapshots - Updated the `custom-widget-fields.md` and `v6.x upgrade guide.md` to document the refactor of the `idPrefix` and `idSeparator` refactor - Updated the `CHANGELOG.md` file accordingly * - Responded to reviewer feedback * - Improved documentation * - Responded to more feedback
1 parent 36908df commit e1aa673

File tree

19 files changed

+233
-176
lines changed

19 files changed

+233
-176
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ should change the heading of the (upcoming) version to include a major version b
2525

2626
- Updated `ObjectField` to remove the `name` from the path passed to `onChange()` callback in `handleAddClick()` and `onDropPropertyClick()`, fixing [#4763](https://github.com/rjsf-team/react-jsonschema-form/issues/4763)
2727
- Updated `Form` to restore the passing of an empty string for `name` to avoid accidentally showing it as the title for the whole schema
28+
- Updated `Form` to add the `globalFormOptions` to the `registry` when there are `GlobalFormOptions` provided, also stopped passing `idPrefix` and `idSeparator` to `SchemaField`
29+
- Updated `ArrayField`, `LayoutGridField`, `ObjectField` and `SchemaField` to get `idPrefix`, `idSeparator` from the `registry.globalFormOptions`, no longer passing them on `FieldProps`
30+
- Updated `SchemaField` to get `experimental_componentUpdateStrategy` from the `registry.globalFormOptions` as well
2831

2932
## @rjsf/shadcn
3033

@@ -33,6 +36,13 @@ should change the heading of the (upcoming) version to include a major version b
3336
## @rjsf/utils
3437

3538
- Update `getDefaultFormState()` to add support for `null` defaults for `["null", "object"]` and `["null", "array"]`, fixing [#1581](https://github.com/rjsf-team/react-jsonschema-form/issues/1581)
39+
- Added a new `GlobalFormProps` interface which contains the following props and replaced the `experimental_componentUpdateStrategy` in `Registry` with `globalFormProps?: GlobalFormProps`
40+
- `experimental_componentUpdateStrategy` (refactored from `Registry`) and `idPrefix` & `idSeparator` (refactored from `FieldProps`)
41+
- BREAKING CHANGE: Removed the optional `idPrefix` and `idSeparator` props from the `FieldProps` interface
42+
43+
## Dev / docs / playground
44+
45+
- Updated the `custom-widget-fields.md` and `v6.x upgrade guide.md` to document the refactor of the `idPrefix` and `idSeparator` refactor
3646

3747
# 6.0.0-beta.16
3848

packages/core/src/components/Form.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import _forEach from 'lodash/forEach';
4343
import _get from 'lodash/get';
4444
import _isEmpty from 'lodash/isEmpty';
4545
import _isNil from 'lodash/isNil';
46+
import _omitBy from 'lodash/omitBy';
4647
import _pick from 'lodash/pick';
4748
import _set from 'lodash/set';
4849
import _toPath from 'lodash/toPath';
@@ -956,10 +957,14 @@ export default class Form<
956957
const {
957958
translateString: customTranslateString,
958959
uiSchema = {},
959-
experimental_componentUpdateStrategy = 'customDeep',
960+
experimental_componentUpdateStrategy,
961+
idSeparator,
962+
idPrefix,
960963
} = this.props;
961964
const { schema, schemaUtils } = this.state;
962965
const { fields, templates, widgets, formContext, translateString } = getDefaultRegistry<T, S, F>();
966+
// Omit any options that are undefined or null
967+
const globalFormOptions = _omitBy({ idPrefix, idSeparator, experimental_componentUpdateStrategy }, _isNil);
963968
return {
964969
fields: { ...fields, ...this.props.fields },
965970
templates: {
@@ -976,7 +981,7 @@ export default class Form<
976981
schemaUtils,
977982
translateString: customTranslateString || translateString,
978983
globalUiOptions: uiSchema[UI_GLOBAL_OPTIONS_KEY],
979-
experimental_componentUpdateStrategy,
984+
globalFormOptions,
980985
};
981986
}
982987

@@ -1101,8 +1106,6 @@ export default class Form<
11011106
const {
11021107
children,
11031108
id,
1104-
idPrefix = '',
1105-
idSeparator,
11061109
className = '',
11071110
tagName,
11081111
name,
@@ -1158,8 +1161,6 @@ export default class Form<
11581161
uiSchema={uiSchema}
11591162
errorSchema={errorSchema}
11601163
idSchema={idSchema}
1161-
idPrefix={idPrefix}
1162-
idSeparator={idSeparator}
11631164
formData={formData}
11641165
onChange={this.onChange}
11651166
onBlur={this.onBlur}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,12 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
511511
registry,
512512
onBlur,
513513
onFocus,
514-
idPrefix,
515-
idSeparator = '_',
516514
rawErrors,
517515
} = this.props;
518516
const { keyedFormData } = this.state;
519517
const fieldTitle = schema.title || title || name;
520-
const { schemaUtils, formContext } = registry;
518+
const { schemaUtils, formContext, globalFormOptions } = registry;
519+
const { idPrefix, idSeparator = '_' } = globalFormOptions;
521520
const uiOptions = getUiOptions<T[], S, F>(uiSchema);
522521
const _schemaItems: S = isObject(schema.items) ? (schema.items as S) : ({} as S);
523522
const itemsSchema: S = schemaUtils.retrieveSchema(_schemaItems);
@@ -735,8 +734,6 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
735734
uiSchema = {},
736735
formData = [],
737736
errorSchema,
738-
idPrefix,
739-
idSeparator = '_',
740737
idSchema,
741738
name,
742739
title,
@@ -753,7 +750,8 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
753750
let { formData: items = [] } = this.props;
754751
const fieldTitle = schema.title || title || name;
755752
const uiOptions = getUiOptions<T[], S, F>(uiSchema);
756-
const { schemaUtils, formContext } = registry;
753+
const { schemaUtils, formContext, globalFormOptions } = registry;
754+
const { idPrefix, idSeparator = '_' } = globalFormOptions;
757755
const _schemaItems: S[] = isObject(schema.items) ? (schema.items as S[]) : ([] as S[]);
758756
const itemSchemas = _schemaItems.map((item: S, index: number) =>
759757
schemaUtils.retrieveSchema(item, formData[index] as unknown as T[]),
@@ -884,7 +882,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
884882
totalItems,
885883
title,
886884
} = props;
887-
const { disabled, hideError, idPrefix, idSeparator, readonly, uiSchema, registry, formContext } = this.props;
885+
const { disabled, hideError, readonly, uiSchema, registry, formContext } = this.props;
888886
const {
889887
fields: { ArraySchemaField, SchemaField },
890888
globalUiOptions,
@@ -911,8 +909,6 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
911909
formData={itemData}
912910
formContext={formContext}
913911
errorSchema={itemErrorSchema}
914-
idPrefix={idPrefix}
915-
idSeparator={idSeparator}
916912
idSchema={itemIdSchema}
917913
required={this.isItemRequired(itemSchema)}
918914
onChange={this.onChangeForIndex(index)}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,11 @@ export default class LayoutGridField<
897897
formData,
898898
readonly,
899899
registry,
900-
idSeparator,
901900
layoutGridSchema, // Used to pull this out of otherProps since we don't want to pass it through
902901
...otherProps
903902
} = this.props;
904-
const { fields, schemaUtils } = registry;
903+
const { fields, schemaUtils, globalFormOptions } = registry;
904+
const { idSeparator } = globalFormOptions;
905905
const { SchemaField, LayoutMultiSchemaField } = fields;
906906
const uiComponentProps = LayoutGridField.computeUIComponentPropsFromGridSchema(registry, gridSchema);
907907
if (uiComponentProps.rendered) {
@@ -953,7 +953,6 @@ export default class LayoutGridField<
953953
uiSchema={fieldUiSchema}
954954
errorSchema={get(errorSchema, name)}
955955
idSchema={fieldIdSchema}
956-
idSeparator={idSeparator}
957956
formData={get(formData, name)}
958957
onChange={this.onFieldChange(name)}
959958
onBlur={onBlur}
@@ -977,7 +976,6 @@ export default class LayoutGridField<
977976
uiSchema={uiSchema}
978977
schema={initialSchema}
979978
idSchema={idSchema}
980-
idSeparator={idSeparator}
981979
onBlur={onBlur}
982980
onFocus={onFocus}
983981
registry={registry}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
237237
disabled,
238238
readonly,
239239
hideError,
240-
idPrefix,
241-
idSeparator,
242240
onBlur,
243241
onFocus,
244242
registry,
@@ -292,8 +290,6 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
292290
uiSchema={fieldUiSchema}
293291
errorSchema={get(errorSchema, name)}
294292
idSchema={fieldIdSchema}
295-
idPrefix={idPrefix}
296-
idSeparator={idSeparator}
297293
formData={get(formData, name)}
298294
formContext={formContext}
299295
wasPropertyKeyModified={this.state.wasPropertyKeyModified}

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
110110
uiSchema,
111111
formData,
112112
errorSchema,
113-
idPrefix,
114-
idSeparator,
115113
name,
116114
onChange,
117115
onKeyChange,
@@ -120,7 +118,8 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
120118
registry,
121119
wasPropertyKeyModified = false,
122120
} = props;
123-
const { formContext, schemaUtils, globalUiOptions } = registry;
121+
const { formContext, schemaUtils, globalUiOptions, globalFormOptions } = registry;
122+
const { idPrefix, idSeparator } = globalFormOptions;
124123
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
125124
const FieldTemplate = getTemplate<'FieldTemplate', T, S, F>('FieldTemplate', registry, uiOptions);
126125
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
@@ -291,9 +290,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
291290
errorSchema={errorSchema}
292291
formData={formData}
293292
formContext={formContext}
294-
idPrefix={idPrefix}
295293
idSchema={idSchema}
296-
idSeparator={idSeparator}
297294
onBlur={props.onBlur}
298295
onChange={props.onChange}
299296
onFocus={props.onFocus}
@@ -315,9 +312,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
315312
errorSchema={errorSchema}
316313
formData={formData}
317314
formContext={formContext}
318-
idPrefix={idPrefix}
319315
idSchema={idSchema}
320-
idSeparator={idSeparator}
321316
onBlur={props.onBlur}
322317
onChange={props.onChange}
323318
onFocus={props.onFocus}
@@ -342,7 +337,10 @@ class SchemaField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
342337
FieldProps<T, S, F>
343338
> {
344339
shouldComponentUpdate(nextProps: Readonly<FieldProps<T, S, F>>) {
345-
const { experimental_componentUpdateStrategy = 'customDeep' } = this.props.registry;
340+
const {
341+
registry: { globalFormOptions },
342+
} = this.props;
343+
const { experimental_componentUpdateStrategy = 'customDeep' } = globalFormOptions;
346344

347345
return shouldRender(this, nextProps, this.state, experimental_componentUpdateStrategy);
348346
}

packages/core/src/getDefaultRegistry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export default function getDefaultRegistry<
2020
rootSchema: {} as S,
2121
formContext: {} as F,
2222
translateString: englishStringTranslator,
23+
globalFormOptions: {},
2324
};
2425
}

packages/core/test/SchemaField.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('SchemaField', () => {
5252
schemaUtils,
5353
translateString: englishStringTranslator,
5454
globalUiOptions: undefined,
55-
experimental_componentUpdateStrategy: 'customDeep',
55+
globalFormOptions: {},
5656
});
5757
});
5858
it('should provide expected registry with globalUiOptions as prop', () => {
@@ -87,7 +87,7 @@ describe('SchemaField', () => {
8787
schemaUtils,
8888
translateString: englishStringTranslator,
8989
globalUiOptions: { copyable: true },
90-
experimental_componentUpdateStrategy: 'customDeep',
90+
globalFormOptions: {},
9191
});
9292
});
9393
});

packages/core/test/testData/getTestRegistry.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ export default function getTestRegistry(
2222
rootSchema,
2323
schemaUtils,
2424
translateString: englishStringTranslator,
25+
globalFormOptions: {},
2526
};
2627
}

packages/daisyui/jest.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"coveragePathIgnorePatterns": ["/node_modules/", "/test/"],
88
"transformIgnorePatterns": [
9-
"/node_modules/(?!(@rjsf|@epicfaace|@fortawesome|@coreui|yup|react-day-picker|dayjs|deep-freeze-es6)/)"
9+
"/node_modules/(?!(@fortawesome|yup|react-day-picker|dayjs|deep-freeze-es6)/)"
1010
],
1111
"moduleNameMapper": {
1212
"\\.(css|less|scss|sass)$": "<rootDir>/test/fileMock.js"

0 commit comments

Comments
 (0)