diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fa369e821..3bc0d0aec4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,10 +23,15 @@ should change the heading of the (upcoming) version to include a major version b - Added `getChakra` to package exports - Restored the `ui:options` customization +## @rjsf/core + +- Updated `LayoutGridField` to use the pre-existing `UI_GLOBAL_OPTIONS_KEY` instead of its own incorrect one. + ## @rjsf/util - Fixed form data propagation with `patternProperties` [#4617](https://github.com/rjsf-team/react-jsonschema-form/pull/4617) - Fixed issue where oneOf schema references could not be modified when defaults were set, fixing [#4580](https://github.com/rjsf-team/react-jsonschema-form/issues/4580). +- Updated the `GlobalUISchemaOptions` types to extend `GenericObjectType` to support user-defined values for their extensions ## Dev / docs / playground diff --git a/packages/core/src/components/fields/LayoutGridField.tsx b/packages/core/src/components/fields/LayoutGridField.tsx index 8d16618f9f..48776fc0dc 100644 --- a/packages/core/src/components/fields/LayoutGridField.tsx +++ b/packages/core/src/components/fields/LayoutGridField.tsx @@ -22,6 +22,7 @@ import { SchemaUtilsType, StrictRJSFSchema, UI_OPTIONS_KEY, + UI_GLOBAL_OPTIONS_KEY, UiSchema, } from '@rjsf/utils'; import cloneDeep from 'lodash/cloneDeep'; @@ -101,10 +102,6 @@ export const LAYOUT_GRID_UI_OPTION = 'layoutGrid'; */ export const LAYOUT_GRID_OPTION = `ui:${LAYOUT_GRID_UI_OPTION}`; -/** The constant representing the global UI Options object potentially contained within the `uiSchema` - */ -export const UI_GLOBAL_OPTIONS = 'ui:global_options'; - /** Type used to return options list and whether it has a discriminator */ type OneOfOptionsInfoType = { options: S[]; hasDiscriminator: boolean }; @@ -386,7 +383,7 @@ export default class LayoutGridField< schemaReadonly?: boolean, forceReadonly?: boolean, ) { - const globalUiOptions = get(uiSchema, [UI_GLOBAL_OPTIONS], {}); + const globalUiOptions = get(uiSchema, [UI_GLOBAL_OPTIONS_KEY], {}); const localUiSchema = get(uiSchema, field); const localUiOptions = { ...get(localUiSchema, [UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions }; const fieldUiSchema = { ...localUiSchema }; @@ -395,7 +392,7 @@ export default class LayoutGridField< } if (!isEmpty(globalUiOptions)) { // pass the global uiOptions down to the field uiSchema so that they can be applied to all nested fields - set(fieldUiSchema, [UI_GLOBAL_OPTIONS], globalUiOptions); + set(fieldUiSchema, [UI_GLOBAL_OPTIONS_KEY], globalUiOptions); } let { readonly: uiReadonly } = getUiOptions(fieldUiSchema); if (forceReadonly === true || (isUndefined(uiReadonly) && schemaReadonly === true)) { diff --git a/packages/core/test/LayoutGridField.test.tsx b/packages/core/test/LayoutGridField.test.tsx index 4cb1213b7d..377cd6476e 100644 --- a/packages/core/test/LayoutGridField.test.tsx +++ b/packages/core/test/LayoutGridField.test.tsx @@ -17,6 +17,7 @@ import { sortedJSONStringify, toIdSchema, UI_OPTIONS_KEY, + UI_GLOBAL_OPTIONS_KEY, UiSchema, } from '@rjsf/utils'; import validator from '@rjsf/validator-ajv8'; @@ -29,7 +30,6 @@ import LayoutGridField, { LAYOUT_GRID_OPTION, LayoutGridFieldProps, Operators, - UI_GLOBAL_OPTIONS, } from '../src/components/fields/LayoutGridField'; import { SAMPLE_SCHEMA, sampleUISchema, SIMPLE_ONEOF, SIMPLE_ONEOF_OPTIONS } from './testData/layoutData'; import getTestRegistry from './testData/getTestRegistry'; @@ -590,7 +590,7 @@ function FakeSchemaField({ 'data-testid': testId, ...props }: Readonly) => { onChange(val, error, id); }; @@ -693,7 +693,7 @@ function getExpectedPropsForField( const idSchema = get(props.idSchema, field)!; const formData = get(props.formData, field); // Also extract any global props - const global = get(props.uiSchema, [UI_GLOBAL_OPTIONS]); + const global = get(props.uiSchema, [UI_GLOBAL_OPTIONS_KEY]); const fieldUISchema = get(props.uiSchema, field); const { readonly: uiReadonly } = getUiOptions(fieldUISchema); // The expected props are the FORWARDED_PROPS, the field name, sub-schema, sub-uiSchema and sub-idSchema @@ -709,7 +709,7 @@ function getExpectedPropsForField( uiSchema: { ...uiSchema, [UI_OPTIONS_KEY]: { ...global, ...otherUiProps }, // spread the global and other ui keys into the ui:options - ...(global ? { [UI_GLOBAL_OPTIONS]: global } : {}), // ensure the globals are maintained + ...(global ? { [UI_GLOBAL_OPTIONS_KEY]: global } : {}), // ensure the globals are maintained }, idSchema, errorSchema, @@ -1208,12 +1208,12 @@ describe('LayoutGridField', () => { test('field with uiProps and uiSchema with global options for the field', () => { const uiProps = { fullWidth: true }; const globalOptions = { label: false }; - const uiSchema = { foo: { 'ui:widget': 'bar' }, [UI_GLOBAL_OPTIONS]: globalOptions }; + const uiSchema = { foo: { 'ui:widget': 'bar' }, [UI_GLOBAL_OPTIONS_KEY]: globalOptions }; expect(LayoutGridField.computeFieldUiSchema('foo', uiProps, uiSchema)).toEqual({ fieldUiSchema: { ...uiSchema.foo, [UI_OPTIONS_KEY]: { ...uiProps, ...globalOptions }, - [UI_GLOBAL_OPTIONS]: globalOptions, + [UI_GLOBAL_OPTIONS_KEY]: globalOptions, }, uiReadonly: undefined, }); @@ -1386,7 +1386,7 @@ describe('LayoutGridField', () => { const otherUIProps = { inline: true }; const props = getProps({ schema: GRID_FORM_SCHEMA, - uiSchema: { ...gridFormUISchema, [UI_GLOBAL_OPTIONS]: globalUiOptions }, + uiSchema: { ...gridFormUISchema, [UI_GLOBAL_OPTIONS_KEY]: globalUiOptions }, formData: {}, errorSchema: { employment: {} }, // IdSchema is weirdly recursive and it's easier to just ignore the error @@ -1513,7 +1513,7 @@ describe('LayoutGridField', () => { const gridProps = { operator: Operators.NONE, field: fieldName, value: null }; const props = getProps({ schema: SAMPLE_SCHEMA, - uiSchema: { ...sampleUISchema, [UI_GLOBAL_OPTIONS]: { always: 'there' } }, + uiSchema: { ...sampleUISchema, [UI_GLOBAL_OPTIONS_KEY]: { always: 'there' } }, formData: { [fieldName]: 'foo' }, layoutGridSchema: { [GridType.CONDITION]: { ...gridProps, children: GRID_CHILDREN } }, registry: sampleSchemaRegistry, diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.ts index d292f3e378..f494dca54c 100644 --- a/packages/utils/src/types.ts +++ b/packages/utils/src/types.ts @@ -370,9 +370,10 @@ export type TemplatesType