Skip to content

Commit faca650

Browse files
authored
Merge pull request #442 from rvsia/mergeRenderUseField
fix(renderer): move functionality from render to useField
2 parents 84fd128 + 636373f commit faca650

File tree

29 files changed

+469
-143
lines changed

29 files changed

+469
-143
lines changed

packages/common/src/wizard/wizard.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import flattenDeep from 'lodash/flattenDeep';
88
import handleEnter from './enter-handler';
99
import reducer, { DYNAMIC_WIZARD_TYPES, findCurrentStep } from './reducer';
1010

11-
const Wizard = ({ fields, isDynamic, crossroads, Wizard, ...props }) => {
11+
const Wizard = ({ fields, isDynamic, crossroads, Wizard, component, ...props }) => {
1212
const formOptions = useFormApi();
1313

1414
const [state, dispatch] = useReducer(reducer, {
@@ -94,7 +94,8 @@ Wizard.propTypes = {
9494
).isRequired,
9595
isDynamic: PropTypes.bool,
9696
crossroads: PropTypes.arrayOf(PropTypes.string),
97-
Wizard: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
97+
Wizard: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
98+
component: PropTypes.any
9899
};
99100

100101
export default Wizard;

packages/mui-component-mapper/src/files/plain-text.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Typography } from '@material-ui/core';
33
import PropTypes from 'prop-types';
44

5-
const PlainText = ({ label, name, ...props }) =>
5+
const PlainText = ({ label, name, component, ...props }) =>
66
label.split('\n').map((paragraph, index) => (
77
<Typography key={`${index}-${name}`} {...props}>
88
{paragraph}
@@ -11,7 +11,8 @@ const PlainText = ({ label, name, ...props }) =>
1111

1212
PlainText.propTypes = {
1313
label: PropTypes.string.isRequired,
14-
name: PropTypes.string.isRequired
14+
name: PropTypes.string.isRequired,
15+
component: PropTypes.any
1516
};
1617

1718
PlainText.defaultProps = {

packages/mui-component-mapper/src/files/sub-form.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const useStyles = makeStyles(() => ({
1212
}
1313
}));
1414

15-
const SubForm = ({ fields, title, description, ...rest }) => {
15+
const SubForm = ({ fields, title, description, component, ...rest }) => {
1616
const { renderForm } = useFormApi();
1717
const classes = useStyles();
1818

@@ -38,7 +38,8 @@ const SubForm = ({ fields, title, description, ...rest }) => {
3838
SubForm.propTypes = {
3939
fields: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
4040
title: PropTypes.string,
41-
description: PropTypes.string
41+
description: PropTypes.string,
42+
component: PropTypes.any
4243
};
4344

4445
export default SubForm;

packages/pf3-component-mapper/src/files/button.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { Button as PFButton } from 'patternfly-react';
44

5-
export const Button = ({ label, variant, dataType, validate, children, ...rest }) => (
5+
export const Button = ({ label, variant, dataType, validate, children, component, ...rest }) => (
66
<PFButton bsStyle={variant} {...rest}>
77
{label || children}
88
</PFButton>
@@ -14,7 +14,8 @@ Button.propTypes = {
1414
className: PropTypes.string,
1515
dataType: PropTypes.any, // should be inside inner props or something
1616
validate: PropTypes.any, // should be inside inner props or something
17-
children: PropTypes.any
17+
children: PropTypes.any,
18+
component: PropTypes.any
1819
};
1920

2021
export default Button;

packages/pf3-component-mapper/src/files/sub-form.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { useFormApi } from '@data-driven-forms/react-form-renderer';
44

5-
const SubForm = ({ fields, title, description, ...rest }) => {
5+
const SubForm = ({ fields, title, description, component, ...rest }) => {
66
const formOptions = useFormApi();
77
return (
88
<div {...rest}>
@@ -16,7 +16,8 @@ const SubForm = ({ fields, title, description, ...rest }) => {
1616
SubForm.propTypes = {
1717
fields: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
1818
title: PropTypes.string,
19-
description: PropTypes.string
19+
description: PropTypes.string,
20+
component: PropTypes.any
2021
};
2122

2223
export default SubForm;

packages/pf3-component-mapper/src/tests/__snapshots__/form-fields.test.js.snap

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ exports[`FormFields <Switch /> should render Switch correctly 1`] = `
390390
>
391391
<Switch
392392
FieldProvider={[Function]}
393-
dataType="someDataType"
394393
id="someIdKey"
395394
input={
396395
Object {
@@ -535,7 +534,6 @@ exports[`FormFields <Switch /> should render Switch with label correctly 1`] = `
535534
>
536535
<Switch
537536
FieldProvider={[Function]}
538-
dataType="someDataType"
539537
id="someIdKey"
540538
input={
541539
Object {
@@ -692,7 +690,6 @@ exports[`FormFields <Switch /> should render Switch with onText (custom prop) co
692690
>
693691
<Switch
694692
FieldProvider={[Function]}
695-
dataType="someDataType"
696693
id="someIdKey"
697694
input={
698695
Object {
@@ -838,7 +835,6 @@ exports[`FormFields <Switch /> should render Switch with placeholder correctly 1
838835
>
839836
<Switch
840837
FieldProvider={[Function]}
841-
dataType="someDataType"
842838
id="someIdKey"
843839
input={
844840
Object {
@@ -984,7 +980,6 @@ exports[`FormFields <Switch /> should render disabled Switch correctly 1`] = `
984980
>
985981
<Switch
986982
FieldProvider={[Function]}
987-
dataType="someDataType"
988983
id="someIdKey"
989984
input={
990985
Object {
@@ -1133,7 +1128,6 @@ exports[`FormFields <Switch /> should render mini Switch correctly 1`] = `
11331128
<Switch
11341129
FieldProvider={[Function]}
11351130
bsSize="mini"
1136-
dataType="someDataType"
11371131
id="someIdKey"
11381132
input={
11391133
Object {
@@ -1279,7 +1273,6 @@ exports[`FormFields <Switch /> should render readOnly Switch correctly 1`] = `
12791273
>
12801274
<Switch
12811275
FieldProvider={[Function]}
1282-
dataType="someDataType"
12831276
id="someIdKey"
12841277
input={
12851278
Object {
@@ -1428,7 +1421,6 @@ exports[`FormFields <Switch /> should render sm Switch correctly 1`] = `
14281421
<Switch
14291422
FieldProvider={[Function]}
14301423
bsSize="mn"
1431-
dataType="someDataType"
14321424
id="someIdKey"
14331425
input={
14341426
Object {

packages/pf3-component-mapper/src/tests/__snapshots__/input-addon.test.js.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ exports[`<Input Addon> should render group button before input addon correctly 1
369369
hideField={false}
370370
>
371371
<TextField
372+
component="text-field"
372373
inputAddon={
373374
Object {
374375
"before": Object {
@@ -523,6 +524,7 @@ exports[`<Input Addon> should render group button before input addon correctly 1
523524
hideField={false}
524525
>
525526
<InputAddonButtonGroup
527+
component="input-addon-button-group"
526528
fields={
527529
Array [
528530
Object {
@@ -558,6 +560,7 @@ exports[`<Input Addon> should render group button before input addon correctly 1
558560
hideField={false}
559561
>
560562
<Button
563+
component="button"
561564
label="Set 1"
562565
name="set1"
563566
onClick={[Function]}
@@ -596,6 +599,7 @@ exports[`<Input Addon> should render group button before input addon correctly 1
596599
hideField={false}
597600
>
598601
<Button
602+
component="button"
599603
label="Set 2"
600604
name="set2"
601605
>
@@ -1083,6 +1087,7 @@ exports[`<Input Addon> should render group mixed before input addon correctly 1`
10831087
hideField={false}
10841088
>
10851089
<TextField
1090+
component="text-field"
10861091
inputAddon={
10871092
Object {
10881093
"before": Object {
@@ -1250,6 +1255,7 @@ exports[`<Input Addon> should render group mixed before input addon correctly 1`
12501255
hideField={false}
12511256
>
12521257
<InputAddonGroup
1258+
component="input-addon-group"
12531259
fields={
12541260
Array [
12551261
Object {
@@ -1280,6 +1286,7 @@ exports[`<Input Addon> should render group mixed before input addon correctly 1`
12801286
hideField={false}
12811287
>
12821288
<PlainText
1289+
component="plain-text"
12831290
label="-"
12841291
name="name1"
12851292
variant="span"
@@ -1318,6 +1325,7 @@ exports[`<Input Addon> should render group mixed before input addon correctly 1`
13181325
hideField={false}
13191326
>
13201327
<InputAddonButtonGroup
1328+
component="input-addon-button-group"
13211329
fields={
13221330
Array [
13231331
Object {
@@ -1346,6 +1354,7 @@ exports[`<Input Addon> should render group mixed before input addon correctly 1`
13461354
hideField={false}
13471355
>
13481356
<Button
1357+
component="button"
13491358
label="Set 3"
13501359
name="set3"
13511360
>
@@ -1697,6 +1706,7 @@ exports[`<Input Addon> should render single after input addon correctly 1`] = `
16971706
hideField={false}
16981707
>
16991708
<TextField
1709+
component="text-field"
17001710
inputAddon={
17011711
Object {
17021712
"after": Object {
@@ -1825,6 +1835,7 @@ exports[`<Input Addon> should render single after input addon correctly 1`] = `
18251835
hideField={false}
18261836
>
18271837
<PlainText
1838+
component="plain-text"
18281839
label="-"
18291840
name="name1"
18301841
variant="span"
@@ -2139,6 +2150,7 @@ exports[`<Input Addon> should render single before input addon correctly 1`] = `
21392150
hideField={false}
21402151
>
21412152
<TextField
2153+
component="text-field"
21422154
inputAddon={
21432155
Object {
21442156
"before": Object {
@@ -2247,6 +2259,7 @@ exports[`<Input Addon> should render single before input addon correctly 1`] = `
22472259
hideField={false}
22482260
>
22492261
<PlainText
2262+
component="plain-text"
22502263
label="-"
22512264
name="name1"
22522265
variant="span"
@@ -2573,6 +2586,7 @@ exports[`<Input Addon> should render single button after input addon correctly 1
25732586
hideField={false}
25742587
>
25752588
<TextField
2589+
component="text-field"
25762590
inputAddon={
25772591
Object {
25782592
"after": Object {
@@ -2697,6 +2711,7 @@ exports[`<Input Addon> should render single button after input addon correctly 1
26972711
hideField={false}
26982712
>
26992713
<Button
2714+
component="button"
27002715
label="Set 3"
27012716
name="set3"
27022717
>
@@ -3062,6 +3077,7 @@ exports[`<Input Addon> should render single button before input addon correctly
30623077
hideField={false}
30633078
>
30643079
<TextField
3080+
component="text-field"
30653081
inputAddon={
30663082
Object {
30673083
"before": Object {
@@ -3192,6 +3208,7 @@ exports[`<Input Addon> should render single button before input addon correctly
31923208
hideField={false}
31933209
>
31943210
<InputAddonButtonGroup
3211+
component="input-addon-button-group"
31953212
fields={
31963213
Array [
31973214
Object {
@@ -3220,6 +3237,7 @@ exports[`<Input Addon> should render single button before input addon correctly
32203237
hideField={false}
32213238
>
32223239
<Button
3240+
component="button"
32233241
label="Set 2"
32243242
name="set2"
32253243
>
@@ -3875,6 +3893,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
38753893
hideField={false}
38763894
>
38773895
<TextField
3896+
component="text-field"
38783897
inputAddon={
38793898
Object {
38803899
"after": Object {
@@ -4110,6 +4129,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
41104129
hideField={false}
41114130
>
41124131
<InputAddonButtonGroup
4132+
component="input-addon-button-group"
41134133
fields={
41144134
Array [
41154135
Object {
@@ -4145,6 +4165,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
41454165
hideField={false}
41464166
>
41474167
<Button
4168+
component="button"
41484169
label="Set 1"
41494170
name="set1"
41504171
onClick={[Function]}
@@ -4183,6 +4204,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
41834204
hideField={false}
41844205
>
41854206
<Button
4207+
component="button"
41864208
label="Set 2"
41874209
name="set2"
41884210
>
@@ -4253,6 +4275,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
42534275
hideField={false}
42544276
>
42554277
<InputAddonGroup
4278+
component="input-addon-group"
42564279
fields={
42574280
Array [
42584281
Object {
@@ -4283,6 +4306,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
42834306
hideField={false}
42844307
>
42854308
<PlainText
4309+
component="plain-text"
42864310
label="-"
42874311
name="name1"
42884312
variant="span"
@@ -4321,6 +4345,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
43214345
hideField={false}
43224346
>
43234347
<InputAddonButtonGroup
4348+
component="input-addon-button-group"
43244349
fields={
43254350
Array [
43264351
Object {
@@ -4349,6 +4374,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
43494374
hideField={false}
43504375
>
43514376
<Button
4377+
component="button"
43524378
label="Set 3"
43534379
name="set3"
43544380
>

0 commit comments

Comments
 (0)