diff --git a/public/pages/DefineDetector/components/Datasource/DataSource.tsx b/public/pages/DefineDetector/components/Datasource/DataSource.tsx index 4fbc882d..904e1b0b 100644 --- a/public/pages/DefineDetector/components/Datasource/DataSource.tsx +++ b/public/pages/DefineDetector/components/Datasource/DataSource.tsx @@ -10,7 +10,7 @@ */ import { EuiComboBox, EuiCallOut, EuiSpacer } from '@elastic/eui'; -import { Field, FieldProps, FormikProps } from 'formik'; +import { Field, FieldProps, FormikProps, useFormikContext } from 'formik'; import { debounce, get } from 'lodash'; import React, { useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; @@ -58,7 +58,13 @@ export function DataSource(props: DataSourceProps) { ); const [queryText, setQueryText] = useState(''); const opensearchState = useSelector((state: AppState) => state.opensearch); + const { setFieldValue } = useFormikContext(); + useEffect(() => { + setFieldValue('index', []); + setFieldValue('timeField', undefined); + setFieldValue('filters', []); + const getInitialIndices = async () => { await dispatch(getIndices(queryText, dataSourceId)); }; @@ -102,7 +108,7 @@ export function DataSource(props: DataSourceProps) { const visibleAliases = get(opensearchState, 'aliases', []) as IndexAlias[]; return ( - + {props.isEdit && isDifferentIndex() ? (
{ // If no detector found with ID, redirect it to list useEffect(() => { - const { history, location } = props; - const updatedParams = { - dataSourceId: MDSCreateState.selectedDataSourceId, - }; - history.replace({ - ...location, - search: queryString.stringify(updatedParams), - }); + if (dataSourceEnabled) { + const { history, location } = props; + const updatedParams = { + dataSourceId: MDSCreateState.selectedDataSourceId, + }; + history.replace({ + ...location, + search: queryString.stringify(updatedParams), + }); + } if (props.isEdit && hasError) { core.notifications.toasts.addDanger( 'Unable to find the detector for editing' diff --git a/public/pages/DefineDetector/containers/__tests__/__snapshots__/DefineDetector.test.tsx.snap b/public/pages/DefineDetector/containers/__tests__/__snapshots__/DefineDetector.test.tsx.snap index 7c86c166..93f0c0c4 100644 --- a/public/pages/DefineDetector/containers/__tests__/__snapshots__/DefineDetector.test.tsx.snap +++ b/public/pages/DefineDetector/containers/__tests__/__snapshots__/DefineDetector.test.tsx.snap @@ -198,7 +198,7 @@ exports[` Full creating detector definition renders the compon class="euiTitle euiTitle--small" data-test-subj="contentPanelTitle" > - Data Source + Select Data
Full creating detector definition renders the compon data-test-subj="comboBoxInput" tabindex="-1" > - - timestamp - + Find timestamp +

empty creating detector definition renders the compo class="euiTitle euiTitle--small" data-test-subj="contentPanelTitle" > - Data Source + Select Data
empty editing detector definition renders the compon class="euiTitle euiTitle--small" data-test-subj="contentPanelTitle" > - Data Source + Select Data