Skip to content

Commit a0a464d

Browse files
MgrdichHaarolean
andauthored
[FE] Fix cleanup policy submit/display (#3067)
* TopicForm CleanupPolicy default value clash in the edit page * minor code import modification in topicsParamsTransformer Co-authored-by: Roman Zabaluev <rzabaluev@provectus.com>
1 parent c099fc1 commit a0a464d

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

kafka-ui-react-app/src/components/Topics/Topic/Edit/topicParamsTransformer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
TOPIC_CUSTOM_PARAMS_PREFIX,
55
} from 'lib/constants';
66
import { TOPIC_EDIT_FORM_DEFAULT_PROPS } from 'components/Topics/Topic/Edit/Edit';
7+
import { getCleanUpPolicyValue } from 'components/Topics/shared/Form/TopicForm';
78
import { Topic, TopicConfig } from 'generated-sources';
89

910
export const getValue = (
@@ -30,6 +31,9 @@ const topicParamsTransformer = (topic?: Topic, config?: TopicConfig[]) => {
3031
replicationFactor: topic.replicationFactor,
3132
partitions:
3233
topic.partitionCount || TOPIC_EDIT_FORM_DEFAULT_PROPS.partitions,
34+
cleanupPolicy:
35+
getCleanUpPolicyValue(topic.cleanUpPolicy) ||
36+
TOPIC_EDIT_FORM_DEFAULT_PROPS.cleanupPolicy,
3337
maxMessageBytes: getValue(config, 'max.message.bytes', 1000012),
3438
minInSyncReplicas: getValue(config, 'min.insync.replicas', 1),
3539
retentionBytes: getValue(config, 'retention.bytes', -1),

kafka-ui-react-app/src/components/Topics/shared/Form/TopicForm.tsx

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ const CleanupPolicyOptions: Array<SelectOption> = [
3636
{ value: 'compact,delete', label: 'Compact,Delete' },
3737
];
3838

39+
export const getCleanUpPolicyValue = (cleanUpPolicy?: string) => {
40+
if (!cleanUpPolicy) return undefined;
41+
42+
return CleanupPolicyOptions.find((option: SelectOption) => {
43+
return (
44+
option.value.toString().replace(/,/g, '_') ===
45+
cleanUpPolicy?.toLowerCase()
46+
);
47+
})?.value.toString();
48+
};
49+
3950
const RetentionBytesOptions: Array<SelectOption> = [
4051
{ value: NOT_SET, label: 'Not Set' },
4152
{ value: BYTES_IN_GB, label: '1 GB' },
@@ -61,12 +72,7 @@ const TopicForm: React.FC<Props> = ({
6172
const navigate = useNavigate();
6273
const { clusterName } = useAppParams<{ clusterName: ClusterName }>();
6374
const getCleanUpPolicy =
64-
CleanupPolicyOptions.find((option: SelectOption) => {
65-
return (
66-
option.value.toString().replace(/,/g, '_') ===
67-
cleanUpPolicy?.toLowerCase()
68-
);
69-
})?.value || CleanupPolicyOptions[0].value;
75+
getCleanUpPolicyValue(cleanUpPolicy) || CleanupPolicyOptions[0].value;
7076

7177
const getRetentionBytes =
7278
RetentionBytesOptions.find((option: SelectOption) => {
@@ -97,8 +103,8 @@ const TopicForm: React.FC<Props> = ({
97103
</S.NameField>
98104
</S.Column>
99105

100-
{!isEditing && (
101-
<S.Column>
106+
<S.Column>
107+
{!isEditing && (
102108
<div>
103109
<InputLabel htmlFor="topicFormNumberOfPartitions">
104110
Number of partitions *
@@ -114,32 +120,33 @@ const TopicForm: React.FC<Props> = ({
114120
<ErrorMessage errors={errors} name="partitions" />
115121
</FormError>
116122
</div>
117-
<div>
118-
<InputLabel
119-
id="topicFormCleanupPolicyLabel"
120-
htmlFor="topicFormCleanupPolicy"
121-
>
122-
Cleanup policy
123-
</InputLabel>
124-
<Controller
125-
defaultValue={CleanupPolicyOptions[0].value}
126-
control={control}
127-
name="cleanupPolicy"
128-
render={({ field: { name, onChange } }) => (
129-
<Select
130-
id="topicFormCleanupPolicy"
131-
aria-labelledby="topicFormCleanupPolicyLabel"
132-
name={name}
133-
value={getCleanUpPolicy}
134-
onChange={onChange}
135-
minWidth="250px"
136-
options={CleanupPolicyOptions}
137-
/>
138-
)}
139-
/>
140-
</div>
141-
</S.Column>
142-
)}
123+
)}
124+
125+
<div>
126+
<InputLabel
127+
id="topicFormCleanupPolicyLabel"
128+
htmlFor="topicFormCleanupPolicy"
129+
>
130+
Cleanup policy
131+
</InputLabel>
132+
<Controller
133+
defaultValue={CleanupPolicyOptions[0].value}
134+
control={control}
135+
name="cleanupPolicy"
136+
render={({ field: { name, onChange } }) => (
137+
<Select
138+
id="topicFormCleanupPolicy"
139+
aria-labelledby="topicFormCleanupPolicyLabel"
140+
name={name}
141+
value={getCleanUpPolicy}
142+
onChange={onChange}
143+
minWidth="250px"
144+
options={CleanupPolicyOptions}
145+
/>
146+
)}
147+
/>
148+
</div>
149+
</S.Column>
143150
</fieldset>
144151

145152
<S.Column>

0 commit comments

Comments
 (0)