Skip to content

Commit d705b19

Browse files
authored
Merge pull request #458 from data-driven-forms/file-input
fix(all): enable input type file
2 parents cb848f0 + f654c4d commit d705b19

File tree

17 files changed

+297
-119
lines changed

17 files changed

+297
-119
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ exports[`<Input Addon> should render group button before input addon correctly 1
8484
"update": [Function],
8585
}
8686
}
87-
onSubmit={[MockFunction]}
87+
onSubmit={[Function]}
8888
render={[Function]}
8989
subscription={
9090
Object {
@@ -760,7 +760,7 @@ exports[`<Input Addon> should render group mixed before input addon correctly 1`
760760
"update": [Function],
761761
}
762762
}
763-
onSubmit={[MockFunction]}
763+
onSubmit={[Function]}
764764
render={[Function]}
765765
subscription={
766766
Object {
@@ -1498,7 +1498,7 @@ exports[`<Input Addon> should render single after input addon correctly 1`] = `
14981498
"update": [Function],
14991499
}
15001500
}
1501-
onSubmit={[MockFunction]}
1501+
onSubmit={[Function]}
15021502
render={[Function]}
15031503
subscription={
15041504
Object {
@@ -1942,7 +1942,7 @@ exports[`<Input Addon> should render single before input addon correctly 1`] = `
19421942
"update": [Function],
19431943
}
19441944
}
1945-
onSubmit={[MockFunction]}
1945+
onSubmit={[Function]}
19461946
render={[Function]}
19471947
subscription={
19481948
Object {
@@ -2385,7 +2385,7 @@ exports[`<Input Addon> should render single button after input addon correctly 1
23852385
"update": [Function],
23862386
}
23872387
}
2388-
onSubmit={[MockFunction]}
2388+
onSubmit={[Function]}
23892389
render={[Function]}
23902390
subscription={
23912391
Object {
@@ -2834,7 +2834,7 @@ exports[`<Input Addon> should render single button before input addon correctly
28342834
"update": [Function],
28352835
}
28362836
}
2837-
onSubmit={[MockFunction]}
2837+
onSubmit={[Function]}
28382838
render={[Function]}
28392839
subscription={
28402840
Object {
@@ -3419,7 +3419,7 @@ exports[`<Input Addon> should render the ultimate input addon correctly 1`] = `
34193419
"update": [Function],
34203420
}
34213421
}
3422-
onSubmit={[MockFunction]}
3422+
onSubmit={[Function]}
34233423
render={[Function]}
34243424
subscription={
34253425
Object {

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

Lines changed: 38 additions & 4 deletions
Large diffs are not rendered by default.

packages/pf4-component-mapper/src/files/dual-list-select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ const DualList = (props) => {
198198
filterValueTitle,
199199
filterValueText,
200200
filterOptionsText,
201+
isEqual: _isEqual,
201202
...rest
202203
} = useFieldApi({
203204
...props,
204205
isEqual: (current, initial) => isEqual([...(current || [])].sort(), [...(initial || [])].sort())
205206
});
206207

207208
const showError = touched && error;
208-
209209
const handleOptionClicked = (event, value, options, isRight) => {
210210
const selectedKey = isRight ? 'selectedLeftValues' : 'selectedRightValues';
211211
const lastKey = isRight ? 'lastLeftClicked' : 'lastRightClicked';

packages/pf4-component-mapper/src/tests/dual-list-select.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
2+
import { act } from 'react-dom/test-utils';
23
import FormRenderer from '@data-driven-forms/react-form-renderer';
34
import { mount } from 'enzyme';
4-
import { act } from 'react-dom/test-utils';
55

66
import { FormGroup, TextInput } from '@patternfly/react-core';
77
import { DataToolbar } from '@patternfly/react-core/dist/js/experimental';
@@ -252,6 +252,7 @@ describe('DualListSelect', () => {
252252
.simulate('click');
253253
});
254254
wrapper.update();
255+
255256
await act(async () => {
256257
wrapper
257258
.find(AngleLeftIcon)

packages/pf4-component-mapper/src/tests/wizard/__snapshots__/wizard.test.js.snap

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
8181
"update": [Function],
8282
}
8383
}
84-
onSubmit={[MockFunction]}
84+
onSubmit={[Function]}
8585
render={[Function]}
8686
subscription={
8787
Object {
@@ -462,6 +462,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
462462
"pristine": true,
463463
"push": [Function],
464464
"registerField": [Function],
465+
"registerInputFile": [Function],
465466
"remove": [Function],
466467
"removeBatch": [Function],
467468
"renderForm": [Function],
@@ -473,6 +474,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
473474
"submit": [Function],
474475
"subscribe": [Function],
475476
"swap": [Function],
477+
"unRegisterInputFile": [Function],
476478
"unshift": [Function],
477479
"update": [Function],
478480
"valid": true,
@@ -672,6 +674,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
672674
"pristine": true,
673675
"push": [Function],
674676
"registerField": [Function],
677+
"registerInputFile": [Function],
675678
"remove": [Function],
676679
"removeBatch": [Function],
677680
"renderForm": [Function],
@@ -683,6 +686,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
683686
"submit": [Function],
684687
"subscribe": [Function],
685688
"swap": [Function],
689+
"unRegisterInputFile": [Function],
686690
"unshift": [Function],
687691
"update": [Function],
688692
"valid": true,
@@ -842,6 +846,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
842846
"pristine": true,
843847
"push": [Function],
844848
"registerField": [Function],
849+
"registerInputFile": [Function],
845850
"remove": [Function],
846851
"removeBatch": [Function],
847852
"renderForm": [Function],
@@ -853,6 +858,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
853858
"submit": [Function],
854859
"subscribe": [Function],
855860
"swap": [Function],
861+
"unRegisterInputFile": [Function],
856862
"unshift": [Function],
857863
"update": [Function],
858864
"valid": true,
@@ -893,6 +899,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
893899
pristine={true}
894900
push={[Function]}
895901
registerField={[Function]}
902+
registerInputFile={[Function]}
896903
remove={[Function]}
897904
removeBatch={[Function]}
898905
renderForm={[Function]}
@@ -905,6 +912,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
905912
submitLabel="Submit"
906913
subscribe={[Function]}
907914
swap={[Function]}
915+
unRegisterInputFile={[Function]}
908916
unshift={[Function]}
909917
update={[Function]}
910918
valid={true}
@@ -1152,7 +1160,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
11521160
"update": [Function],
11531161
}
11541162
}
1155-
onSubmit={[MockFunction]}
1163+
onSubmit={[Function]}
11561164
render={[Function]}
11571165
subscription={
11581166
Object {
@@ -1542,6 +1550,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
15421550
"pristine": true,
15431551
"push": [Function],
15441552
"registerField": [Function],
1553+
"registerInputFile": [Function],
15451554
"remove": [Function],
15461555
"removeBatch": [Function],
15471556
"renderForm": [Function],
@@ -1553,6 +1562,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
15531562
"submit": [Function],
15541563
"subscribe": [Function],
15551564
"swap": [Function],
1565+
"unRegisterInputFile": [Function],
15561566
"unshift": [Function],
15571567
"update": [Function],
15581568
"valid": true,
@@ -1976,6 +1986,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
19761986
"pristine": true,
19771987
"push": [Function],
19781988
"registerField": [Function],
1989+
"registerInputFile": [Function],
19791990
"remove": [Function],
19801991
"removeBatch": [Function],
19811992
"renderForm": [Function],
@@ -1987,6 +1998,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
19871998
"submit": [Function],
19881999
"subscribe": [Function],
19892000
"swap": [Function],
2001+
"unRegisterInputFile": [Function],
19902002
"unshift": [Function],
19912003
"update": [Function],
19922004
"valid": true,
@@ -2146,6 +2158,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
21462158
"pristine": true,
21472159
"push": [Function],
21482160
"registerField": [Function],
2161+
"registerInputFile": [Function],
21492162
"remove": [Function],
21502163
"removeBatch": [Function],
21512164
"renderForm": [Function],
@@ -2157,6 +2170,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
21572170
"submit": [Function],
21582171
"subscribe": [Function],
21592172
"swap": [Function],
2173+
"unRegisterInputFile": [Function],
21602174
"unshift": [Function],
21612175
"update": [Function],
21622176
"valid": true,
@@ -2197,6 +2211,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
21972211
pristine={true}
21982212
push={[Function]}
21992213
registerField={[Function]}
2214+
registerInputFile={[Function]}
22002215
remove={[Function]}
22012216
removeBatch={[Function]}
22022217
renderForm={[Function]}
@@ -2209,6 +2224,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
22092224
submitLabel="Submit"
22102225
subscribe={[Function]}
22112226
swap={[Function]}
2227+
unRegisterInputFile={[Function]}
22122228
unshift={[Function]}
22132229
update={[Function]}
22142230
valid={true}

packages/react-form-renderer/demo/index.js

Lines changed: 7 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,17 @@
11
/* eslint-disable camelcase */
22
import React from 'react';
33
import ReactDOM from 'react-dom';
4-
import FormRenderer, { validatorTypes } from '../src';
4+
import FormRenderer from '../src';
55
import componentMapper from './form-fields-mapper';
66
import FormTemplate from './form-template';
7-
// import sandboxSchema from './sandbox';
8-
import DefaultSchemaError from '../src/files/schema-errors';
97

10-
const intl = (name) => `translated ${name}`;
11-
12-
const actionMapper = {
13-
loadData: (data) => (...args) =>
14-
new Promise((resolve) => {
15-
setTimeout(() => resolve({ custom: 'ererewr', ...data }), 1700);
16-
}),
17-
loadLabel: intl
18-
};
19-
20-
const validatorMapper = {
21-
asyncValidator: (url, attributes) => (value, allValues) =>
22-
new Promise((resolve, reject) =>
23-
setTimeout(() => {
24-
if (value === 'error') {
25-
reject('Async validation failed');
26-
}
27-
28-
resolve('hola');
29-
}, 1700)
30-
)
31-
};
32-
33-
// eslint-disable-next-line no-unused-vars
34-
const asyncValidatorSchema = {
8+
const fileSchema = {
359
fields: [
36-
{
37-
component: 'composite-mapper-field',
38-
name: 'composite-field',
39-
label: 'Componsite field'
40-
},
4110
{
4211
component: 'text-field',
43-
name: 'async-validation-field',
44-
label: 'Async validation field',
45-
validate: [
46-
{ type: 'asyncValidator' },
47-
{ type: 'required' },
48-
{
49-
type: validatorTypes.PATTERN,
50-
pattern: '^Foo$',
51-
flags: 'i'
52-
}
53-
]
54-
}
55-
]
56-
};
57-
58-
const conditionLogicDemo = {
59-
title: 'Testing Conditions',
60-
description: 'Write X in both',
61-
fields: [
62-
{
63-
name: 'text_box_1',
64-
label: 'Text Box 1',
65-
title: 'Text Box',
66-
component: 'text-field',
67-
clearOnUnmount: true,
68-
condition: {
69-
sequence: [
70-
{ when: 'a', is: 'x', then: { visible: true, set: { password: 'defaultPassword' } }, else: { set: { password: 'no password' } } },
71-
{ when: 'b', is: 'x', then: { visible: true, set: { text_box_1: 'defaultText' } } }
72-
]
73-
}
74-
},
75-
{
76-
name: 'a',
77-
label: 'a',
78-
title: 'a',
79-
component: 'text-field'
80-
},
81-
{
82-
name: 'b',
83-
label: 'b',
84-
title: 'b',
85-
component: 'text-field'
86-
},
87-
{
88-
name: 'password',
89-
label: 'password',
90-
title: 'password',
91-
component: 'text-field'
12+
name: 'file-upload',
13+
type: 'file',
14+
label: 'file upload'
9215
}
9316
]
9417
};
@@ -98,23 +21,10 @@ const App = () => {
9821
return (
9922
<div style={{ padding: 20 }}>
10023
<FormRenderer
101-
validatorMapper={validatorMapper}
10224
componentMapper={componentMapper}
103-
onSubmit={(values) => console.log(values)}
104-
schema={conditionLogicDemo}
25+
onSubmit={(values, ...args) => console.log(values, args)}
10526
FormTemplate={FormTemplate}
106-
actionMapper={actionMapper}
107-
schemaValidatorMapper={{
108-
actions: {
109-
loadLabel: (action, fieldName) => {
110-
if (typeof action[1] !== 'string') {
111-
throw new DefaultSchemaError(
112-
`Second argument of loadLabel action has to be a string: ID of the text from the translated database. Error found in ${fieldName}`
113-
);
114-
}
115-
}
116-
}
117-
}}
27+
schema={fileSchema}
11828
/>
11929
</div>
12030
);

0 commit comments

Comments
 (0)