diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_kafka_headers.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_kafka_headers.tsx index 89ff4b5d0de7a..9687b81be5698 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_kafka_headers.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_kafka_headers.tsx @@ -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] diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_kafka_topics.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_kafka_topics.tsx index 55b76ccf84c57..9360a5c35bcd5 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_kafka_topics.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/edit_output_flyout/output_form_kafka_topics.tsx @@ -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 }), - }; - } - 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; + }), + }, + }; + } + } + return topic; + }); + onChange(updatedTopics); }, [topics, onChange] );