Skip to content

Commit 349aa72

Browse files
Add LayoutGridField and LayoutMultiSchemaField (#4506)
* Add LayoutGridField and LayoutMultiSchemaField Added new `LayoutGridField` and `LayoutMultiSchemaField` with updates to `utils` to support them - Updated `@rjsf/utils` to support the new fields as follows: - Updated the `UIOptionsBaseType` to add the optional `optionsSchemaSelector?: string` prop - Updated `getDiscriminatorFieldFromSchema()` to use the `DISCRIMINATOR_PATH` constant - Updated `hashForSchema.ts` to expose the `sortedJSONStringify()` method adding it to the `index.ts` export - Also added unit tests for the exposed method - Updated `getTestIds()` to read the `NODE_ENV` from the `process.env` via lodash `get()` to avoid odd bug - Updated `optionsList()` to switch the order of the generics and to add support for drilling into a `anyOf/oneOf` schema with a discriminator or a `optionsSchemaSelector` - This resulted in a few updates to other methods - Updated the tests to match the new capabilities - Updated `findSelectedOptionInXxxOf()` to use `getDiscriminatorFieldFromSchema()` rather than `DISCRIMINATOR_PATH` - Updated `ensureFormDataMatchingSchema()` to add the missing generics on the functions that have them - In `rjsf/core` : - Updated `package.json` to add the necessary `@testing-library` packages needed for the new components tests - Updated `ArrayField`, `BooleanField` and `StringField` to fix the order of the generics for `optionsList()` - Updated `RadioWidget` to add `radiogroup` role and `SelectWidget` to add the `combobox` role - Added the `LayoutGridField` and `LayoutMultiSchemaField` to the `fields` and added full `@testing-library` tests for them - Updated the snapshots due to the `role` changes to the two widgets - Updated the `utility-functions.md` to add `sortedJSONStringify()` docs and updated the `optionsList()` docs - Updated the `v6.x upgrade guide.md` to add breaking changes for `optionsList()` and adding the new `sortedJSONStringify()` * - Added `@babel/plugin-transform-class-static-block` to support testing * - Fixed build due to incorrect casing on import * - Responded to self-review * - Responded to reviewer feedback * - Fixed the name of the LAYOUT_GRID_UI_OPTION in the source and tests
1 parent 19e143c commit 349aa72

32 files changed

+4046
-337
lines changed

babel.config.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ module.exports = {
99
],
1010
'@babel/preset-typescript',
1111
],
12-
plugins: ['@babel/plugin-proposal-class-properties', '@babel/plugin-proposal-optional-chaining'],
12+
plugins: [
13+
'@babel/plugin-proposal-class-properties',
14+
'@babel/plugin-proposal-optional-chaining',
15+
'@babel/plugin-transform-class-static-block',
16+
],
1317
};

package-lock.json

+177-283
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"homepage": "https://github.com/rjsf-team/react-jsonschema-form",
3333
"devDependencies": {
3434
"@babel/eslint-parser": "^7.23.10",
35+
"@babel/plugin-transform-class-static-block": "^7.26.0",
3536
"@nrwl/nx-cloud": "^15.3.5",
3637
"@testing-library/jest-dom": "^6.4.2",
3738
"@testing-library/react": "^14.2.1",

packages/core/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
"@rjsf/snapshot-tests": "^6.0.0-alpha.0",
5858
"@rjsf/utils": "^6.0.0-alpha.0",
5959
"@rjsf/validator-ajv8": "^6.0.0-alpha.0",
60+
"@testing-library/jest-dom": "^6.6.3",
61+
"@testing-library/react": "^16.2.0",
62+
"@testing-library/user-event": "^14.6.1",
6063
"@types/jest": "^29.5.12",
6164
"@types/lodash": "^4.14.202",
6265
"@types/react": "^18.2.58",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
612612
} = this.props;
613613
const { widgets, schemaUtils, formContext, globalUiOptions } = registry;
614614
const itemsSchema = schemaUtils.retrieveSchema(schema.items as S, items);
615-
const enumOptions = optionsList<S, T[], F>(itemsSchema, uiSchema);
615+
const enumOptions = optionsList<T[], S, F>(itemsSchema, uiSchema);
616616
const { widget = 'select', title: uiTitle, ...options } = getUiOptions<T[], S, F>(uiSchema, globalUiOptions);
617617
const Widget = getWidget<T[], S, F>(schema, widget, widgets);
618618
const label = uiTitle ?? schema.title ?? name;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
5252
let enumOptions: EnumOptionsType<S>[] | undefined;
5353
const label = uiTitle ?? schemaTitle ?? title ?? name;
5454
if (Array.isArray(schema.oneOf)) {
55-
enumOptions = optionsList<S, T, F>(
55+
enumOptions = optionsList<T, S, F>(
5656
{
5757
oneOf: schema.oneOf
5858
.map((option) => {
@@ -84,7 +84,7 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
8484
},
8585
];
8686
} else {
87-
enumOptions = optionsList<S, T, F>(
87+
enumOptions = optionsList<T, S, F>(
8888
{
8989
enum: enums,
9090
// NOTE: enumNames is deprecated, but still supported for now.

0 commit comments

Comments
 (0)