@@ -12,36 +12,65 @@ import {
1212 FlexRow ,
1313} from 'widgets/ClusterConfigForm/ClusterConfigForm.styled' ;
1414import SectionHeader from 'widgets/ClusterConfigForm/common/SectionHeader' ;
15- import { Serde } from 'widgets/ClusterConfigForm/types' ;
1615
17- const Serdes = ( ) => {
18- const { control, reset , getValues } = useFormContext ( ) ;
16+ const PropertiesFields = ( { nestedId } : { nestedId : number } ) => {
17+ const { control } = useFormContext ( ) ;
1918 const { fields, append, remove } = useFieldArray ( {
2019 control,
21- name : ' serde' ,
20+ name : ` serde. ${ nestedId } .properties` ,
2221 } ) ;
23- const {
24- fields : propsFields ,
25- append : appendProps ,
26- remove : removeProps ,
27- } = useFieldArray ( {
22+
23+ return (
24+ < S . GroupFieldWrapper >
25+ < Heading level = { 4 } > Serde properties</ Heading >
26+ { fields . map ( ( propsField , propsIndex ) => (
27+ < S . SerdeProperties key = { propsField . id } >
28+ < div >
29+ < Input
30+ name = { `serde.${ nestedId } .properties.${ propsIndex } .key` }
31+ placeholder = "Key"
32+ type = "text"
33+ withError
34+ />
35+ </ div >
36+ < div >
37+ < Input
38+ name = { `serde.${ nestedId } .properties.${ propsIndex } .value` }
39+ placeholder = "Value"
40+ type = "text"
41+ withError
42+ />
43+ </ div >
44+ < S . SerdePropertiesActions
45+ aria-label = "deleteProperty"
46+ onClick = { ( ) => remove ( propsIndex ) }
47+ >
48+ < CloseCircleIcon aria-hidden />
49+ </ S . SerdePropertiesActions >
50+ </ S . SerdeProperties >
51+ ) ) }
52+ < div >
53+ < Button
54+ type = "button"
55+ buttonSize = "M"
56+ buttonType = "secondary"
57+ onClick = { ( ) => append ( { key : '' , value : '' } ) }
58+ >
59+ < PlusIcon />
60+ Add Property
61+ </ Button >
62+ </ div >
63+ </ S . GroupFieldWrapper >
64+ ) ;
65+ } ;
66+
67+ const Serdes = ( ) => {
68+ const { control } = useFormContext ( ) ;
69+ const { fields, append, remove } = useFieldArray ( {
2870 control,
29- name : 'properties ' ,
71+ name : 'serde ' ,
3072 } ) ;
3173
32- React . useEffect ( ( ) => {
33- reset ( ) ;
34- getValues ( ) . serde ?. forEach ( ( item : Serde , index : number ) => {
35- item . properties ?. forEach ( ( itemProp ) => {
36- appendProps ( {
37- key : itemProp . key ,
38- value : itemProp . value ,
39- serdeIndex : index ,
40- } ) ;
41- } ) ;
42- } ) ;
43- } , [ ] ) ;
44-
4574 const handleAppend = ( ) =>
4675 append ( {
4776 name : '' ,
@@ -109,54 +138,7 @@ const Serdes = () => {
109138 withError
110139 />
111140 < hr />
112- < S . GroupFieldWrapper >
113- < Heading level = { 4 } > Serde properties</ Heading >
114- { propsFields
115- . filter (
116- ( propItem ) =>
117- ( propItem as unknown as { serdeIndex : number } )
118- . serdeIndex === index
119- )
120- . map ( ( propsField , propsIndex ) => (
121- < S . SerdeProperties key = { propsField . id } >
122- < div >
123- < Input
124- name = { `serde.${ index } .properties.${ propsIndex } .key` }
125- placeholder = "Key"
126- type = "text"
127- withError
128- />
129- </ div >
130- < div >
131- < Input
132- name = { `serde.${ index } .properties.${ propsIndex } .value` }
133- placeholder = "Value"
134- type = "text"
135- withError
136- />
137- </ div >
138- < S . SerdePropertiesActions
139- aria-label = "deleteProperty"
140- onClick = { ( ) => removeProps ( index ) }
141- >
142- < CloseCircleIcon aria-hidden />
143- </ S . SerdePropertiesActions >
144- </ S . SerdeProperties >
145- ) ) }
146- < div >
147- < Button
148- type = "button"
149- buttonSize = "M"
150- buttonType = "secondary"
151- onClick = { ( ) =>
152- appendProps ( { key : '' , value : '' , serdeIndex : index } )
153- }
154- >
155- < PlusIcon />
156- Add Property
157- </ Button >
158- </ div >
159- </ S . GroupFieldWrapper >
141+ < PropertiesFields nestedId = { index } />
160142 </ FlexGrow1 >
161143 < S . RemoveButton onClick = { ( ) => remove ( index ) } >
162144 < IconButtonWrapper aria-label = "deleteProperty" >
0 commit comments