From b95e31029dd8586e69bd749433892eb084cee45e Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Mon, 29 Apr 2024 14:38:04 -0700 Subject: [PATCH 1/2] clean selected field values when switching data source on create page Signed-off-by: Jackie Han --- .../components/Datasource/DataSource.tsx | 10 ++++++++-- .../containers/DefineDetector.tsx | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) 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' From 17744f9bda6794f583e7acdbd4033dd5ab5b0aad Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Mon, 29 Apr 2024 15:09:49 -0700 Subject: [PATCH 2/2] update snapshot for create page Signed-off-by: Jackie Han --- .../__snapshots__/DefineDetector.test.tsx.snap | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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