From 89bed8bb54676336b9400e1353c7ff27d2c76bd5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 15:59:15 -0700 Subject: [PATCH] Changing select index error message to be more informative (#173) (#270) (#275) * Changing select index error message to be more informative (#173) * Changing select index error message to be a constant to keep code DRY (#173) * Reverting change to yarn.lock --------- (cherry picked from commit dff6559823eede7d87d5610aa2d8b3e336c1c6f2) Signed-off-by: Evan Kielley Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- public/components/query_compare/search_result/index.tsx | 4 ++-- .../search_components/search_configs/search_config.tsx | 4 ++-- public/types/index.ts | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/public/components/query_compare/search_result/index.tsx b/public/components/query_compare/search_result/index.tsx index e9a65d3..d5573b8 100644 --- a/public/components/query_compare/search_result/index.tsx +++ b/public/components/query_compare/search_result/index.tsx @@ -11,7 +11,7 @@ import { SearchConfigsPanel } from './search_components/search_configs/search_co import { SearchInputBar } from './search_components/search_bar'; import { ServiceEndpoints } from '../../../../common'; import { Header } from '../../common/header'; -import { SearchResults, QueryError, QueryStringError } from '../../../types/index'; +import { SearchResults, QueryError, QueryStringError, SelectIndexError } from '../../../types/index'; import { ResultComponents } from './result_components/result_components'; import { useSearchRelevanceContext, initialQueryErrorState } from '../../../contexts'; @@ -53,7 +53,7 @@ export const SearchResult = ({ http }: SearchResultProps) => { const validateQuery = (selectedIndex: string, queryString: string, queryError: QueryError) => { // Check if select an index if (!selectedIndex.length) { - queryError.selectIndex = 'An index is required. Select an index.'; + queryError.selectIndex = SelectIndexError.unselected; } // Check if query string is empty diff --git a/public/components/query_compare/search_result/search_components/search_configs/search_config.tsx b/public/components/query_compare/search_result/search_components/search_configs/search_config.tsx index 8f98e55..5fc8cd1 100644 --- a/public/components/query_compare/search_result/search_components/search_configs/search_config.tsx +++ b/public/components/query_compare/search_result/search_components/search_configs/search_config.tsx @@ -15,7 +15,7 @@ import { } from '@elastic/eui'; import { useSearchRelevanceContext } from '../../../../../contexts'; -import { QueryError, QueryStringError } from '../../../../../types/index'; +import { QueryError, QueryStringError, SelectIndexError } from '../../../../../types/index'; interface SearchConfigProps { queryNumber: 1 | 2; @@ -54,7 +54,7 @@ export const SearchConfig: FunctionComponent = ({ if (!selectedIndex.length) { setQueryError({ ...queryError, - selectIndex: 'An index is required. Select an index.', + selectIndex: SelectIndexError.unselected, }); } }; diff --git a/public/types/index.ts b/public/types/index.ts index 865ec41..e1dbffe 100644 --- a/public/types/index.ts +++ b/public/types/index.ts @@ -45,12 +45,16 @@ export interface SearchResults { }; } +export enum SelectIndexError { + unselected = 'An index is required to compare search results. Select an index.' +} + export enum QueryStringError { empty = 'A query is required. Enter a query.', invalid = 'Query syntax is invalid. Enter a valid query.', } export interface QueryError { - selectIndex: 'An index is required. Select an index.' | ''; + selectIndex: SelectIndexError | string; queryString: QueryStringError | string; }