Skip to content

Commit

Permalink
Changing select index error message to be more informative (#173) (#270)
Browse files Browse the repository at this point in the history
* Changing select index error message to be more informative (#173)

Signed-off-by: Evan Kielley <[email protected]>

* Changing select index error message to be a constant to keep code DRY (#173)

Signed-off-by: Evan Kielley <[email protected]>

* Reverting change to yarn.lock

Signed-off-by: Evan Kielley <[email protected]>

---------

Signed-off-by: Evan Kielley <[email protected]>
(cherry picked from commit dff6559)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Sep 5, 2023
1 parent ffdeb98 commit 6978f57
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions public/components/query_compare/search_result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +54,7 @@ export const SearchConfig: FunctionComponent<SearchConfigProps> = ({
if (!selectedIndex.length) {
setQueryError({
...queryError,
selectIndex: 'An index is required. Select an index.',
selectIndex: SelectIndexError.unselected,
});
}
};
Expand Down
6 changes: 5 additions & 1 deletion public/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 6978f57

Please sign in to comment.