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

[ML] Fixes query bar not switching from KQL to Lucene and vice versa in Anomaly explorer #163625

Merged
merged 4 commits into from Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { FC, useState, useEffect } from 'react';
import React, { FC, useEffect, useState } from 'react';
import { EuiCode, EuiInputPopover } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@kbn/es-query';
Expand Down Expand Up @@ -78,23 +78,16 @@ export function getKqlQueryValues({
}

function getInitSearchInputState({
filterActive,
queryString,
searchInput,
}: {
filterActive: boolean;
queryString?: string;
searchInput?: Query;
}) {
if (queryString !== undefined && filterActive === true) {
return {
language: SEARCH_QUERY_LANGUAGE.KUERY,
query: queryString,
};
} else {
return {
query: '',
language: DEFAULT_QUERY_LANG,
};
}
return {
language: searchInput?.language ?? DEFAULT_QUERY_LANG,
query: queryString ?? '',
};
}

interface ExplorerQueryBarProps {
Expand Down Expand Up @@ -129,18 +122,17 @@ export const ExplorerQueryBar: FC<ExplorerQueryBarProps> = ({
} = services;

// The internal state of the input query bar updated on every key stroke.
const [searchInput, setSearchInput] = useState<Query>(
getInitSearchInputState({ filterActive, queryString })
);
const [searchInput, setSearchInput] = useState<Query>(getInitSearchInputState({ queryString }));
const [queryErrorMessage, setQueryErrorMessage] = useState<QueryErrorMessage | undefined>(
undefined
);

useEffect(
function updateSearchInputFromFilter() {
setSearchInput(getInitSearchInputState({ filterActive, queryString }));
setSearchInput(getInitSearchInputState({ queryString, searchInput }));
},
[filterActive, queryString]
// eslint-disable-next-line react-hooks/exhaustive-deps
[queryString, searchInput.language]
);

const searchChangeHandler = (query: Query) => {
Expand Down