Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b95e310

Browse files
committedApr 29, 2024·
clean selected field values when switching data source on create page
Signed-off-by: Jackie Han <jkhanjob@gmail.com>
1 parent 48acb93 commit b95e310

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
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'

0 commit comments

Comments
 (0)
Please sign in to comment.