1- import React , { useState } from 'react' ;
1+ import React from 'react' ;
22import { Input , List , Button , Form } from 'antd' ;
33import { PlusOutlined , CloseCircleTwoTone } from '@ant-design/icons' ;
44import ConfigResourceContainer from './ConfigResource'
@@ -7,83 +7,76 @@ import { IDictionary, IResource, IConfig } from '../interfaces'
77interface IProps {
88 dictionary : IDictionary ;
99 config : IConfig ;
10+ setConfig : any ;
1011}
1112
12- function ConfigContainer ( { dictionary, config } :IProps ) {
13- const [ configState , setConfig ] = useState < IConfig > ( config ) ;
14-
13+ function ConfigContainer ( { dictionary, config, setConfig } :IProps ) {
1514 const handleFeaturePathsChange = ( index ) => {
1615 return ( e ) => {
17- let featurePaths = configState . features_path ;
16+ let featurePaths = config . features_path ;
1817 featurePaths [ index ] = e . target . value ;
1918
2019 setConfig ( {
21- features_path : configState . features_path . map ( ( val , i ) => {
20+ features_path : config . features_path . map ( ( val , i ) => {
2221 if ( i === index ) return e . target . value ;
2322 return val ;
2423 } ) ,
25- resources : configState . resources
24+ resources : config . resources
2625 } )
2726 }
2827 }
2928 const handleFeaturePathsDelete = ( index ) => {
3029 return ( ) => {
3130 setConfig ( {
32- features_path : configState . features_path . filter ( ( item , i ) => index !== i ) ,
33- resources : configState . resources
31+ features_path : config . features_path . filter ( ( item , i ) => index !== i ) ,
32+ resources : config . resources
3433 } )
3534 }
3635 }
3736 const handleFeaturePathsAdd = ( ) => {
3837 setConfig ( {
39- features_path : [ ...configState . features_path , `somewhere/features-${ configState . features_path . length } ` ] ,
40- resources : configState . resources
38+ features_path : [ ...config . features_path , `somewhere/features-${ config . features_path . length } ` ] ,
39+ resources : config . resources
4140 } )
4241 }
4342
4443 const handleResourceItemChange = ( selectedName : string , newItem : IResource | null ) => {
4544 if ( newItem === null ) return handleResourceItemRemove ( selectedName ) ;
46- const newResourceItem = configState . resources . map ( ( item : IResource ) => {
45+ const newResourceItem = config . resources . map ( ( item : IResource ) => {
4746 if ( item . name === selectedName ) {
4847 return newItem ;
4948 }
5049 return item ;
5150 } ) ;
5251
5352 setConfig ( {
54- features_path : configState . features_path ,
53+ features_path : config . features_path ,
5554 resources : newResourceItem
5655 } ) ;
5756 }
5857
5958 const handleResourceItemRemove = ( selectedName : string ) => {
60- const newResourceItems = configState . resources . filter ( ( item : IResource ) => {
59+ const newResourceItems = config . resources . filter ( ( item : IResource ) => {
6160 return ( item . name !== selectedName )
6261 } ) ;
6362
6463 setConfig ( {
65- features_path : configState . features_path ,
64+ features_path : config . features_path ,
6665 resources : newResourceItems
6766 } ) ;
6867 }
6968
7069 const handleAddResourceItem = ( ) => {
7170 const newResourceItem = {
72- name : `new-${ configState . resources . length } ` ,
73- type : " wiremock" ,
71+ name : `new-${ config . resources . length } ` ,
72+ type : ' wiremock' ,
7473 parameters : { }
7574 } ;
76-
7775 setConfig ( {
78- features_path : configState . features_path ,
79- resources : [ ...configState . resources , newResourceItem ]
76+ features_path : config . features_path ,
77+ resources : [ ...config . resources , newResourceItem ]
8078 } ) ;
8179 }
82-
83-
84- const handleSave = ( ) => {
85-
86- }
8780
8881 return (
8982 < div className = "App" >
@@ -92,10 +85,11 @@ function ConfigContainer({ dictionary, config }:IProps) {
9285 < strong > Features Path</ strong >
9386 < List
9487 itemLayout = "horizontal"
95- dataSource = { configState . features_path }
88+ dataSource = { config . features_path }
9689 renderItem = { ( item , index ) => (
9790 < List . Item >
9891 < Input
92+ key = { index }
9993 style = { { width : '300px' } }
10094 onChange = { handleFeaturePathsChange ( index ) }
10195 placeholder = "Features path"
@@ -114,10 +108,13 @@ function ConfigContainer({ dictionary, config }:IProps) {
114108 </ Button >
115109 </ div >
116110 < table style = { { width : '100%' } } >
117- < tr >
118- < th > Resources</ th >
119- </ tr >
120- { configState . resources . map ( ( item , index ) => {
111+ < thead >
112+ < tr >
113+ < th > Resources</ th >
114+ </ tr >
115+ </ thead >
116+ < tbody >
117+ { config . resources . map ( ( item , index ) => {
121118 return (
122119 < ConfigResourceContainer
123120 key = { index }
@@ -127,27 +124,25 @@ function ConfigContainer({ dictionary, config }:IProps) {
127124 />
128125 ) ;
129126 } ) }
130- < tr >
131- < td colSpan = { 3 } >
132- < Form . Item >
133- < Button
134- style = { { height : '60px' } }
135- type = "dashed"
136- onClick = { handleAddResourceItem }
137- block
138- >
139- < PlusOutlined /> Add new resource
140- </ Button >
141- </ Form . Item >
142- </ td >
143- </ tr >
127+ </ tbody >
128+ < tfoot >
129+ < tr >
130+ < td colSpan = { 3 } >
131+ < Form . Item >
132+ < Button
133+ style = { { height : '60px' } }
134+ type = "dashed"
135+ onClick = { handleAddResourceItem }
136+ block
137+ >
138+ < PlusOutlined /> Add new resource
139+ </ Button >
140+ </ Form . Item >
141+ </ td >
142+ </ tr >
143+ </ tfoot >
144144 </ table >
145-
146- < Button onClick = { handleSave } type = "primary" >
147- Save
148- </ Button >
149-
150- < div > { JSON . stringify ( configState ) } </ div >
145+ < div > { JSON . stringify ( config ) } </ div >
151146 </ div >
152147 ) ;
153148}
0 commit comments