Skip to content

Commit

Permalink
Add uischemas to dependency array
Browse files Browse the repository at this point in the history
Currently the uischema prop of JSONForms was not watched for changes. So when uischemas was changed after JSONForms was rendered, the change did not get applied
  • Loading branch information
TheZoker committed Nov 16, 2021
1 parent 7532a3e commit 9bc2f65
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react/src/JsonFormsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const JsonFormsStateProvider = ({ children, initState, onChange }: any) =
i18n: i18n,
// only core dispatch available
dispatch: coreDispatch,
}), [core, initState.renderers, initState.cells, config, initState.readonly, i18n]);
}), [core, initState.renderers, initState.cells, config, initState.uischemas, initState.readonly, i18n]);

const onChangeRef = useRef(onChange);
useEffect(() => {
Expand Down
66 changes: 66 additions & 0 deletions packages/react/test/JsonFormsContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,69 @@ test('withJsonFormsDetailProps - should use uischemas props', () => {
expect(mockUISchemasProps.schema).toEqual(schema);
expect(mockUISchemasProps.uischemas).toEqual(uischemas);
});

test('withJsonFormsDetailProps - should update uischemas after change', () => {
const MockUISchemas = (_: StatePropsOfControlWithDetail) => {
return <></>;
};

const MockBasicRenderer = withJsonFormsDetailProps(MockUISchemas);

const schema = {
type: 'object',
properties: {
foo: {
type: 'string',
},
bar: {
type: 'number'
}
}
};

const renderers = [
{
tester: rankWith(1, () => true),
renderer: MockBasicRenderer
}
];

const newUischemas = [
{
tester: (_jsonSchema: JsonSchema, schemaPath: string) => {
return schemaPath === '#/properties/color' ? 2 : NOT_APPLICABLE;
},
uischema: {
type: 'HorizontalLayout',
elements: [
{
type: 'Control',
scope: '#/properties/foo'
},
{
type: 'Control',
scope: '#/properties/bar'
}
]
}
}
];

const uischema = {
type: 'Control',
scope: '#'
};

const wrapper = mount(
<JsonForms
data={{}}
schema={schema}
uischema={uischema}
renderers={renderers}
/>
);

wrapper.setProps({ uischemas: newUischemas });
wrapper.update();
expect(wrapper.props().uischemas).toEqual(newUischemas);
});

0 comments on commit 9bc2f65

Please sign in to comment.