[Ingest Pipelines] Fix bug in reroute processor (#162872)

Fixes https://github.com/elastic/kibana/issues/162823

## Summary

This PR fixes the bug in the Reroute processor form which makes the page
crash when switching from another processor type to reroute processor.

**How to test:**

1. Start Es with `yarn es snapshot` and Kibana with `yarn start`.
2. Go to Stack Management > Ingest Pipeline.
3. Click **Create pipeline**, and then select **New pipeline**.
4. Click **Add a processor**.
5. In the **Configure processor** form, open the Processor dropdown, and
select Reroute.
6. From the Processor dropdown, select Bytes (or any other processor
type).
7. From the Processor dropdown, select Reroute.
8. Verify that the form works as expected.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Elena Stoeva 2023-08-02 16:53:55 +01:00 committed by GitHub
parent 9942fdcb2a
commit 190a98f487
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -114,7 +114,10 @@ export const Reroute: FunctionComponent = () => {
const [{ fields }] = useFormData({ watch: ['fields.dataset', 'fields.namespace'] });
useEffect(() => {
if (fields?.dataset.length > 0 || fields?.namespace.length > 0) {
if (
(fields?.dataset && fields.dataset.length > 0) ||
(fields?.namespace && fields.namespace.length > 0)
) {
form.setFieldValue('fields.destination', '');
}
}, [form, fields]);
@ -127,7 +130,9 @@ export const Reroute: FunctionComponent = () => {
component={Field}
componentProps={{
euiFieldProps: {
disabled: fields?.dataset.length > 0 || fields?.namespace.length > 0,
disabled:
(fields?.dataset && fields.dataset.length > 0) ||
(fields?.namespace && fields.namespace.length > 0),
},
}}
path="fields.destination"