Skip to content

Commit b664b8d

Browse files
authored
Merge pull request #63 from rvsia/field-array-pf4
FieldArray make it works
2 parents 2097c12 + 05442e3 commit b664b8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1683
-3878
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Data Driven Forms is a React library used for rendering and managing forms with
2020
- Asynchronous validation supported!
2121
- Supporting Wizard forms!
2222
- Supporting Mozzila form schema!
23+
- Supporting [Final Form Field Array](https://github.com/final-form/react-final-form-arrays)!
2324
- ... and a lot more!
2425

2526
:book: For more information please visit the [documentation](https://data-driven-forms.org/). :book:

__mocks__/mock-layout-mapper.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import { layoutComponents } from "../packages/react-form-renderer/src/constants"
44
export const layoutMapper = {
55
[layoutComponents.FORM_WRAPPER]: ({ children }) => <div>{ children }</div>,
66
[layoutComponents.BUTTON]: ({ label, ...rest }) => <button { ...rest }>{ label }</button>,
7-
[layoutComponents.COL]: ({ children }) => <div>{ children }</div>,
8-
[layoutComponents.FORM_GROUP]: ({ children }) => <div>{ children }</div>,
97
[layoutComponents.BUTTON_GROUP]: ({ children }) => <div>{ children }</div>,
10-
[layoutComponents.ICON]: props => <div>Icon</div>,
11-
[layoutComponents.ARRAY_FIELD_WRAPPER]: ({ children }) => <div>{ children }</div>,
12-
[layoutComponents.HELP_BLOCK]: ({ children }) => <div>{ children }</div>,
138
[layoutComponents.TITLE]: ({ children }) => <div>{ children }</div>,
149
[layoutComponents.DESCRIPTION]: ({ children }) => <div>{ children }</div>,
1510
};

packages/mui-component-mapper/src/form-fields/form-fields.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ const FieldInterface = ({
207207
condition,
208208
componentType,
209209
initialKey,
210+
FieldArrayProvider, // eslint-disable-line react/prop-types
210211
...props
211212
}) => (
212213
<Grid xs={ 12 } item style={{ marginBottom: 16, padding: 0 }}>

packages/mui-component-mapper/src/form-fields/layout-components.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
import React, { Fragment } from 'react';
1+
import React from 'react';
22
import { layoutComponents } from '@data-driven-forms/react-form-renderer';
33
import Grid from '@material-ui/core/Grid';
44
import Button from '@material-ui/core/Button';
55
import Typography from '@material-ui/core/Typography';
66

7-
const ArrayFieldWrapper = ({ children }) => (
8-
<div style={{
9-
display: 'inline-block',
10-
width: '100%',
11-
}}>
12-
{ children }
13-
</div>
14-
);
15-
167
const layoutMapper = {
178
[layoutComponents.FORM_WRAPPER]: ({ children, ...props }) => <form { ...props }>{ children }</form>,
189
[layoutComponents.BUTTON]: ({ label, variant, children, ...props }) => <Button color={ variant } variant="contained" { ...props }>{ label || children }</Button>,
19-
[layoutComponents.COL]: ({ children, xs, ...rest }) => <div key={ rest.key || rest.name }>{ children }</div>,
20-
[layoutComponents.FORM_GROUP]: ({ children }) => <Fragment>{ children }</Fragment>,
2110
[layoutComponents.BUTTON_GROUP]: ({ children }) => (
2211
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
2312
{ children }
2413
</div>),
25-
[layoutComponents.ICON]: props => <div>Icon</div>,
26-
[layoutComponents.ARRAY_FIELD_WRAPPER]: props => <div>Array field</div>,
27-
[layoutComponents.HELP_BLOCK]: props => <div>Help block</div>,
2814
[layoutComponents.TITLE]: ({ children }) => <Grid item xs={ 12 }>
2915
<Typography variant="h3" gutterBottom>
3016
{ children }
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# react-starter
2-
Used to create new react libs for data-driven-forms
1+
## Documentation: http://data-driven-forms.org/

packages/pf3-component-mapper/src/form-fields/form-fields.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const FieldInterface = ({
130130
condition,
131131
componentType,
132132
initialKey,
133+
FieldArrayProvider, // eslint-disable-line
133134
...props
134135
}) => (
135136
fieldMapper(componentType)({

packages/pf3-component-mapper/src/form-fields/layout-components.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { layoutComponents } from '@data-driven-forms/react-form-renderer';
4-
import { Button, FormGroup, Icon, HelpBlock, Form } from 'patternfly-react';
4+
import { Button, Form } from 'patternfly-react';
55
import './layout-components.scss';
66

7-
const ArrayFieldWrapper = ({ children }) => (
8-
<div style={{
9-
display: 'inline-block',
10-
width: '100%',
11-
}}>
12-
{ children }
13-
</div>
14-
);
15-
167
const FormWapper = ({ children, ...props }) => <Form { ...props } >{ children }</Form>;
178

189
FormWapper.propTypes = {
@@ -58,12 +49,7 @@ DescriptionWrapper.propTypes = {
5849
const layoutMapper = {
5950
[layoutComponents.FORM_WRAPPER]: FormWapper,
6051
[layoutComponents.BUTTON]: FormButton,
61-
[layoutComponents.COL]: ({ children, xs, ...rest }) => <div key={ rest.key || rest.name }>{ children }</div>, // TO BE removed
62-
[layoutComponents.FORM_GROUP]: FormGroup,
6352
[layoutComponents.BUTTON_GROUP]: ButtonGroupWrapper,
64-
[layoutComponents.ICON]: props => <Icon { ...props } />, // TO BE removed
65-
[layoutComponents.ARRAY_FIELD_WRAPPER]: ArrayFieldWrapper, // TO BE removed
66-
[layoutComponents.HELP_BLOCK]: HelpBlock,
6753
[layoutComponents.TITLE]: TitleWrapper,
6854
[layoutComponents.DESCRIPTION]: DescriptionWrapper,
6955
};

packages/pf3-component-mapper/src/tests/layout-components.test.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { mount } from 'enzyme';
2-
import { FormGroup, Button, Icon, HelpBlock, Form } from 'patternfly-react';
2+
import { Button, Form } from 'patternfly-react';
33
import { layoutComponents } from '@data-driven-forms/react-form-renderer';
44
import layoutMapper from '../form-fields/layout-components';
55

66
describe('Layout mapper', () => {
7-
it('should return PF3 Col', () => {
8-
expect(mount(layoutMapper[layoutComponents.COL]({})).find('div')).toHaveLength(1);
9-
});
10-
117
it('should return PF3 Button', () => {
128
expect(mount(layoutMapper[layoutComponents.BUTTON]({})).find(Button)).toHaveLength(1);
139
});
@@ -16,18 +12,6 @@ describe('Layout mapper', () => {
1612
expect(mount(layoutMapper[layoutComponents.FORM_WRAPPER]({})).find(Form)).toHaveLength(1);
1713
});
1814

19-
it('should return PF3 FormGroup', () => {
20-
expect(layoutMapper[layoutComponents.FORM_GROUP]).toEqual(FormGroup);
21-
});
22-
23-
it('should return PF3 Icon', () => {
24-
expect(mount(layoutMapper[layoutComponents.ICON]({ name: 'Foo' })).find(Icon)).toHaveLength(1);
25-
});
26-
27-
it('should return PF3 HelpBlock', () => {
28-
expect(layoutMapper[layoutComponents.HELP_BLOCK]).toEqual(HelpBlock);
29-
});
30-
3115
it('should return PF3 Title', () => {
3216
expect(mount(layoutMapper[layoutComponents.TITLE]({})).find('h3')).toHaveLength(1);
3317
});
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# react-starter
2-
Used to create new react libs for data-driven-forms
1+
## Documentation: http://data-driven-forms.org/

packages/pf4-component-mapper/demo/demo-schemas/widget-schema.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,97 @@ export const arraySchema = {
380380
},
381381
};
382382

383+
export const array1Schema = {
384+
definitions: {
385+
Thing: {
386+
type: 'string',
387+
properties: {
388+
name: {
389+
type: 'string',
390+
default: 'Default name',
391+
},
392+
},
393+
},
394+
},
395+
type: 'object',
396+
properties: {
397+
minItemsList: {
398+
type: 'array',
399+
title: 'A list with a minimal number of items',
400+
minItems: 3,
401+
items: {
402+
title: 'A string',
403+
type: 'string',
404+
default: 'lorem ipsum',
405+
},
406+
},
407+
},
408+
};
409+
410+
export const arraySchemaDDF = {
411+
title: 'FieldArray',
412+
fields: [
413+
{
414+
component: 'field-array',
415+
name: 'nicePeople',
416+
fieldKey: 'field_array',
417+
label: 'Nice people',
418+
description: 'This allow you to add nice people to the list dynamically',
419+
itemDefault: { name: 'enter a name', lastName: 'enter a last name' },
420+
fields: [{
421+
component: 'text-field',
422+
name: 'name',
423+
label: 'Name',
424+
placeholder: 'Borek',
425+
isRequired: true,
426+
validate: [{
427+
type: 'required-validator',
428+
}],
429+
}, {
430+
component: 'text-field',
431+
name: 'lastName',
432+
label: 'Last Name',
433+
placeholder: 'Stavitel',
434+
}],
435+
},
436+
{
437+
component: 'field-array',
438+
name: 'minItems',
439+
label: 'A list with a minimal number of items',
440+
validate: [{ type: 'min-items-validator', threshold: 3 }],
441+
fields: [{
442+
component: 'text-field',
443+
label: 'Item',
444+
}],
445+
},
446+
{
447+
component: 'field-array',
448+
name: 'number',
449+
defaultItem: 5,
450+
label: 'Default value with initialValues set',
451+
fields: [{
452+
component: 'text-field',
453+
label: 'Item',
454+
type: 'number',
455+
}],
456+
},
457+
{
458+
component: 'field-array',
459+
name: 'minMax',
460+
minItems: 4,
461+
maxItems: 6,
462+
label: 'Min 4 item, max 6 items without validators',
463+
fields: [{
464+
component: 'text-field',
465+
isRequired: true,
466+
validate: [{
467+
type: 'required-validator',
468+
}],
469+
}],
470+
},
471+
],
472+
};
473+
383474
export const uiArraySchema = {
384475
listOfStrings: {
385476
items: {

0 commit comments

Comments
 (0)