Skip to content

Commit 6bcdbb1

Browse files
authored
Watch uischemas prop in React bindings
The "uischemas" prop of the React state manager was not watched for changes. Therefore changes to "uischemas" were only applied when other props also changed. This is now fixed.
1 parent 988f282 commit 6bcdbb1

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

packages/react/src/JsonFormsContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export const JsonFormsStateProvider = ({ children, initState, onChange }: any) =
158158
i18n: i18n,
159159
// only core dispatch available
160160
dispatch: coreDispatch,
161-
}), [core, initState.renderers, initState.cells, config, initState.readonly, i18n]);
161+
}), [core, initState.renderers, initState.cells, config, initState.uischemas, initState.readonly, i18n]);
162162

163163
const onChangeRef = useRef(onChange);
164164
useEffect(() => {

packages/react/test/JsonFormsContext.test.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,70 @@ test('withJsonFormsDetailProps - should use uischemas props', () => {
264264
expect(mockUISchemasProps.schema).toEqual(schema);
265265
expect(mockUISchemasProps.uischemas).toEqual(uischemas);
266266
});
267+
268+
test('withJsonFormsDetailProps - should update uischemas after change', () => {
269+
const MockUISchemas = (_: StatePropsOfControlWithDetail) => {
270+
return <></>;
271+
};
272+
273+
const MockBasicRenderer = withJsonFormsDetailProps(MockUISchemas);
274+
275+
const schema = {
276+
type: 'object',
277+
properties: {
278+
foo: {
279+
type: 'string',
280+
},
281+
bar: {
282+
type: 'number'
283+
}
284+
}
285+
};
286+
287+
const renderers = [
288+
{
289+
tester: rankWith(1, () => true),
290+
renderer: MockBasicRenderer
291+
}
292+
];
293+
294+
const newUischemas = [
295+
{
296+
tester: (_jsonSchema: JsonSchema, schemaPath: string) => {
297+
return schemaPath === '#/properties/color' ? 2 : NOT_APPLICABLE;
298+
},
299+
uischema: {
300+
type: 'HorizontalLayout',
301+
elements: [
302+
{
303+
type: 'Control',
304+
scope: '#/properties/foo'
305+
},
306+
{
307+
type: 'Control',
308+
scope: '#/properties/bar'
309+
}
310+
]
311+
}
312+
}
313+
];
314+
315+
const uischema = {
316+
type: 'Control',
317+
scope: '#'
318+
};
319+
320+
const wrapper = mount(
321+
<JsonForms
322+
data={{}}
323+
schema={schema}
324+
uischema={uischema}
325+
renderers={renderers}
326+
/>
327+
);
328+
329+
wrapper.setProps({ uischemas: newUischemas });
330+
wrapper.update();
331+
const mockUISchemasProps = wrapper.find(MockUISchemas).props();
332+
expect(mockUISchemasProps.uischemas).toEqual(newUischemas);
333+
});

0 commit comments

Comments
 (0)