Skip to content

Optimize condition and field array performance #1017

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

Merged
merged 6 commits into from
Mar 31, 2021
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
2 changes: 1 addition & 1 deletion __mocks__/with-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { RendererContext } from '@data-driven-forms/react-form-renderer';
import Form from '@data-driven-forms/react-form-renderer/form';

const RenderWithProvider = ({ value = { formOptions: {} }, children, onSubmit = () => {} }) => {
const RenderWithProvider = ({ value = { formOptions: {internalRegisterField: jest.fn(), internalUnRegisterField: jest.fn()} }, children, onSubmit = () => {} }) => {
return (
<Form onSubmit={onSubmit}>
{() => (
Expand Down
3 changes: 2 additions & 1 deletion packages/ant-component-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"react-dom": ">=16.13.0"
},
"dependencies": {
"@data-driven-forms/common": "*"
"@data-driven-forms/common": "*",
"lodash": "^4.17.21"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't lodash dependency of form-renderer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but now lodash is a direct dependency of the package and should be listed.

},
"postpublish": "export RELEASE_DEMO=true"
}
7 changes: 4 additions & 3 deletions packages/ant-component-mapper/src/field-array/field-array.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useReducer } from 'react';
import React, { memo, useReducer } from 'react';
import isEqual from 'lodash/isEqual';
import PropTypes from 'prop-types';
import { useFieldApi, useFormApi, FieldArray } from '@data-driven-forms/react-form-renderer';
import { Row, Col, Button, Typography, Space } from 'antd';
import { UndoOutlined, RedoOutlined } from '@ant-design/icons';

import FormGroup from '../form-group';

const ArrayItem = ({
const ArrayItem = memo(({
fields,
fieldIndex,
name,
Expand Down Expand Up @@ -38,7 +39,7 @@ const ArrayItem = ({
</Col>
</Row>
);
};
}, ({remove: _prevRemove, ...prev}, {remove: _nextRemove, ...next}) => isEqual(prev, next));

ArrayItem.propTypes = {
name: PropTypes.string,
Expand Down
6 changes: 4 additions & 2 deletions packages/ant-component-mapper/src/tests/slider.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';
import { Form as DDFForm } from '@data-driven-forms/react-form-renderer';
import { Form as DDFForm, RendererContext } from '@data-driven-forms/react-form-renderer';
import { mount } from 'enzyme';
import { Slider as AntSlider, Form as OriginalForm } from 'antd';
import Slider from '../slider';
import FormGroup from '../form-group';

const Form = (props) => (
<OriginalForm>
<DDFForm onSubmit={jest.fn()} {...props} />
<RendererContext.Provider value={{ formOptions: { internalRegisterField: jest.fn(), internalUnRegisterField: jest.fn() } }}>
<DDFForm onSubmit={jest.fn()} {...props} />
</RendererContext.Provider>
</OriginalForm>
);

Expand Down
1 change: 1 addition & 0 deletions packages/blueprint-component-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"dependencies": {
"@data-driven-forms/common": "*",
"clsx": "^1.1.0",
"lodash": "^4.17.21",
"prop-types": "^15.7.2",
"react-jss": "^10.5.0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useContext } from 'react';
import React, { memo, useContext } from 'react';
import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';
import clsx from 'clsx';
import { useFieldApi, useFormApi, FieldArray as FieldArrayFF } from '@data-driven-forms/react-form-renderer';
import { createUseStyles } from 'react-jss';
Expand All @@ -19,7 +20,7 @@ const useStyles = createUseStyles({
}
});

const ArrayItem = ({ remove, fields, name, removeLabel, ArrayItemProps, RemoveButtonProps, disabledRemove }) => {
const ArrayItem = memo(({ remove, fields, name, removeLabel, ArrayItemProps, RemoveButtonProps, disabledRemove }) => {
const formOptions = useFormApi();
const { remove: removeCss } = useStyles();

Expand All @@ -42,7 +43,7 @@ const ArrayItem = ({ remove, fields, name, removeLabel, ArrayItemProps, RemoveBu
</Button>
</div>
);
};
}, ({remove: _prevRemove, ...prev}, {remove: _nextRemove, ...next}) => isEqual(prev, next));

ArrayItem.propTypes = {
remove: PropTypes.func,
Expand Down
1 change: 1 addition & 0 deletions packages/carbon-component-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"peerDependencies": {},
"dependencies": {
"@data-driven-forms/common": "*",
"lodash": "^4.17.21",
"prop-types": ">=15.7.2",
"react-jss": "^10.5.0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import React, { memo } from 'react';
import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';
import clsx from 'clsx';
import { createUseStyles } from 'react-jss';

Expand Down Expand Up @@ -30,7 +31,7 @@ const useStyles = createUseStyles({
}
});

const ArrayItem = ({ remove, fields, name, removeText, buttonDisabled, RemoveButtonProps, ArrayItemProps }) => {
const ArrayItem = memo(({ remove, fields, name, removeText, buttonDisabled, RemoveButtonProps, ArrayItemProps }) => {
const formOptions = useFormApi();
const { remove: removeStyle } = useStyles();

Expand All @@ -55,7 +56,7 @@ const ArrayItem = ({ remove, fields, name, removeText, buttonDisabled, RemoveBut
</Button>
</div>
);
};
}, ({remove: _prevRemove, ...prev}, {remove: _nextRemove, ...next}) => isEqual(prev, next));

ArrayItem.propTypes = {
remove: PropTypes.func,
Expand Down
1 change: 1 addition & 0 deletions packages/mui-component-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@material-ui/pickers": "^3.2.10",
"clsx": "^1.0.4",
"date-fns": "^1.30.1",
"lodash": "^4.17.21",
"moment": "^2.23.0",
"@material-ui/lab": "^4.0.0-alpha.53"
},
Expand Down
7 changes: 4 additions & 3 deletions packages/mui-component-mapper/src/field-array/field-array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useReducer } from 'react';
import React, { memo, useReducer } from 'react';
import PropTypes from 'prop-types';
import { useFormApi, FieldArray } from '@data-driven-forms/react-form-renderer';
import isEqual from 'lodash/isEqual';

import { Grid, Button, Typography, FormControl, FormHelperText, IconButton } from '@material-ui/core';

Expand Down Expand Up @@ -36,7 +37,7 @@ const useFielArrayStyles = makeStyles({
}
});

const ArrayItem = ({
const ArrayItem = memo(({
fields,
fieldIndex,
name,
Expand Down Expand Up @@ -71,7 +72,7 @@ const ArrayItem = ({
</Grid>
</Grid>
);
};
}, ({remove: _prevRemove, ...prev}, {remove: _nextRemove, ...next}) => isEqual(prev, next));

ArrayItem.propTypes = {
name: PropTypes.string,
Expand Down
3 changes: 2 additions & 1 deletion packages/pf4-component-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"dependencies": {
"@data-driven-forms/common": "*",
"prop-types": "^15.7.2",
"downshift": "^5.4.3"
"downshift": "^5.4.3",
"lodash": "^4.17.21"
},
"postpublish": "export RELEASE_DEMO=true"
}
7 changes: 4 additions & 3 deletions packages/pf4-component-mapper/src/field-array/field-array.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Fragment } from 'react';
import React, { Fragment, memo } from 'react';
import isEqual from 'lodash/isEqual';
import PropTypes from 'prop-types';
import { useFormApi, FieldArray } from '@data-driven-forms/react-form-renderer';

Expand All @@ -9,7 +10,7 @@ import { AddCircleOIcon, CloseIcon } from '@patternfly/react-icons';
import './final-form-array.css';
import { useFieldApi } from '@data-driven-forms/react-form-renderer';

const ArrayItem = ({ fields, fieldIndex, name, remove, length, minItems }) => {
const ArrayItem = memo(({ fields, fieldIndex, name, remove, length, minItems }) => {
const { renderForm } = useFormApi();

const widths = {
Expand Down Expand Up @@ -60,7 +61,7 @@ const ArrayItem = ({ fields, fieldIndex, name, remove, length, minItems }) => {
</Grid>
</React.Fragment>
);
};
}, ({remove: _prevRemove, ...prev}, {remove: _nextRemove, ...next}) => isEqual(prev, next));

ArrayItem.propTypes = {
name: PropTypes.string,
Expand Down
Loading