Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ should change the heading of the (upcoming) version to include a major version b

- 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)
- Updated `Form` to restore the passing of an empty string for `name` to avoid accidentally showing it as the title for the whole schema
- Updated `Form` to add the `globalFormOptions` to the `registry` when there are `GlobalFormOptions` provided, also stopped passing `idPrefix` and `idSeparator` to `SchemaField`
- 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

## @rjsf/shadcn

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

- 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)
- Added a new `GlobalFormProps` interface which contains the following props and replaced the `experimental_componentUpdateStrategy` in `Registry` with `globalFormProps?: GlobalFormProps`
- `experimental_componentUpdateStrategy` (refactored from `Registry`) and `idPrefix` & `idSeparator` (refactored from `FieldProps`)
- BREAKING CHANGE: Removed the optional `idPrefix` and `idSeparator` props from the `FieldProps` interface

## Dev / docs / playground

- Updated the `custom-widget-fields.md` and `v6.x upgrade guide.md` to document the refactor of the `idPrefix` and `idSeparator` refactor

# 6.0.0-beta.16

Expand Down
13 changes: 7 additions & 6 deletions packages/core/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import _forEach from 'lodash/forEach';
import _get from 'lodash/get';
import _isEmpty from 'lodash/isEmpty';
import _isNil from 'lodash/isNil';
import _omitBy from 'lodash/omitBy';
import _pick from 'lodash/pick';
import _set from 'lodash/set';
import _toPath from 'lodash/toPath';
Expand Down Expand Up @@ -956,10 +957,14 @@ export default class Form<
const {
translateString: customTranslateString,
uiSchema = {},
experimental_componentUpdateStrategy = 'customDeep',
experimental_componentUpdateStrategy,
idSeparator,
idPrefix,
} = this.props;
const { schema, schemaUtils } = this.state;
const { fields, templates, widgets, formContext, translateString } = getDefaultRegistry<T, S, F>();
// Omit any options that are undefined or null
const globalFormOptions = _omitBy({ idPrefix, idSeparator, experimental_componentUpdateStrategy }, _isNil);
return {
fields: { ...fields, ...this.props.fields },
templates: {
Expand All @@ -976,7 +981,7 @@ export default class Form<
schemaUtils,
translateString: customTranslateString || translateString,
globalUiOptions: uiSchema[UI_GLOBAL_OPTIONS_KEY],
experimental_componentUpdateStrategy,
globalFormOptions,
};
}

