mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Fleet][Kafka] Headers and topics changes trigger hasChanged (#166062)
https://github.com/elastic/kibana/issues/165976
Proper onChange function for headers and topics fields that now
correctly triggers `hasChanged` property resulting in activating `Save`
button as soon as any change is made.
935aee94
-d4c3-424e-9481-32103eeb5b04
This commit is contained in:
parent
26ba212c44
commit
9578950404
2 changed files with 32 additions and 13 deletions
|
@ -38,8 +38,15 @@ export const OutputFormKafkaHeaders: React.FunctionComponent<{ inputs: OutputFor
|
|||
|
||||
const handleKeyValuePairChange = useCallback(
|
||||
(index: number, field: 'key' | 'value', value: string) => {
|
||||
const updatedPairs = [...keyValuePairs];
|
||||
updatedPairs[index][field] = value;
|
||||
const updatedPairs = keyValuePairs.map((pair, i) => {
|
||||
if (i === index) {
|
||||
return {
|
||||
...pair,
|
||||
[field]: value,
|
||||
};
|
||||
}
|
||||
return pair;
|
||||
});
|
||||
onChange(updatedPairs);
|
||||
},
|
||||
[keyValuePairs, onChange]
|
||||
|
|
|
@ -94,17 +94,29 @@ export const OutputFormKafkaTopics: React.FunctionComponent<{ inputs: OutputForm
|
|||
|
||||
const handleTopicProcessorChange = useCallback(
|
||||
(index: number, field: 'topic' | 'condition' | 'type', value: string) => {
|
||||
const updatedPairs = [...topics];
|
||||
if (field === 'topic') {
|
||||
updatedPairs[index].topic = value;
|
||||
} else {
|
||||
updatedPairs[index].when = {
|
||||
...(updatedPairs[index].when || {}),
|
||||
...((field === 'condition' ? { condition: value } : {}) as { condition?: string }),
|
||||
...((field === 'type' ? { type: value } : {}) as { type?: ValueOf<KafkaTopicWhenType> }),
|
||||
};
|
||||
}
|
||||
onChange(updatedPairs);
|
||||
const updatedTopics = topics.map((topic, i) => {
|
||||
if (i === index) {
|
||||
if (field === 'topic') {
|
||||
return {
|
||||
...topic,
|
||||
topic: value,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
...topic,
|
||||
when: {
|
||||
...(topic.when || {}),
|
||||
...((field === 'condition' ? { condition: value } : {}) as { condition?: string }),
|
||||
...((field === 'type' ? { type: value } : {}) as {
|
||||
type?: ValueOf<KafkaTopicWhenType>;
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
return topic;
|
||||
});
|
||||
onChange(updatedTopics);
|
||||
},
|
||||
[topics, onChange]
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue