From fb1536ef79da4694d377435448607c50b3a2a5dd Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 15:34:51 -0700 Subject: [PATCH] clean selected field values when switching data source on create page (#742) (#743) * clean selected field values when switching data source on create page Signed-off-by: Jackie Han * update snapshot for create page Signed-off-by: Jackie Han --------- Signed-off-by: Jackie Han (cherry picked from commit 0335282a2d2b823f2d68a1c6ee9b1c7bf2031228) Co-authored-by: Jackie Han --- .../components/Datasource/DataSource.tsx | 10 ++++++++-- .../containers/DefineDetector.tsx | 18 ++++++++++-------- .../__snapshots__/DefineDetector.test.tsx.snap | 14 +++++++------- 3 files changed, 25 insertions(+), 17 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' 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