Skip to content

Commit fb1536e

Browse files
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 <jkhanjob@gmail.com> * update snapshot for create page Signed-off-by: Jackie Han <jkhanjob@gmail.com> --------- Signed-off-by: Jackie Han <jkhanjob@gmail.com> (cherry picked from commit 0335282) Co-authored-by: Jackie Han <jkhanjob@gmail.com>
1 parent 55ed6f5 commit fb1536e

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

public/pages/DefineDetector/components/Datasource/DataSource.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
import { EuiComboBox, EuiCallOut, EuiSpacer } from '@elastic/eui';
13-
import { Field, FieldProps, FormikProps } from 'formik';
13+
import { Field, FieldProps, FormikProps, useFormikContext } from 'formik';
1414
import { debounce, get } from 'lodash';
1515
import React, { useEffect, useState } from 'react';
1616
import { useDispatch, useSelector } from 'react-redux';
@@ -58,7 +58,13 @@ export function DataSource(props: DataSourceProps) {
5858
);
5959
const [queryText, setQueryText] = useState('');
6060
const opensearchState = useSelector((state: AppState) => state.opensearch);
61+
const { setFieldValue } = useFormikContext();
62+
6163
useEffect(() => {
64+
setFieldValue('index', []);
65+
setFieldValue('timeField', undefined);
66+
setFieldValue('filters', []);
67+
6268
const getInitialIndices = async () => {
6369
await dispatch(getIndices(queryText, dataSourceId));
6470
};
@@ -102,7 +108,7 @@ export function DataSource(props: DataSourceProps) {
102108
const visibleAliases = get(opensearchState, 'aliases', []) as IndexAlias[];
103109

104110
return (
105-
<ContentPanel title="Data Source" titleSize="s">
111+
<ContentPanel title="Select Data" titleSize="s">
106112
{props.isEdit && isDifferentIndex() ? (
107113
<div>
108114
<EuiCallOut

public/pages/DefineDetector/containers/DefineDetector.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,16 @@ export const DefineDetector = (props: DefineDetectorProps) => {
165165

166166
// If no detector found with ID, redirect it to list
167167
useEffect(() => {
168-
const { history, location } = props;
169-
const updatedParams = {
170-
dataSourceId: MDSCreateState.selectedDataSourceId,
171-
};
172-
history.replace({
173-
...location,
174-
search: queryString.stringify(updatedParams),
175-
});
168+
if (dataSourceEnabled) {
169+
const { history, location } = props;
170+
const updatedParams = {
171+
dataSourceId: MDSCreateState.selectedDataSourceId,
172+
};
173+
history.replace({
174+
...location,
175+
search: queryString.stringify(updatedParams),
176+
});
177+
}
176178
if (props.isEdit && hasError) {
177179
core.notifications.toasts.addDanger(
178180
'Unable to find the detector for editing'

public/pages/DefineDetector/containers/__tests__/__snapshots__/DefineDetector.test.tsx.snap

+7-7
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ exports[`<DefineDetector /> Full creating detector definition renders the compon
198198
class="euiTitle euiTitle--small"
199199
data-test-subj="contentPanelTitle"
200200
>
201-
Data Source
201+
Select Data
202202
</h3>
203203
<div
204204
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
@@ -528,11 +528,11 @@ exports[`<DefineDetector /> Full creating detector definition renders the compon
528528
data-test-subj="comboBoxInput"
529529
tabindex="-1"
530530
>
531-
<span
532-
class="euiComboBoxPill euiComboBoxPill--plainText"
531+
<p
532+
class="euiComboBoxPlaceholder"
533533
>
534-
timestamp
535-
</span>
534+
Find timestamp
535+
</p>
536536
<div
537537
class="euiComboBox__input"
538538
style="font-size: 14px; display: inline-block;"
@@ -1175,7 +1175,7 @@ exports[`<DefineDetector /> empty creating detector definition renders the compo
11751175
class="euiTitle euiTitle--small"
11761176
data-test-subj="contentPanelTitle"
11771177
>
1178-
Data Source
1178+
Select Data
11791179
</h3>
11801180
<div
11811181
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
@@ -2152,7 +2152,7 @@ exports[`<DefineDetector /> empty editing detector definition renders the compon
21522152
class="euiTitle euiTitle--small"
21532153
data-test-subj="contentPanelTitle"
21542154
>
2155-
Data Source
2155+
Select Data
21562156
</h3>
21572157
<div
21582158
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"

0 commit comments

Comments
 (0)