Skip to content

Commit 60bc71d

Browse files
authored
Merge pull request #402 from data-driven-forms/v2
V2 Release
2 parents 3dc98c7 + 589ba14 commit 60bc71d

File tree

477 files changed

+38040
-54796
lines changed

Some content is hidden

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

477 files changed

+38040
-54796
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
- run:
2121
name: test
2222
command: yarn test:ci
23+
- run:
24+
name: lint
25+
command: yarn lint
2326
- codecov/upload:
2427
file: coverage/*.json
2528
token: aa1b6b4d-79a1-49f6-bcb2-d6069134a772

.eslintignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**/node_modules
2+
/**/dist
3+
/**/public
4+
/**/coverage
5+
/**/vendor.js
6+
/**/*.config.js
7+
/**/doc-components/
8+
/**/examples-texts/

packages/common/.eslintrc renamed to .eslintrc.json

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"settings": {
1313
"react": {
14-
"version": 16.6
14+
"version": "16.6"
1515
}
1616
},
1717
"globals": {
@@ -21,7 +21,8 @@
2121
"it": true,
2222
"arguments": true
2323
},
24-
"extends": ["react-app", "prettier", "eslint:recommended", "plugin:react/recommended"],
24+
"plugins": ["prettier"],
25+
"extends": ["react-app", "eslint:recommended", "plugin:react/recommended", "plugin:prettier/recommended", "prettier/react"],
2526
"env": {
2627
"es6": true,
2728
"browser": true,
@@ -31,10 +32,6 @@
3132
"rules": {
3233
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
3334
"react/display-name": "off",
34-
"array-bracket-spacing": ["error", "always", {
35-
"objectsInArrays": false
36-
}],
37-
"comma-dangle": [1, "always-multiline"],
3835
"comma-spacing": ["error", {
3936
"after": true
4037
}],
@@ -43,23 +40,9 @@
4340
"curly": ["error", "all"],
4441
"eol-last": "error",
4542
"eqeqeq": "error",
46-
"indent": ["error", 2, {
47-
"SwitchCase": 1,
48-
"MemberExpression": 0,
49-
"ImportDeclaration": 1,
50-
"ObjectExpression": 1
51-
}],
52-
"react/jsx-curly-spacing": ["error", "always", {
53-
"children": true,
54-
"allowMultiline": false,
55-
"spacing": {
56-
"objectLiterals": "never"
57-
}
58-
}],
5943
"key-spacing": "error",
6044
"keyword-spacing": "error",
6145
"linebreak-style": ["warn", "unix"],
62-
"max-len": ["error", 150],
6346
"new-cap": "error",
6447
"no-bitwise": "error",
6548
"no-caller": "error",
@@ -76,10 +59,6 @@
7659
"no-var": "error",
7760
"no-with": "error",
7861
"object-shorthand": "error",
79-
"object-curly-spacing": ["error", "always", {
80-
"objectsInObjects": false,
81-
"arraysInObjects": false
82-
}],
8362
"one-var": ["error", "never"],
8463
"padding-line-between-statements": ["error", {
8564
"blankLine": "always",
@@ -95,6 +74,16 @@
9574
"space-infix-ops": "error",
9675
"wrap-iife": "error",
9776
"yoda": ["error", "never"],
98-
"jsx-a11y/href-no-hash": "off"
77+
"jsx-a11y/href-no-hash": "off",
78+
"react/jsx-curly-spacing": "off",
79+
"no-unused-vars": "error",
80+
"react/no-unused-prop-types": "error",
81+
"react-hooks/rules-of-hooks": "error",
82+
"react/prop-types": "error",
83+
"react/no-unescaped-entities": "error",
84+
"no-prototype-builtins": "error",
85+
"no-mixed-operators": "error",
86+
"no-unused-expressions": "error",
87+
"no-sequences": "error"
9988
}
10089
}

.prettierrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"printWidth": 150,
3+
"arrowParens": "always",
4+
"semi": true,
5+
"tabWidth": 2,
6+
"singleQuote": true,
7+
"jsxSingleQuote": false,
8+
"bracketSpacing": true
9+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ For using Data Driven Forms in your component you need the renderer and a compon
102102
```jsx
103103
import React from 'react';
104104
import FormRenderer, { componentTypes } from '@data-driven-forms/react-form-renderer';
105-
import { formFieldsMapper, layoutMapper } from '@data-driven-forms/pf4-component-mapper';
105+
import { componentMapper, layoutMapper } from '@data-driven-forms/pf4-component-mapper';
106106

107107
const schema = {
108108
fields: [{
@@ -115,7 +115,7 @@ const schema = {
115115
const Form = () => (
116116
<FormRenderer
117117
schema={schema}
118-
formFieldsMapper={formFieldsMapper}
118+
componentMapper={componentMapper}
119119
layoutMapper={layoutMapper}
120120
onSubmit={console.log}
121121
/>

__mocks__/file-mock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// mocks css and scss files
22

3-
module.exports = 'test-file-stub';
3+
module.exports = 'test-file-stub';

__mocks__/mock-field-provider.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ import { createElement } from 'react';
33
const MockFieldProvider = ({ input, render, meta, component, children, ...rest }) => {
44
const fieldInput = {
55
onChange: jest.fn(),
6-
...input,
6+
...input
77
};
88
const fieldMeta = {
9-
...meta,
9+
...meta
1010
};
1111

1212
if (typeof children === 'function') {
1313
return children({ ...rest, input: fieldInput, meta: fieldMeta });
1414
}
1515

16-
if (typeof component === 'object') {
16+
if (typeof component === 'object' || typeof component === 'function') {
1717
return createElement(component, { ...rest, input: fieldInput, meta: fieldMeta, children });
1818
}
1919

2020
return render({ ...rest, input: fieldInput, meta: fieldMeta, children });
21-
2221
};
2322

2423
export default MockFieldProvider;

__mocks__/mock-form-template.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* eslint-disable react/prop-types */
2+
/* eslint-disable react-hooks/rules-of-hooks */
3+
import React from 'react';
4+
import { useFormApi, FormSpy } from '@data-driven-forms/react-form-renderer';
5+
import { useFormApi as useFormApiInternal, FormSpy as FormSpyInternal } from '../packages/react-form-renderer/src';
6+
const path = require('path');
7+
8+
const FormTemplate = ({ schema: { title, label, description }, formFields }) => {
9+
// When testing inside the renderer package, it cannot import things from itself!
10+
const isInternal = path.dirname(module.parent.filename).includes('/react-form-renderer/');
11+
const formOptions = isInternal ? useFormApiInternal() : useFormApi();
12+
const FormSpyFinal = isInternal ? FormSpyInternal : FormSpy;
13+
14+
return (
15+
<form onSubmit={formOptions.handleSubmit}>
16+
{(title || label) && <h1>{title || label}</h1>}
17+
{description && <h2>{description}</h2>}
18+
{formFields}
19+
<FormSpyFinal>
20+
{({ submitting, pristine, validating, form: { reset }, values }) => (
21+
<React.Fragment>
22+
<button type="submit" disabled={submitting || validating || formOptions.getState().invalid}>
23+
Submit
24+
</button>
25+
<button
26+
type="button"
27+
disabled={pristine}
28+
onClick={() => {
29+
formOptions.onReset && formOptions.onReset();
30+
reset();
31+
}}
32+
>
33+
Reset
34+
</button>
35+
<button type="button" disabled={pristine} onClick={() => formOptions.onCancel(values)}>
36+
Cancel
37+
</button>
38+
</React.Fragment>
39+
)}
40+
</FormSpyFinal>
41+
</form>
42+
);
43+
};
44+
45+
export default FormTemplate;

__mocks__/mock-layout-mapper.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

__mocks__/with-provider.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable react/prop-types */
2+
import React from 'react';
3+
import { RendererContext } from '@data-driven-forms/react-form-renderer';
4+
import Form from '@data-driven-forms/react-form-renderer/dist/cjs/form';
5+
6+
const RenderWithProvider = ({ value = { formOptions: {} }, children, onSubmit = () => {} }) => {
7+
return (
8+
<Form onSubmit={onSubmit}>
9+
{() => (
10+
<RendererContext.Provider
11+
value={{
12+
...value
13+
}}
14+
>
15+
{children}
16+
</RendererContext.Provider>
17+
)}
18+
</Form>
19+
);
20+
};
21+
22+
export default RenderWithProvider;

0 commit comments

Comments
 (0)