Skip to content

Commit f83c4a6

Browse files
committed
Remove mapStateToCombinatorRendererProps usage from mapStateToAllOfProps
In contrast to oneOf and anyOf rendererer, allOf renderers do not need the `indexOfFittingSchema` because all schemas apply at once. Thus, remove using mapStateToCombinatorRendererProps from mapStateToAllOfProps and, with this, the unnecessary calculation of the index. Part of #2371
1 parent 138d69d commit f83c4a6

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

packages/core/src/mappers/renderer.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,11 @@ export interface StatePropsOfCombinator extends StatePropsOfControl {
11231123
data: any;
11241124
}
11251125

1126+
export type StatePropsOfAllOfRenderer = Omit<
1127+
StatePropsOfCombinator,
1128+
'indexOfFittingSchema'
1129+
>;
1130+
11261131
export const mapStateToCombinatorRendererProps = (
11271132
state: JsonFormsState,
11281133
ownProps: OwnPropsOfControl,
@@ -1155,6 +1160,12 @@ export const mapStateToCombinatorRendererProps = (
11551160
export interface CombinatorRendererProps
11561161
extends StatePropsOfCombinator,
11571162
DispatchPropsOfControl {}
1163+
1164+
export type AllOfRendererProps = Omit<
1165+
CombinatorRendererProps,
1166+
'indexOfFittingSchema'
1167+
>;
1168+
11581169
/**
11591170
* Map state to all of renderer props.
11601171
* @param state the store's state
@@ -1164,8 +1175,20 @@ export interface CombinatorRendererProps
11641175
export const mapStateToAllOfProps = (
11651176
state: JsonFormsState,
11661177
ownProps: OwnPropsOfControl
1167-
): StatePropsOfCombinator =>
1168-
mapStateToCombinatorRendererProps(state, ownProps, 'allOf');
1178+
): StatePropsOfAllOfRenderer => {
1179+
const { data, schema, rootSchema, i18nKeyPrefix, label, ...props } =
1180+
mapStateToControlProps(state, ownProps);
1181+
1182+
return {
1183+
data,
1184+
schema,
1185+
rootSchema,
1186+
...props,
1187+
i18nKeyPrefix,
1188+
label,
1189+
uischemas: getUISchemas(state),
1190+
};
1191+
};
11691192

11701193
export const mapStateToAnyOfProps = (
11711194
state: JsonFormsState,

packages/material-renderers/src/complex/MaterialAllOfRenderer.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
JsonSchema,
3232
RankedTester,
3333
rankWith,
34-
StatePropsOfCombinator,
34+
StatePropsOfAllOfRenderer,
3535
} from '@jsonforms/core';
3636
import { JsonFormsDispatch, withJsonFormsAllOfProps } from '@jsonforms/react';
3737

@@ -44,7 +44,7 @@ export const MaterialAllOfRenderer = ({
4444
path,
4545
uischemas,
4646
uischema,
47-
}: StatePropsOfCombinator) => {
47+
}: StatePropsOfAllOfRenderer) => {
4848
const delegateUISchema = findMatchingUISchema(uischemas)(
4949
schema,
5050
uischema.scope,

packages/react/src/JsonFormsContext.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
arrayDefaultTranslations,
8282
getArrayTranslations,
8383
ArrayTranslations,
84+
AllOfRendererProps,
8485
} from '@jsonforms/core';
8586
import debounce from 'lodash/debounce';
8687
import React, {
@@ -561,12 +562,12 @@ const withContextToAnyOfProps = (
561562
};
562563

563564
const withContextToAllOfProps = (
564-
Component: ComponentType<CombinatorRendererProps>
565+
Component: ComponentType<AllOfRendererProps>
565566
): ComponentType<OwnPropsOfControl> =>
566567
function WithContextToAllOfProps({
567568
ctx,
568569
props,
569-
}: JsonFormsStateContext & CombinatorRendererProps) {
570+
}: JsonFormsStateContext & AllOfRendererProps) {
570571
const allOfProps = ctxToAllOfProps(ctx, props);
571572
const dispatchProps = ctxDispatchToControlProps(ctx.dispatch);
572573
return <Component {...props} {...allOfProps} {...dispatchProps} />;
@@ -764,7 +765,7 @@ export const withJsonFormsAnyOfProps = (
764765
);
765766

766767
export const withJsonFormsAllOfProps = (
767-
Component: ComponentType<CombinatorRendererProps>,
768+
Component: ComponentType<AllOfRendererProps>,
768769
memoize = true
769770
): ComponentType<OwnPropsOfControl> =>
770771
withJsonFormsContext(

0 commit comments

Comments
 (0)