@@ -12,36 +12,65 @@ import {
12
12
FlexRow ,
13
13
} from 'widgets/ClusterConfigForm/ClusterConfigForm.styled' ;
14
14
import SectionHeader from 'widgets/ClusterConfigForm/common/SectionHeader' ;
15
- import { Serde } from 'widgets/ClusterConfigForm/types' ;
16
15
17
- const Serdes = ( ) => {
18
- const { control, reset , getValues } = useFormContext ( ) ;
16
+ const PropertiesFields = ( { nestedId } : { nestedId : number } ) => {
17
+ const { control } = useFormContext ( ) ;
19
18
const { fields, append, remove } = useFieldArray ( {
20
19
control,
21
- name : ' serde' ,
20
+ name : ` serde. ${ nestedId } .properties` ,
22
21
} ) ;
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 ( {
28
70
control,
29
- name : 'properties ' ,
71
+ name : 'serde ' ,
30
72
} ) ;
31
73
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
-
45
74
const handleAppend = ( ) =>
46
75
append ( {
47
76
name : '' ,
@@ -109,54 +138,7 @@ const Serdes = () => {
109
138
withError
110
139
/>
111
140
< 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 } />
160
142
</ FlexGrow1 >
161
143
< S . RemoveButton onClick = { ( ) => remove ( index ) } >
162
144
< IconButtonWrapper aria-label = "deleteProperty" >
0 commit comments