Skip to content

Commit

Permalink
renaming for more distinct error var names
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Apr 20, 2023
1 parent cea3bd7 commit cf1b19a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
// The internal state of the input query bar updated on every key stroke.
const [searchInput, setSearchInput] = useState<Query>(query);
const [idToSelectedMap, setIdToSelectedMap] = useState<{ [id: string]: boolean }>({});
const [errorMessage, setErrorMessage] = useState<QueryErrorMessage | undefined>(undefined);
const [queryErrorMessage, setQueryErrorMessage] = useState<QueryErrorMessage | undefined>(
undefined
);

const { services } = useMlKibana();
const {
Expand Down Expand Up @@ -116,7 +118,7 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
convertedQuery = luceneStringToDsl(query.query as string);
break;
default:
setErrorMessage({
setQueryErrorMessage({
query: query.query as string,
message: i18n.translate('xpack.ml.queryBar.queryLanguageNotSupported', {
defaultMessage: 'Query language is not supported',
Expand All @@ -130,7 +132,7 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
language: query.language,
});
} catch (e) {
setErrorMessage({ query: query.query as string, message: e.message });
setQueryErrorMessage({ query: query.query as string, message: e.message });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [query.query]);
Expand Down Expand Up @@ -184,7 +186,7 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
return (
<EuiInputPopover
style={{ maxWidth: '100%' }}
closePopover={() => setErrorMessage(undefined)}
closePopover={() => setQueryErrorMessage(undefined)}
input={
<EuiFlexGroup alignItems="center">
<EuiFlexItem>
Expand Down Expand Up @@ -246,14 +248,14 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
)}
</EuiFlexGroup>
}
isOpen={errorMessage?.query === searchInput.query && errorMessage?.message !== ''}
isOpen={queryErrorMessage?.query === searchInput.query && queryErrorMessage?.message !== ''}
>
<EuiCode>
{i18n.translate('xpack.ml.stepDefineForm.invalidQuery', {
defaultMessage: 'Invalid Query',
})}
{': '}
{errorMessage?.message.split('\n')[0]}
{queryErrorMessage?.message.split('\n')[0]}
</EuiCode>
</EuiInputPopover>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@k
import type { Query } from '@kbn/es-query';
import { QueryStringInput } from '@kbn/unified-search-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/common';
import type { ErrorMessage } from '@kbn/ml-error-utils';
import type { QueryErrorMessage } from '@kbn/ml-error-utils';
import { SEARCH_QUERY_LANGUAGE } from '../../../../../common/constants/search';
import { InfluencersFilterQuery } from '../../../../../common/types/es_client';
import { useAnomalyExplorerContext } from '../../anomaly_explorer_context';
Expand Down Expand Up @@ -130,7 +130,9 @@ export const ExplorerQueryBar: FC<ExplorerQueryBarProps> = ({
const [searchInput, setSearchInput] = useState<Query>(
getInitSearchInputState({ filterActive, queryString })
);
const [errorMessage, setErrorMessage] = useState<ErrorMessage | undefined>(undefined);
const [queryErrorMessage, setQueryErrorMessage] = useState<QueryErrorMessage | undefined>(
undefined
);

useEffect(
function updateSearchInputFromFilter() {
Expand Down Expand Up @@ -161,14 +163,14 @@ export const ExplorerQueryBar: FC<ExplorerQueryBarProps> = ({
}
} catch (e) {
console.log('Invalid query syntax in search bar', e); // eslint-disable-line no-console
setErrorMessage({ query: query.query as string, message: e.message });
setQueryErrorMessage({ query: query.query as string, message: e.message });
}
};

return (
<EuiInputPopover
css={{ 'max-width': '100%' }}
closePopover={setErrorMessage.bind(null, undefined)}
closePopover={setQueryErrorMessage.bind(null, undefined)}
input={
<QueryStringInput
bubbleSubmitEvent={false}
Expand All @@ -193,14 +195,14 @@ export const ExplorerQueryBar: FC<ExplorerQueryBarProps> = ({
}}
/>
}
isOpen={errorMessage?.query === searchInput.query && errorMessage?.message !== ''}
isOpen={queryErrorMessage?.query === searchInput.query && queryErrorMessage?.message !== ''}
>
<EuiCode>
{i18n.translate('xpack.ml.explorer.invalidKuerySyntaxErrorMessageQueryBar', {
defaultMessage: 'Invalid query',
})}
{': '}
{errorMessage?.message.split('\n')[0]}
{queryErrorMessage?.message.split('\n')[0]}
</EuiCode>
</EuiInputPopover>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ interface SourceSearchBarProps {
}
export const SourceSearchBar: FC<SourceSearchBarProps> = ({ dataView, searchBar }) => {
const {
actions: { searchChangeHandler, searchSubmitHandler, setErrorMessage },
state: { errorMessage, searchInput },
actions: { searchChangeHandler, searchSubmitHandler, setQueryErrorMessage },
state: { queryErrorMessage, searchInput },
} = searchBar;

const {
Expand All @@ -44,7 +44,7 @@ export const SourceSearchBar: FC<SourceSearchBarProps> = ({ dataView, searchBar
return (
<EuiInputPopover
style={{ maxWidth: '100%' }}
closePopover={() => setErrorMessage(undefined)}
closePopover={() => setQueryErrorMessage(undefined)}
input={
<QueryStringInput
bubbleSubmitEvent={true}
Expand Down Expand Up @@ -80,13 +80,13 @@ export const SourceSearchBar: FC<SourceSearchBarProps> = ({ dataView, searchBar
}}
/>
}
isOpen={errorMessage?.query === searchInput.query && errorMessage?.message !== ''}
isOpen={queryErrorMessage?.query === searchInput.query && queryErrorMessage?.message !== ''}
>
<EuiCode>
{i18n.translate('xpack.transform.stepDefineForm.invalidKuerySyntaxErrorMessageQueryBar', {
defaultMessage: 'Invalid query: {errorMessage}',
defaultMessage: 'Invalid query: {queryErrorMessage}',
values: {
errorMessage: errorMessage?.message.split('\n')[0],
queryErrorMessage: queryErrorMessage?.message.split('\n')[0],
},
})}
</EuiCode>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const useSearchBar = (

const [searchQuery, setSearchQuery] = useState(defaults.searchQuery);

const [errorMessage, setErrorMessage] = useState<QueryErrorMessage | undefined>(undefined);
const [queryErrorMessage, setQueryErrorMessage] = useState<QueryErrorMessage | undefined>(
undefined
);

const searchChangeHandler = (query: Query) => setSearchInput(query);
const searchSubmitHandler = (query: Query) => {
Expand All @@ -61,7 +63,7 @@ export const useSearchBar = (
return;
}
} catch (e) {
setErrorMessage({ query: query.query as string, message: e.message });
setQueryErrorMessage({ query: query.query as string, message: e.message });
}
};

Expand All @@ -71,14 +73,14 @@ export const useSearchBar = (
actions: {
searchChangeHandler,
searchSubmitHandler,
setErrorMessage,
setQueryErrorMessage,
setSearchInput,
setSearchLanguage,
setSearchQuery,
setSearchString,
},
state: {
errorMessage,
queryErrorMessage,
transformConfigQuery,
searchInput,
searchLanguage,
Expand Down

0 comments on commit cf1b19a

Please sign in to comment.