Expand Down Expand Up @@ -1101,8 +1106,6 @@ export default class Form<
const {
children,
id,
idPrefix = '',
idSeparator,
className = '',
tagName,
name,
Expand Down Expand Up @@ -1158,8 +1161,6 @@ export default class Form<
uiSchema={uiSchema}
errorSchema={errorSchema}
idSchema={idSchema}
idPrefix={idPrefix}
idSeparator={idSeparator}
formData={formData}
onChange={this.onChange}
onBlur={this.onBlur}
Expand Down
14 changes: 5 additions & 9 deletions packages/core/src/components/fields/ArrayField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,12 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
registry,
onBlur,
onFocus,
idPrefix,
idSeparator = '_',
rawErrors,
} = this.props;
const { keyedFormData } = this.state;
const fieldTitle = schema.title || title || name;
const { schemaUtils, formContext } = registry;
const { schemaUtils, formContext, globalFormOptions } = registry;
const { idPrefix, idSeparator = '_' } = globalFormOptions;
const uiOptions = getUiOptions<T[], S, F>(uiSchema);
const _schemaItems: S = isObject(schema.items) ? (schema.items as S) : ({} as S);
const itemsSchema: S = schemaUtils.retrieveSchema(_schemaItems);
Expand Down Expand Up @@ -735,8 +734,6 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
uiSchema = {},
formData = [],
errorSchema,
idPrefix,
idSeparator = '_',
idSchema,
name,
title,
Expand All @@ -753,7 +750,8 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
let { formData: items = [] } = this.props;
const fieldTitle = schema.title || title || name;
const uiOptions = getUiOptions<T[], S, F>(uiSchema);
const { schemaUtils, formContext } = registry;
const { schemaUtils, formContext, globalFormOptions } = registry;
const { idPrefix, idSeparator = '_' } = globalFormOptions;
const _schemaItems: S[] = isObject(schema.items) ? (schema.items as S[]) : ([] as S[]);
const itemSchemas = _schemaItems.map((item: S, index: number) =>
schemaUtils.retrieveSchema(item, formData[index] as unknown as T[]),
Expand Down Expand Up @@ -884,7 +882,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
totalItems,
title,
} = props;
const { disabled, hideError, idPrefix, idSeparator, readonly, uiSchema, registry, formContext } = this.props;
const { disabled, hideError, readonly, uiSchema, registry, formContext } = this.props;
const {
fields: { ArraySchemaField, SchemaField },
globalUiOptions,
Expand All @@ -911,8 +909,6 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
formData={itemData}
formContext={formContext}
errorSchema={itemErrorSchema}
idPrefix={idPrefix}
idSeparator={idSeparator}
idSchema={itemIdSchema}
required={this.isItemRequired(itemSchema)}
onChange={this.onChangeForIndex(index)}
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/components/fields/LayoutGridField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -897,11 +897,11 @@ export default class LayoutGridField<
formData,
readonly,
registry,
idSeparator,
layoutGridSchema, // Used to pull this out of otherProps since we don't want to pass it through
...otherProps
} = this.props;
const { fields, schemaUtils } = registry;
const { fields, schemaUtils, globalFormOptions } = registry;
const { idSeparator } = globalFormOptions;
const { SchemaField, LayoutMultiSchemaField } = fields;
const uiComponentProps = LayoutGridField.computeUIComponentPropsFromGridSchema(registry, gridSchema);
if (uiComponentProps.rendered) {
Expand Down Expand Up @@ -953,7 +953,6 @@ export default class LayoutGridField<
uiSchema={fieldUiSchema}
errorSchema={get(errorSchema, name)}
idSchema={fieldIdSchema}
idSeparator={idSeparator}
formData={get(formData, name)}
onChange={this.onFieldChange(name)}
onBlur={onBlur}
Expand All @@ -977,7 +976,6 @@ export default class LayoutGridField<
uiSchema={uiSchema}
schema={initialSchema}
idSchema={idSchema}
idSeparator={idSeparator}
onBlur={onBlur}
onFocus={onFocus}
registry={registry}
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/components/fields/ObjectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
disabled,
readonly,
hideError,
idPrefix,
idSeparator,
onBlur,
onFocus,
registry,
Expand Down Expand Up @@ -292,8 +290,6 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
uiSchema={fieldUiSchema}
errorSchema={get(errorSchema, name)}
idSchema={fieldIdSchema}
idPrefix={idPrefix}
idSeparator={idSeparator}
formData={get(formData, name)}
formContext={formContext}
wasPropertyKeyModified={this.state.wasPropertyKeyModified}
Expand Down
14 changes: 6 additions & 8 deletions packages/core/src/components/fields/SchemaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
uiSchema,
formData,
errorSchema,
idPrefix,
idSeparator,
name,
onChange,
onKeyChange,
Expand All @@ -120,7 +118,8 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
registry,
wasPropertyKeyModified = false,
} = props;
const { formContext, schemaUtils, globalUiOptions } = registry;
const { formContext, schemaUtils, globalUiOptions, globalFormOptions } = registry;
const { idPrefix, idSeparator } = globalFormOptions;
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
const FieldTemplate = getTemplate<'FieldTemplate', T, S, F>('FieldTemplate', registry, uiOptions);
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
Expand Down Expand Up @@ -291,9 +290,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
errorSchema={errorSchema}
formData={formData}
formContext={formContext}
idPrefix={idPrefix}
idSchema={idSchema}
idSeparator={idSeparator}
onBlur={props.onBlur}
onChange={props.onChange}
onFocus={props.onFocus}
Expand All @@ -315,9 +312,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
errorSchema={errorSchema}
formData={formData}
formContext={formContext}
idPrefix={idPrefix}
idSchema={idSchema}
idSeparator={idSeparator}
onBlur={props.onBlur}
onChange={props.onChange}
onFocus={props.onFocus}
Expand All @@ -342,7 +337,10 @@ class SchemaField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
FieldProps<T, S, F>
> {
shouldComponentUpdate(nextProps: Readonly<FieldProps<T, S, F>>) {
const { experimental_componentUpdateStrategy = 'customDeep' } = this.props.registry;
const {
registry: { globalFormOptions },
} = this.props;
const { experimental_componentUpdateStrategy = 'customDeep' } = globalFormOptions;

return shouldRender(this, nextProps, this.state, experimental_componentUpdateStrategy);
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/getDefaultRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export default function getDefaultRegistry<
rootSchema: {} as S,
formContext: {} as F,
translateString: englishStringTranslator,
globalFormOptions: {},
};
}
4 changes: 2 additions & 2 deletions packages/core/test/SchemaField.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('SchemaField', () => {
schemaUtils,
translateString: englishStringTranslator,
globalUiOptions: undefined,
experimental_componentUpdateStrategy: 'customDeep',
globalFormOptions: {},
});
});
it('should provide expected registry with globalUiOptions as prop', () => {
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('SchemaField', () => {
schemaUtils,
translateString: englishStringTranslator,
globalUiOptions: { copyable: true },
experimental_componentUpdateStrategy: 'customDeep',
globalFormOptions: {},
});
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/testData/getTestRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export default function getTestRegistry(
rootSchema,
schemaUtils,
translateString: englishStringTranslator,
globalFormOptions: {},
};
}
2 changes: 1 addition & 1 deletion packages/daisyui/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"coveragePathIgnorePatterns": ["/node_modules/", "/test/"],
"transformIgnorePatterns": [
"/node_modules/(?!(@rjsf|@epicfaace|@fortawesome|@coreui|yup|react-day-picker|dayjs|deep-freeze-es6)/)"
"/node_modules/(?!(@fortawesome|yup|react-day-picker|dayjs|deep-freeze-es6)/)"
],
"moduleNameMapper": {
"\\.(css|less|scss|sass)$": "<rootDir>/test/fileMock.js"
Expand Down
Loading