Skip to content
  • Sponsor kafbat/kafka-ui

  • Notifications You must be signed in to change notification settings
  • Fork 147

Commit 123d071

Browse files
committedMar 8, 2025
fix: properties fields array
1 parent 17f4125 commit 123d071

File tree

3 files changed

+62
-73
lines changed

3 files changed

+62
-73
lines changed
 
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as React from 'react';
2+
import * as S from 'widgets/ClusterConfigForm/ClusterConfigForm.styled';
3+
import { Button } from 'components/common/Button/Button';
4+
import Input from 'components/common/Input/Input';
5+
import { useFieldArray, useFormContext } from 'react-hook-form';
6+
import PlusIcon from 'components/common/Icons/PlusIcon';
7+
import CloseCircleIcon from 'components/common/Icons/CloseCircleIcon';
8+
import Heading from 'components/common/heading/Heading.styled';
9+
10+
const PropertiesFields = ({ nestedId }: { nestedId: number }) => {
11+
const { control } = useFormContext();
12+
const { fields, append, remove } = useFieldArray({
13+
control,
14+
name: `serde.${nestedId}.properties`,
15+
});
16+
17+
return (
18+
<S.GroupFieldWrapper>
19+
<Heading level={4}>Serde properties</Heading>
20+
{fields.map((propsField, propsIndex) => (
21+
<S.SerdeProperties key={propsField.id}>
22+
<Input
23+
name={`serde.${nestedId}.properties.${propsIndex}.key`}
24+
placeholder="Key"
25+
type="text"
26+
withError
27+
/>
28+
<Input
29+
name={`serde.${nestedId}.properties.${propsIndex}.value`}
30+
placeholder="Value"
31+
type="text"
32+
withError
33+
/>
34+
<S.SerdePropertiesActions
35+
aria-label="deleteProperty"
36+
onClick={() => remove(propsIndex)}
37+
>
38+
<CloseCircleIcon aria-hidden />
39+
</S.SerdePropertiesActions>
40+
</S.SerdeProperties>
41+
))}
42+
<div>
43+
<Button
44+
type="button"
45+
buttonSize="M"
46+
buttonType="secondary"
47+
onClick={() => append({ key: '', value: '' })}
48+
>
49+
<PlusIcon />
50+
Add Property
51+
</Button>
52+
</div>
53+
</S.GroupFieldWrapper>
54+
);
55+
};
56+
57+
export default PropertiesFields;

‎frontend/src/widgets/ClusterConfigForm/Sections/Serdes.tsx renamed to ‎frontend/src/widgets/ClusterConfigForm/Sections/Serdes/Serdes.tsx

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,20 @@ import { useFieldArray, useFormContext } from 'react-hook-form';
66
import PlusIcon from 'components/common/Icons/PlusIcon';
77
import IconButtonWrapper from 'components/common/Icons/IconButtonWrapper';
88
import CloseCircleIcon from 'components/common/Icons/CloseCircleIcon';
9-
import Heading from 'components/common/heading/Heading.styled';
109
import {
1110
FlexGrow1,
1211
FlexRow,
1312
} from 'widgets/ClusterConfigForm/ClusterConfigForm.styled';
1413
import SectionHeader from 'widgets/ClusterConfigForm/common/SectionHeader';
15-
import { Serde } from 'widgets/ClusterConfigForm/types';
14+
15+
import PropertiesFields from './PropertiesFields';
1616

1717
const Serdes = () => {
18-
const { control, reset, getValues } = useFormContext();
18+
const { control } = useFormContext();
1919
const { fields, append, remove } = useFieldArray({
2020
control,
2121
name: 'serde',
2222
});
23-
const {
24-
fields: propsFields,
25-
append: appendProps,
26-
remove: removeProps,
27-
} = useFieldArray({
28-
control,
29-
name: 'properties',
30-
});
31-
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-
}, []);
4423

4524
const handleAppend = () =>
4625
append({
@@ -109,54 +88,7 @@ const Serdes = () => {
10988
withError
11089
/>
11190
<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>
91+
<PropertiesFields nestedId={index} />
16092
</FlexGrow1>
16193
<S.RemoveButton onClick={() => remove(index)}>
16294
<IconButtonWrapper aria-label="deleteProperty">

‎frontend/src/widgets/ClusterConfigForm/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { useNavigate } from 'react-router-dom';
1717
import useBoolean from 'lib/hooks/useBoolean';
1818
import KafkaCluster from 'widgets/ClusterConfigForm/Sections/KafkaCluster';
1919
import SchemaRegistry from 'widgets/ClusterConfigForm/Sections/SchemaRegistry';
20-
import Serdes from 'widgets/ClusterConfigForm/Sections/Serdes';
20+
import Serdes from 'widgets/ClusterConfigForm/Sections/Serdes/Serdes';
2121
import KafkaConnect from 'widgets/ClusterConfigForm/Sections/KafkaConnect';
2222
import Metrics from 'widgets/ClusterConfigForm/Sections/Metrics';
2323
import CustomAuthentication from 'widgets/ClusterConfigForm/Sections/CustomAuthentication';

0 commit comments

Comments
 (0)