Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean selected field values when switching data source on create page #742

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
};
Expand Down Expand Up @@ -102,7 +108,7 @@ export function DataSource(props: DataSourceProps) {
const visibleAliases = get(opensearchState, 'aliases', []) as IndexAlias[];

return (
<ContentPanel title="Data Source" titleSize="s">
<ContentPanel title="Select Data" titleSize="s">
{props.isEdit && isDifferentIndex() ? (
<div>
<EuiCallOut
Expand Down
18 changes: 10 additions & 8 deletions public/pages/DefineDetector/containers/DefineDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,16 @@ export const DefineDetector = (props: DefineDetectorProps) => {

// 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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ exports[`<DefineDetector /> Full creating detector definition renders the compon
class="euiTitle euiTitle--small"
data-test-subj="contentPanelTitle"
>
Data Source
Select Data
</h3>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
Expand Down Expand Up @@ -528,11 +528,11 @@ exports[`<DefineDetector /> Full creating detector definition renders the compon
data-test-subj="comboBoxInput"
tabindex="-1"
>
<span
class="euiComboBoxPill euiComboBoxPill--plainText"
<p
class="euiComboBoxPlaceholder"
>
timestamp
</span>
Find timestamp
</p>
<div
class="euiComboBox__input"
style="font-size: 14px; display: inline-block;"
Expand Down Expand Up @@ -1175,7 +1175,7 @@ exports[`<DefineDetector /> empty creating detector definition renders the compo
class="euiTitle euiTitle--small"
data-test-subj="contentPanelTitle"
>
Data Source
Select Data
</h3>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
Expand Down Expand Up @@ -2152,7 +2152,7 @@ exports[`<DefineDetector /> empty editing detector definition renders the compon
class="euiTitle euiTitle--small"
data-test-subj="contentPanelTitle"
>
Data Source
Select Data
</h3>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
Expand Down
Loading