From 649b32107484b7659b1ac08b1bafd2fa1394b195 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
Date: Wed, 4 Oct 2023 19:29:22 +0000
Subject: [PATCH] Adding error message in Search Comparison Tool (#267)
* adding error message in search comparison tool
Signed-off-by: Sean Li
* updating test snapshots
Signed-off-by: Sean Li
* adding tests for query error
Signed-off-by: Sean Li
* updating tests
Signed-off-by: Sean Li
* refactoring QueryError, adding error message to result panel
Signed-off-by: Sean Li
* moving helper text to helpText prop
Signed-off-by: Sean Li
* adding tests and addressing comments
Signed-off-by: Sean Li
* adding more tests, fixing state management, addressing comments
Signed-off-by: Sean Li
* reverting changes to validateQuery, addressing comments
Signed-off-by: Sean Li
---------
Signed-off-by: Sean Li
(cherry picked from commit 6fb31c89a298520bad0eadeac88939001d5aea32)
Signed-off-by: github-actions[bot]
---
.../query_compare/search_result/index.tsx | 114 +++--
.../result_component.test.tsx.snap | 60 +++
.../__snapshots__/result_grid.test.tsx.snap | 347 +++++++++++++
.../__test__/result_component.test.tsx | 8 +-
.../__test__/result_grid.test.tsx | 23 +
.../result_components/result_components.tsx | 29 +-
.../result_components/result_panel.tsx | 20 +-
.../__snapshots__/search_config.test.tsx.snap | 462 ++++++++++++++++++
.../search_configs.test.tsx.snap | 134 +++--
.../__tests__/search_config.test.tsx | 47 ++
.../__tests__/search_configs.test.tsx | 5 +
.../search_configs/search_config.tsx | 42 +-
.../search_configs/search_configs.tsx | 13 +-
public/contexts/index.tsx | 17 +-
public/types/index.ts | 17 +-
test/constants.ts | 11 +
16 files changed, 1225 insertions(+), 124 deletions(-)
create mode 100644 public/components/query_compare/search_result/search_components/__tests__/__snapshots__/search_config.test.tsx.snap
create mode 100644 public/components/query_compare/search_result/search_components/__tests__/search_config.test.tsx
diff --git a/public/components/query_compare/search_result/index.tsx b/public/components/query_compare/search_result/index.tsx
index d5573b8..4d27fb1 100644
--- a/public/components/query_compare/search_result/index.tsx
+++ b/public/components/query_compare/search_result/index.tsx
@@ -6,14 +6,20 @@
import React, { useState } from 'react';
import { EuiPageContentBody } from '@elastic/eui';
-import { CoreStart, ChromeBreadcrumb } from '../../../../../../src/core/public';
+import { CoreStart } from '../../../../../../src/core/public';
import { SearchConfigsPanel } from './search_components/search_configs/search_configs';
import { SearchInputBar } from './search_components/search_bar';
import { ServiceEndpoints } from '../../../../common';
import { Header } from '../../common/header';
-import { SearchResults, QueryError, QueryStringError, SelectIndexError } from '../../../types/index';
+import {
+ SearchResults,
+ QueryError,
+ QueryStringError,
+ SelectIndexError,
+ initialQueryErrorState,
+} from '../../../types/index';
import { ResultComponents } from './result_components/result_components';
-import { useSearchRelevanceContext, initialQueryErrorState } from '../../../contexts';
+import { useSearchRelevanceContext } from '../../../contexts';
const DEFAULT_QUERY = '{}';
@@ -26,6 +32,8 @@ export const SearchResult = ({ http }: SearchResultProps) => {
const [queryString2, setQueryString2] = useState(DEFAULT_QUERY);
const [queryResult1, setQueryResult1] = useState({} as any);
const [queryResult2, setQueryResult2] = useState({} as any);
+ const [queryError1, setQueryError1] = useState(initialQueryErrorState);
+ const [queryError2, setQueryError2] = useState(initialQueryErrorState);
const [searchBarValue, setSearchBarValue] = useState('');
const {
@@ -33,12 +41,13 @@ export const SearchResult = ({ http }: SearchResultProps) => {
updateComparedResult2,
selectedIndex1,
selectedIndex2,
- setQueryError1,
- setQueryError2,
} = useSearchRelevanceContext();
const onClickSearch = () => {
- const queryErrors = [{ ...initialQueryErrorState }, { ...initialQueryErrorState }];
+ const queryErrors = [
+ { ...initialQueryErrorState, errorResponse: { ...initialQueryErrorState.errorResponse } },
+ { ...initialQueryErrorState, errorResponse: { ...initialQueryErrorState.errorResponse } },
+ ];
const jsonQueries = [{}, {}];
validateQuery(selectedIndex1, queryString1, queryErrors[0]);
@@ -47,7 +56,7 @@ export const SearchResult = ({ http }: SearchResultProps) => {
validateQuery(selectedIndex2, queryString2, queryErrors[1]);
jsonQueries[1] = rewriteQuery(searchBarValue, queryString2, queryErrors[1]);
- handleQuery(jsonQueries, queryErrors);
+ handleSearch(jsonQueries, queryErrors);
};
const validateQuery = (selectedIndex: string, queryString: string, queryError: QueryError) => {
@@ -59,45 +68,58 @@ export const SearchResult = ({ http }: SearchResultProps) => {
// Check if query string is empty
if (!queryString.length) {
queryError.queryString = QueryStringError.empty;
+ queryError.errorResponse.statusCode = 400;
}
};
- const rewriteQuery = (searchBarValue: string, queryString: string, queryError: QueryError) => {
+ const rewriteQuery = (value: string, queryString: string, queryError: QueryError) => {
if (queryString.trim().length > 0) {
try {
- return JSON.parse(queryString.replace(/%SearchText%/g, searchBarValue));
+ return JSON.parse(queryString.replace(/%SearchText%/g, value));
} catch {
queryError.queryString = QueryStringError.invalid;
+ queryError.errorResponse.statusCode = 400;
}
}
};
- const handleQuery = (jsonQueries: any, queryErrors: QueryError[]) => {
- let requestBody = {};
-
- // Handle query1
- if (queryErrors[0].queryString.length || queryErrors[0].selectIndex.length) {
- setQueryError1(queryErrors[0]);
- setQueryResult1({} as any);
- updateComparedResult1({} as any);
- } else if (!queryErrors[0].queryString.length && !queryErrors[0].selectIndex.length) {
- requestBody = {
- query1: { index: selectedIndex1, ...jsonQueries[0] },
- };
- }
-
- // Handle query2
- if (queryErrors[1].queryString.length || queryErrors[1].selectIndex.length) {
- setQueryError2(queryErrors[1]);
- setQueryResult2({} as any);
- updateComparedResult2({} as any);
- } else if (!queryErrors[1].queryString.length && !queryErrors[1].selectIndex.length) {
- requestBody = {
- ...requestBody,
- query2: { index: selectedIndex2, ...jsonQueries[1] },
- };
+ const handleQuery = (
+ queryError: QueryError,
+ selectedIndex: string,
+ jsonQuery: any,
+ updateComparedResult: (result: SearchResults) => void,
+ setQueryResult: React.Dispatch>,
+ setQueryError: React.Dispatch>
+ ) => {
+ if (queryError.queryString.length || queryError.selectIndex.length) {
+ setQueryError(queryError);
+ setQueryResult({} as any);
+ updateComparedResult({} as any);
+ } else if (!queryError.queryString.length && !queryError.selectIndex) {
+ setQueryError(initialQueryErrorState);
+ return { index: selectedIndex, ...jsonQuery };
}
+ };
+ const handleSearch = (jsonQueries: any, queryErrors: QueryError[]) => {
+ const requestBody = {
+ query1: handleQuery(
+ queryErrors[0],
+ selectedIndex1,
+ jsonQueries[0],
+ updateComparedResult1,
+ setQueryResult1,
+ setQueryError1
+ ),
+ query2: handleQuery(
+ queryErrors[1],
+ selectedIndex2,
+ jsonQueries[1],
+ updateComparedResult2,
+ setQueryResult2,
+ setQueryError2
+ ),
+ };
if (Object.keys(requestBody).length !== 0) {
http
.post(ServiceEndpoints.GetSearchResults, {
@@ -115,20 +137,23 @@ export const SearchResult = ({ http }: SearchResultProps) => {
}
if (res.errorMessage1) {
- setQueryError1({
- ...queryErrors[0],
+ setQueryError1((error: QueryError) => ({
+ ...error,
queryString: res.errorMessage1,
- });
+ errorResponse: res.errorMessage1,
+ }));
}
if (res.errorMessage2) {
- setQueryError2({
- ...queryErrors[1],
+ setQueryError2((error: QueryError) => ({
+ ...error,
queryString: res.errorMessage2,
- });
+ errorResponse: res.errorMessage2,
+ }));
}
})
.catch((error: Error) => {
+ // eslint-disable-next-line no-console
console.error(error);
});
}
@@ -149,8 +174,17 @@ export const SearchResult = ({ http }: SearchResultProps) => {
queryString2={queryString2}
setQueryString1={setQueryString1}
setQueryString2={setQueryString2}
+ queryError1={queryError1}
+ queryError2={queryError2}
+ setQueryError1={setQueryError1}
+ setQueryError2={setQueryError2}
+ />
+
-
>
);
diff --git a/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap b/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap
index a18eaa5..13b3f52 100644
--- a/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap
+++ b/public/components/query_compare/search_result/result_components/__test__/__snapshots__/result_component.test.tsx.snap
@@ -3,6 +3,26 @@
exports[`Result component Renders result component 1`] = `
`;
+
+exports[`Result panel query error Displays error message on query error 1`] = `
+
+
+ <_EuiSplitPanelInner
+ className="search-relevance-result-panel"
+ >
+
+
+
+
+
+
+
+
+ Result 1
+
+
+
+
+
+
+
+
+ 10
+ results
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Query
+ Error
+
+
+
+
+
+
+
+
+ Error: parsing_exception - Unknown key for a VALUE_STRING in [this].
+
+
+
+
+
+
+
+
+ Status Code:
+ 400
+
+
+
+
+
+
+
+
+
+
+`;
diff --git a/public/components/query_compare/search_result/result_components/__test__/result_component.test.tsx b/public/components/query_compare/search_result/result_components/__test__/result_component.test.tsx
index 85ac1aa..148c91a 100644
--- a/public/components/query_compare/search_result/result_components/__test__/result_component.test.tsx
+++ b/public/components/query_compare/search_result/result_components/__test__/result_component.test.tsx
@@ -10,13 +10,19 @@ import { waitFor } from '@testing-library/react';
import { ResultComponents } from '../result_components';
import { TEST_QUERY_RESPONSE } from '../../../../../../test/constants';
import { SearchRelevanceContextProvider } from '../../../../../contexts';
+import { initialQueryErrorState } from '../../../../../../public/types/index';
describe('Result component', () => {
configure({ adapter: new Adapter() });
it('Renders result component', async () => {
const wrapper = mount(
-
+
);
diff --git a/public/components/query_compare/search_result/result_components/__test__/result_grid.test.tsx b/public/components/query_compare/search_result/result_components/__test__/result_grid.test.tsx
index 4a8b689..86008af 100644
--- a/public/components/query_compare/search_result/result_components/__test__/result_grid.test.tsx
+++ b/public/components/query_compare/search_result/result_components/__test__/result_grid.test.tsx
@@ -11,8 +11,10 @@ import { ResultGridComponent } from '../result_grid';
import {
TEST_QUERY_RESPONSE,
TEST_COMPARED_DOCUMENTS_RANK,
+ TEST_QUERY_ERROR,
} from '../../../../../../test/constants';
import { SearchRelevanceContextProvider } from '../../../../../contexts';
+import { ResultPanel } from '../result_panel';
describe('Result grid component', () => {
configure({ adapter: new Adapter() });
@@ -34,3 +36,24 @@ describe('Result grid component', () => {
});
});
});
+
+describe('Result panel query error', () => {
+ configure({ adapter: new Adapter() });
+ it('Displays error message on query error', async () => {
+ const wrapper = mount(
+
+
+
+ );
+
+ wrapper.update();
+
+ await waitFor(() => {
+ expect(wrapper).toMatchSnapshot();
+ });
+ });
+});
diff --git a/public/components/query_compare/search_result/result_components/result_components.tsx b/public/components/query_compare/search_result/result_components/result_components.tsx
index 02e1560..0cba158 100644
--- a/public/components/query_compare/search_result/result_components/result_components.tsx
+++ b/public/components/query_compare/search_result/result_components/result_components.tsx
@@ -6,7 +6,7 @@
import React, { useEffect, useState } from 'react';
import { EuiSplitPanel, EuiTitle, EuiFlexGroup, EuiPanel } from '@elastic/eui';
-import { SearchResults } from '../../../../types/index';
+import { QueryError, SearchResults } from '../../../../types/index';
import { ResultPanel } from './result_panel';
import './result_components.scss';
@@ -14,6 +14,8 @@ import './result_components.scss';
interface ResultComponentsProps {
queryResult1: SearchResults;
queryResult2: SearchResults;
+ queryError1: QueryError;
+ queryError2: QueryError;
}
const InitialState = () => {
@@ -33,16 +35,26 @@ const InitialState = () => {
);
};
-const ResultPanels = ({ queryResult1, queryResult2 }: ResultComponentsProps) => {
+const ResultPanels = ({
+ queryResult1,
+ queryResult2,
+ queryError1,
+ queryError2,
+}: ResultComponentsProps) => {
return (
-
-
+
+
);
};
-export const ResultComponents = ({ queryResult1, queryResult2 }: ResultComponentsProps) => {
+export const ResultComponents = ({
+ queryResult1,
+ queryResult2,
+ queryError1,
+ queryError2,
+}: ResultComponentsProps) => {
const [initialState, setInitialState] = useState(true);
// Set initial state
@@ -59,7 +71,12 @@ export const ResultComponents = ({ queryResult1, queryResult2 }: ResultComponent
{initialState === true ? (
) : (
-
+
)}
>
);
diff --git a/public/components/query_compare/search_result/result_components/result_panel.tsx b/public/components/query_compare/search_result/result_components/result_panel.tsx
index 49260da..2731274 100644
--- a/public/components/query_compare/search_result/result_components/result_panel.tsx
+++ b/public/components/query_compare/search_result/result_components/result_panel.tsx
@@ -14,7 +14,7 @@ import {
} from '@elastic/eui';
import { ResultGridComponent } from './result_grid';
-import { SearchResults } from '../../../../types/index';
+import { QueryError, SearchResults } from '../../../../types/index';
import { useSearchRelevanceContext } from '../../../../contexts';
import './result_components.scss';
@@ -22,11 +22,23 @@ import './result_components.scss';
interface ResultPanelProps {
resultNumber: number;
queryResult: SearchResults;
+ queryError: QueryError;
}
-export const ResultPanel = ({ resultNumber, queryResult }: ResultPanelProps) => {
+export const ResultPanel = ({ resultNumber, queryResult, queryError }: ResultPanelProps) => {
const { comparedResult1, comparedResult2 } = useSearchRelevanceContext();
+ const ErrorMessage = () => (
+ <>
+
+
+ {queryError.errorResponse.statusCode >= 500 ? 'Internal' : 'Query'} Error
+
+ {queryError.errorResponse.body}
+ Status Code: {queryError.errorResponse.statusCode}
+ >
+ );
+
const getComparedDocumentsRank = () => {
return resultNumber === 1 ? comparedResult2 : comparedResult1;
};
@@ -47,7 +59,9 @@ export const ResultPanel = ({ resultNumber, queryResult }: ResultPanelProps) =>
- {queryResult?.hits?.hits?.length ? (
+ {queryError.errorResponse.statusCode !== 200 || queryError.queryString.length ? (
+
+ ) : queryResult?.hits?.hits?.length ? (
+
+
+
+ Query
+ 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enter a query in
+
+
+ OpenSearch Query DSL
+
+ . Use %SearchText% to refer to the text in the search bar
+
+ }
+ isInvalid={false}
+ label="Query"
+ labelAppend={
+
+
+ Help
+
+
+ }
+ labelType="label"
+ >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+`;
diff --git a/public/components/query_compare/search_result/search_components/__tests__/__snapshots__/search_configs.test.tsx.snap b/public/components/query_compare/search_result/search_components/__tests__/__snapshots__/search_configs.test.tsx.snap
index 3b17a2f..c52cfa8 100644
--- a/public/components/query_compare/search_result/search_components/__tests__/__snapshots__/search_configs.test.tsx.snap
+++ b/public/components/query_compare/search_result/search_components/__tests__/__snapshots__/search_configs.test.tsx.snap
@@ -3,8 +3,30 @@
exports[`Flyout component Renders flyout component 1`] = `
@@ -41,6 +63,10 @@ exports[`Flyout component Renders flyout component 1`] = `
+ Enter a query in
+
+
+ OpenSearch Query DSL
+
+ . Use %SearchText% to refer to the text in the search bar
+
+ }
isInvalid={false}
label="Query"
labelAppend={
@@ -317,6 +355,7 @@ exports[`Flyout component Renders flyout component 1`] = `
className="euiFormRow__fieldWrapper"
>
+
+
+
-
-
-
- Enter a query in OpenSearch Query DSL. Use %SearchText% to refer to the text in the search bar.
-
-
-
@@ -483,6 +527,10 @@ exports[`Flyout component Renders flyout component 1`] = `
+ Enter a query in
+
+
+ OpenSearch Query DSL
+
+ . Use %SearchText% to refer to the text in the search bar
+
+ }
isInvalid={false}
label="Query"
labelAppend={
@@ -759,6 +819,7 @@ exports[`Flyout component Renders flyout component 1`] = `
className="euiFormRow__fieldWrapper"
>
+
+
+
-
-
-
- Enter a query in OpenSearch Query DSL. Use %SearchText% to refer to the text in the search bar.
-
-
-
diff --git a/public/components/query_compare/search_result/search_components/__tests__/search_config.test.tsx b/public/components/query_compare/search_result/search_components/__tests__/search_config.test.tsx
new file mode 100644
index 0000000..5b2bd79
--- /dev/null
+++ b/public/components/query_compare/search_result/search_components/__tests__/search_config.test.tsx
@@ -0,0 +1,47 @@
+/*
+ * Copyright OpenSearch Contributors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { configure, mount } from 'enzyme';
+import Adapter from 'enzyme-adapter-react-16';
+import React from 'react';
+import { waitFor } from '@testing-library/react';
+import { SearchConfig } from '../search_configs/search_config';
+import { SearchRelevanceContextProvider } from '../../../../../contexts';
+import { TEST_QUERY_STRING } from '../../../../../../test/constants';
+import { initialQueryErrorState } from '../../../../../../public/types/index';
+
+describe('Flyout component', () => {
+ configure({ adapter: new Adapter() });
+
+ it('Renders flyout component', async () => {
+ const setQueryString = jest.fn();
+ const setSelectedIndex = jest.fn();
+ const setQueryError = jest.fn();
+ const wrapper = mount(
+
+
+
+ );
+
+ wrapper.update();
+ await waitFor(() => {
+ expect(wrapper).toMatchSnapshot();
+ wrapper.find('EuiCodeEditor').prop('onChange')?.({ target: { value: '' } });
+ wrapper.find('EuiSelect').prop('onChange')?.({ target: {} });
+ wrapper.find('EuiSelect').prop('onBlur')?.({ target: {} });
+ });
+ expect(setQueryString).toHaveBeenCalledTimes(1);
+ expect(setSelectedIndex).toHaveBeenCalledTimes(1);
+ expect(setQueryError).toHaveBeenCalledTimes(3);
+ });
+});
diff --git a/public/components/query_compare/search_result/search_components/__tests__/search_configs.test.tsx b/public/components/query_compare/search_result/search_components/__tests__/search_configs.test.tsx
index fc4867a..1efb59d 100644
--- a/public/components/query_compare/search_result/search_components/__tests__/search_configs.test.tsx
+++ b/public/components/query_compare/search_result/search_components/__tests__/search_configs.test.tsx
@@ -10,6 +10,7 @@ import { waitFor } from '@testing-library/react';
import { SearchConfigsPanel } from '../search_configs/search_configs';
import { SearchRelevanceContextProvider } from '../../../../../contexts';
import { TEST_QUERY_STRING } from '../../../../../../test/constants';
+import { initialQueryErrorState } from '../../../../../../public/types/index';
describe('Flyout component', () => {
configure({ adapter: new Adapter() });
@@ -22,6 +23,10 @@ describe('Flyout component', () => {
queryString2={TEST_QUERY_STRING}
setQueryString1={() => {}}
setQueryString2={() => {}}
+ queryError1={initialQueryErrorState}
+ queryError2={initialQueryErrorState}
+ setQueryError1={() => {}}
+ setQueryError2={() => {}}
/>
);
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 5fc8cd1..391699c 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
@@ -37,45 +37,48 @@ export const SearchConfig: FunctionComponent = ({
setQueryError,
}) => {
const { documentsIndexes, setShowFlyout } = useSearchRelevanceContext();
-
// On select index
const onChangeSelectedIndex: React.ChangeEventHandler = (e) => {
setSelectedIndex(e.target.value);
- setQueryError({
- ...queryError,
+ setQueryError((error: QueryError) => ({
+ ...error,
selectIndex: '',
- });
+ }));
};
// Select index on blur
const selectIndexOnBlur = () => {
// If Index Select on blur without selecting an index, show error
if (!selectedIndex.length) {
- setQueryError({
- ...queryError,
+ setQueryError((error: QueryError) => ({
+ ...error,
selectIndex: SelectIndexError.unselected,
- });
+ }));
}
};
// On change query string
const onChangeQueryString = (value: string) => {
setQueryString(value);
- setQueryError({
- ...queryError,
+ setQueryError((error: QueryError) => ({
+ ...error,
queryString: '',
- });
+ }));
};
// Code editor on blur
const codeEditorOnBlur = () => {
// If no query string on blur, show error
if (!queryString.length) {
- setQueryError({
- ...queryError,
+ setQueryError((error: QueryError) => ({
+ ...error,
+ errorResponse: {
+ body: '',
+ statusCode: 400,
+ },
queryString: QueryStringError.empty,
- });
+ }));
}
};
@@ -115,6 +118,13 @@ export const SearchConfig: FunctionComponent = ({
}
+ helpText={
+
+ Enter a query in{' '}
+ OpenSearch Query DSL.
+ Use %SearchText% to refer to the text in the search bar
+
+ }
>
= ({
tabSize={2}
/>
-
-
- Enter a query in OpenSearch Query DSL. Use %SearchText% to refer to the text in the search
- bar.
-
-
>
);
};
diff --git a/public/components/query_compare/search_result/search_components/search_configs/search_configs.tsx b/public/components/query_compare/search_result/search_components/search_configs/search_configs.tsx
index c3e8f37..09d2800 100644
--- a/public/components/query_compare/search_result/search_components/search_configs/search_configs.tsx
+++ b/public/components/query_compare/search_result/search_components/search_configs/search_configs.tsx
@@ -11,12 +11,17 @@ import { SearchConfig } from './search_config';
import { useSearchRelevanceContext } from '../../../../../contexts';
import './search_configs.scss';
+import { QueryError } from '../../../../../../public/types/index';
interface SearchConfigsPanelProps {
queryString1: string;
queryString2: string;
setQueryString1: React.Dispatch>;
setQueryString2: React.Dispatch>;
+ queryError1: QueryError;
+ queryError2: QueryError;
+ setQueryError1: React.Dispatch>;
+ setQueryError2: React.Dispatch>;
}
export const SearchConfigsPanel = ({
@@ -24,16 +29,16 @@ export const SearchConfigsPanel = ({
queryString2,
setQueryString1,
setQueryString2,
+ queryError1,
+ queryError2,
+ setQueryError1,
+ setQueryError2,
}: SearchConfigsPanelProps) => {
const {
selectedIndex1,
setSelectedIndex1,
selectedIndex2,
setSelectedIndex2,
- queryError1,
- queryError2,
- setQueryError1,
- setQueryError2,
} = useSearchRelevanceContext();
return (
diff --git a/public/contexts/index.tsx b/public/contexts/index.tsx
index 4d0361f..d15f1de 100644
--- a/public/contexts/index.tsx
+++ b/public/contexts/index.tsx
@@ -5,14 +5,9 @@
import React, { createContext, useContext, useState } from 'react';
-import { DocumentsIndex, SearchResults, QueryError } from '../types/index';
+import { DocumentsIndex, SearchResults } from '../types/index';
import { getDocumentRank, DocumentRank } from './utils';
-export const initialQueryErrorState: QueryError = {
- selectIndex: '',
- queryString: '',
-};
-
export interface SearchRelevanceContextProps {
documentsIndexes: DocumentsIndex[];
setDocumentsIndexes: React.Dispatch>;
@@ -26,10 +21,6 @@ export interface SearchRelevanceContextProps {
setSelectedIndex1: React.Dispatch>;
selectedIndex2: string;
setSelectedIndex2: React.Dispatch>;
- queryError1: QueryError;
- setQueryError1: React.Dispatch>;
- queryError2: QueryError;
- setQueryError2: React.Dispatch>;
}
export const SearchRelevanceContext = createContext(null);
@@ -51,8 +42,6 @@ export const SearchRelevanceContextProvider = ({ children }: { children: React.R
const [comparedResult2, setComparedResult2] = useState({});
const [selectedIndex1, setSelectedIndex1] = useState('');
const [selectedIndex2, setSelectedIndex2] = useState('');
- const [queryError1, setQueryError1] = useState(initialQueryErrorState);
- const [queryError2, setQueryError2] = useState(initialQueryErrorState);
const updateComparedResult1 = (result: SearchResults) => {
setComparedResult1(getDocumentRank(result?.hits?.hits));
@@ -77,10 +66,6 @@ export const SearchRelevanceContextProvider = ({ children }: { children: React.R
setSelectedIndex1,
selectedIndex2,
setSelectedIndex2,
- queryError1,
- setQueryError1,
- queryError2,
- setQueryError2,
}}
>
{children}
diff --git a/public/types/index.ts b/public/types/index.ts
index e1dbffe..7ea4f43 100644
--- a/public/types/index.ts
+++ b/public/types/index.ts
@@ -46,7 +46,7 @@ export interface SearchResults {
}
export enum SelectIndexError {
- unselected = 'An index is required to compare search results. Select an index.'
+ unselected = 'An index is required to compare search results. Select an index.',
}
export enum QueryStringError {
@@ -54,7 +54,22 @@ export enum QueryStringError {
invalid = 'Query syntax is invalid. Enter a valid query.',
}
+export interface ErrorResponse {
+ body: string;
+ statusCode: number;
+}
+
export interface QueryError {
selectIndex: SelectIndexError | string;
queryString: QueryStringError | string;
+ errorResponse: ErrorResponse;
}
+
+export const initialQueryErrorState: QueryError = {
+ selectIndex: '',
+ queryString: '',
+ errorResponse: {
+ body: '',
+ statusCode: 200,
+ },
+};
diff --git a/test/constants.ts b/test/constants.ts
index 80e7126..05926a0 100644
--- a/test/constants.ts
+++ b/test/constants.ts
@@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import { QueryError } from '../public/types/index';
+
export const TEST_SEARCH_TEXT = 'basic';
export const TEST_QUERY_RESPONSE = {
@@ -200,3 +202,12 @@ export const TEST_COMPARED_DOCUMENTS_RANK = {
};
export const TEST_QUERY_STRING = '{}';
+
+export const TEST_QUERY_ERROR: QueryError = {
+ selectIndex: '',
+ queryString: '',
+ errorResponse: {
+ statusCode: 400,
+ body: 'Error: parsing_exception - Unknown key for a VALUE_STRING in [this].',
+ },
+};