Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass all props in the MaterialArrayLayoutRenderer #1951

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions packages/material/src/layouts/MaterialArrayLayoutRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,18 @@ import { withJsonFormsArrayLayoutProps } from '@jsonforms/react';

export const MaterialArrayLayoutRenderer = ({
visible,
enabled,
id,
uischema,
schema,
label,
rootSchema,
renderers,
cells,
data,
path,
errors,
uischemas,
addItem
addItem,
...props
}: ArrayLayoutProps) => {
const addItemCb = useCallback((p: string, value: any) => addItem(p, value), [
addItem
]);
return (
<Hidden xsUp={!visible}>
<MaterialArrayLayout
label={label}
uischema={uischema}
schema={schema}
id={id}
rootSchema={rootSchema}
errors={errors}
enabled={enabled}
visible={visible}
data={data}
path={path}
addItem={addItemCb}
renderers={renderers}
cells={cells}
uischemas={uischemas}
{...props}
sdirix marked this conversation as resolved.
Show resolved Hide resolved
/>
</Hidden>
);
Expand Down
33 changes: 32 additions & 1 deletion packages/material/test/renderers/MaterialArrayLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,36 @@ describe('Material array layout', () => {
.find({ 'aria-label': 'Move down' }).length
).toBe(1);
});
it('should render sort buttons if showSortButtons is true in config', () => {
wrapper = mount(
<JsonForms
data={data}
schema={nestedSchema}
uischema={uischema}
renderers={materialRenderers}
config={{showSortButtons: true}}
/>
);

expect(wrapper.find(MaterialArrayLayout).length).toBeTruthy();

// up button
expect(
wrapper
.find('Memo(ExpandPanelRendererComponent)')
.at(0)
.find('button')
.find({ 'aria-label': 'Move up' }).length
).toBe(1);
// down button
expect(
wrapper
.find('Memo(ExpandPanelRendererComponent)')
.at(0)
.find('button')
.find({ 'aria-label': 'Move down' }).length
).toBe(1);
});
it('should move item up if up button is presses', (done) => {
const onChangeData: any = {
data: undefined
Expand All @@ -341,7 +371,8 @@ describe('Material array layout', () => {
<JsonForms
data={data}
schema={nestedSchema}
uischema={uischemaWithSortOption}
uischema={uischema}
config={{showSortButtons: true}}
renderers={materialRenderers}
onChange={({ data }) => {
onChangeData.data = data;
Expand Down