Skip to content

Commit

Permalink
Remove mapStateToCombinatorRendererProps usage from mapStateToAllOfProps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lucas-koehler committed Jan 31, 2025
1 parent a4ae9f5 commit 07fe0f7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
27 changes: 25 additions & 2 deletions packages/core/src/mappers/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,11 @@ export interface StatePropsOfCombinator extends StatePropsOfControl {
data: any;
}

export type StatePropsOfAllOfRenderer = Omit<
StatePropsOfCombinator,
'indexOfFittingSchema'
>;

export const mapStateToCombinatorRendererProps = (
state: JsonFormsState,
ownProps: OwnPropsOfControl,
Expand Down Expand Up @@ -1155,6 +1160,12 @@ export const mapStateToCombinatorRendererProps = (
export interface CombinatorRendererProps
extends StatePropsOfCombinator,
DispatchPropsOfControl {}

export type AllOfRendererProps = Omit<
CombinatorRendererProps,
'indexOfFittingSchema'
>;

/**
* Map state to all of renderer props.
* @param state the store's state
Expand All @@ -1164,8 +1175,20 @@ export interface CombinatorRendererProps
export const mapStateToAllOfProps = (
state: JsonFormsState,
ownProps: OwnPropsOfControl
): StatePropsOfCombinator =>
mapStateToCombinatorRendererProps(state, ownProps, 'allOf');
): StatePropsOfAllOfRenderer => {
const { data, schema, rootSchema, i18nKeyPrefix, label, ...props } =
mapStateToControlProps(state, ownProps);

return {
data,
schema,
rootSchema,
...props,
i18nKeyPrefix,
label,
uischemas: getUISchemas(state),
};
};

export const mapStateToAnyOfProps = (
state: JsonFormsState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
JsonSchema,
RankedTester,
rankWith,
StatePropsOfCombinator,
StatePropsOfAllOfRenderer,
} from '@jsonforms/core';
import { JsonFormsDispatch, withJsonFormsAllOfProps } from '@jsonforms/react';

Expand All @@ -44,7 +44,7 @@ export const MaterialAllOfRenderer = ({
path,
uischemas,
uischema,
}: StatePropsOfCombinator) => {
}: StatePropsOfAllOfRenderer) => {
const delegateUISchema = findMatchingUISchema(uischemas)(
schema,
uischema.scope,
Expand Down
7 changes: 4 additions & 3 deletions packages/react/src/JsonFormsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
arrayDefaultTranslations,
getArrayTranslations,
ArrayTranslations,
AllOfRendererProps,
} from '@jsonforms/core';
import debounce from 'lodash/debounce';
import React, {
Expand Down Expand Up @@ -561,12 +562,12 @@ const withContextToAnyOfProps = (
};

const withContextToAllOfProps = (
Component: ComponentType<CombinatorRendererProps>
Component: ComponentType<AllOfRendererProps>
): ComponentType<OwnPropsOfControl> =>
function WithContextToAllOfProps({
ctx,
props,
}: JsonFormsStateContext & CombinatorRendererProps) {
}: JsonFormsStateContext & AllOfRendererProps) {
const allOfProps = ctxToAllOfProps(ctx, props);
const dispatchProps = ctxDispatchToControlProps(ctx.dispatch);
return <Component {...props} {...allOfProps} {...dispatchProps} />;
Expand Down Expand Up @@ -764,7 +765,7 @@ export const withJsonFormsAnyOfProps = (
);

export const withJsonFormsAllOfProps = (
Component: ComponentType<CombinatorRendererProps>,
Component: ComponentType<AllOfRendererProps>,
memoize = true
): ComponentType<OwnPropsOfControl> =>
withJsonFormsContext(
Expand Down

0 comments on commit 07fe0f7

Please sign in to comment.