1- import React from 'react' ;
2- import PropTypes from 'prop-types' ;
3- import _ from 'lodash' ;
1+ import React from "react" ;
2+ import PropTypes from "prop-types" ;
3+ import _ from "lodash" ;
4+ import Input from "./Input" ;
5+ import { InputTypes } from "./ProcessFormUtils" ;
46
5- import LayerInput from ' ../LayerInput' ;
7+ import LayerInput from " ../LayerInput" ;
68// import LayerInput from '../../containers/LayerInputContainer'; todo remove LayerInputContainer
79
8- import './ProcessForm.css' ;
9-
10- const MIME_TYPE = 'application/vnd.geo+json' ;
10+ import "./ProcessForm.css" ;
1111
1212class ProcessForm extends React . Component {
13- constructor ( props ) {
13+ constructor ( props ) {
1414 super ( props ) ;
1515
1616 this . inputValues = [ ] ;
@@ -19,44 +19,63 @@ class ProcessForm extends React.Component {
1919 this . inputGenerator = new window . InputGenerator ( ) ;
2020 }
2121
22- handleAddComplexData ( identifier , value ) {
23- // const value = event.target.value;
24- _ . pullAllBy ( this . inputValues , [ { 'identifier' : identifier } ] , 'identifier' ) ;
25- const newInput = this . inputGenerator . createComplexDataInput_wps_1_0_and_2_0 (
26- identifier , MIME_TYPE , undefined , undefined , true , value ) ;
27- this . inputValues . push ( newInput ) ;
28- // this.props.addLayer('614', event.target.value, 'LAyerName');
22+ handleAddComplexData ( layerId , i ) {
23+ const values = layerId !== undefined ? [ layerId ] : [ ] ;
24+
25+ const identifier = this . props . inputs [ i ] . id ;
26+ let inputs = this . props . inputs . map (
27+ input =>
28+ input . id === identifier
29+ ? Object . assign ( new Input ( ) , input , { values : [ layerId ] } )
30+ : input
31+ ) ;
32+
33+ this . props . onChange ( inputs ) ;
2934 }
3035
31- handleAddLiteralData ( identifier , event ) {
36+ handleAddLiteralData ( event ) {
37+ const i = parseInt ( event . currentTarget . id . replace ( "form-input-" , "" ) ) ;
38+ const identifier = this . props . inputs [ i ] . id ;
3239 const value = event . target . value ;
33- _ . pullAllBy ( this . inputValues , [ { 'identifier' : identifier } ] , 'identifier' ) ;
34- const newInput = this . inputGenerator . createLiteralDataInput_wps_1_0_and_2_0 (
35- identifier , undefined , undefined , value ) ;
36- this . inputValues . push ( newInput ) ;
37- // this.props.addLayer('614', event.target.value, 'LAyerName');
40+
41+ const values = value ? [ value ] : [ ] ;
42+ let inputs = this . props . inputs . map (
43+ input =>
44+ input . id === identifier
45+ ? Object . assign ( new Input ( ) , input , { values } )
46+ : input
47+ ) ;
48+
49+ this . props . onChange ( inputs ) ;
3850 }
3951
40- render ( ) {
41- const { inputs, handleOnSubmit} = this . props ;
52+ render ( ) {
53+ const { inputs, handleOnSubmit } = this . props ;
4254 return (
4355 < form >
44- { inputs . map ( input =>
56+ { inputs . map ( ( formInput , i ) => (
4557 < div >
46- < h3 > { input . title } </ h3 >
47- < p > { input . abstractValue } </ p >
48- { input . hasOwnProperty ( 'complexData' )
49- ? < LayerInput
58+ < h3 > { formInput . title } </ h3 >
59+ < p > { formInput . abstractValue } </ p >
60+ { formInput . type === InputTypes . COMPLEX ? (
61+ < LayerInput
5062 layers = { this . props . layers }
51- key = { input . identifier }
52- addLayer = { this . handleAddComplexData . bind ( null ,
53- input . identifier ) } />
54- : < input key = { input . identifier }
55- onBlur = { this . handleAddLiteralData . bind ( null ,
56- input . identifier ) }
57- type = "text" /> }
58- </ div > ) }
59- < button type = "button" onClick = { ( ) => handleOnSubmit ( this . inputValues ) } >
63+ key = { i }
64+ id = { i }
65+ onSelect = { this . handleAddComplexData }
66+ />
67+ ) : (
68+ < input
69+ key = { formInput . identifier }
70+ onChange = { this . handleAddLiteralData }
71+ value = { formInput . values [ 0 ] }
72+ id = { `form-input-${ i } ` }
73+ type = "text"
74+ />
75+ ) }
76+ </ div >
77+ ) ) }
78+ < button type = "button" onClick = { this . props . onSubmit } >
6079 Execute
6180 </ button >
6281 </ form >
@@ -66,7 +85,7 @@ class ProcessForm extends React.Component {
6685
6786ProcessForm . propTypes = {
6887 inputs : PropTypes . array . isRequired ,
69- handleOnSubmit : PropTypes . func . isRequired ,
88+ onSubmit : PropTypes . func . isRequired
7089} ;
7190
72- export default ProcessForm ;
91+ export default ProcessForm ;
0 commit comments