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

Adding error message in Search Comparison Tool #267

Merged
merged 9 commits into from
Oct 4, 2023
Merged
28 changes: 23 additions & 5 deletions public/components/query_compare/search_result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
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,
} from '../../../types/index';
import { ResultComponents } from './result_components/result_components';
import { useSearchRelevanceContext, initialQueryErrorState } from '../../../contexts';

Expand All @@ -26,15 +31,15 @@ export const SearchResult = ({ http }: SearchResultProps) => {
const [queryString2, setQueryString2] = useState(DEFAULT_QUERY);
const [queryResult1, setQueryResult1] = useState<SearchResults>({} as any);
const [queryResult2, setQueryResult2] = useState<SearchResults>({} as any);
const [queryError1, setQueryError1] = useState<QueryError>(initialQueryErrorState);
const [queryError2, setQueryError2] = useState<QueryError>(initialQueryErrorState);
const [searchBarValue, setSearchBarValue] = useState('');

const {
updateComparedResult1,
updateComparedResult2,
selectedIndex1,
selectedIndex2,
setQueryError1,
setQueryError2,
} = useSearchRelevanceContext();

const onClickSearch = () => {
Expand Down Expand Up @@ -81,6 +86,7 @@ export const SearchResult = ({ http }: SearchResultProps) => {
setQueryResult1({} as any);
updateComparedResult1({} as any);
} else if (!queryErrors[0].queryString.length && !queryErrors[0].selectIndex.length) {
setQueryError1(initialQueryErrorState);
requestBody = {
query1: { index: selectedIndex1, ...jsonQueries[0] },
};
Expand All @@ -92,6 +98,7 @@ export const SearchResult = ({ http }: SearchResultProps) => {
setQueryResult2({} as any);
updateComparedResult2({} as any);
} else if (!queryErrors[1].queryString.length && !queryErrors[1].selectIndex.length) {
setQueryError2(initialQueryErrorState);
requestBody = {
...requestBody,
query2: { index: selectedIndex2, ...jsonQueries[1] },
Expand All @@ -118,13 +125,15 @@ export const SearchResult = ({ http }: SearchResultProps) => {
setQueryError1({
...queryErrors[0],
queryString: res.errorMessage1,
errorResponse: res.errorMessage1,
});
}

if (res.errorMessage2) {
setQueryError2({
...queryErrors[1],
queryString: res.errorMessage2,
errorResponse: res.errorMessage2,
});
}
})
Expand All @@ -149,8 +158,17 @@ export const SearchResult = ({ http }: SearchResultProps) => {
queryString2={queryString2}
setQueryString1={setQueryString1}
setQueryString2={setQueryString2}
queryError1={queryError1}
queryError2={queryError2}
setQueryError1={setQueryError1}
setQueryError2={setQueryError2}
/>
<ResultComponents
queryResult1={queryResult1}
queryResult2={queryResult2}
queryError1={queryError1}
queryError2={queryError2}
/>
<ResultComponents queryResult1={queryResult1} queryResult2={queryResult2} />
</EuiPageContentBody>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@
exports[`Result component Renders result component 1`] = `
<SearchRelevanceContextProvider>
<ResultComponents
queryError1={
Object {
"errorResponse": Object {
"body": "",
"statusCode": 200,
},
"queryString": "",
"selectIndex": "",
}
}
queryError2={
Object {
"errorResponse": Object {
"body": "",
"statusCode": 200,
},
"queryString": "",
"selectIndex": "",
}
}
queryResult1={
Object {
"_shards": Object {
Expand Down Expand Up @@ -385,6 +405,26 @@ exports[`Result component Renders result component 1`] = `
}
>
<ResultPanels
queryError1={
Object {
"errorResponse": Object {
"body": "",
"statusCode": 200,
},
"queryString": "",
"selectIndex": "",
}
}
queryError2={
Object {
"errorResponse": Object {
"body": "",
"statusCode": 200,
},
"queryString": "",
"selectIndex": "",
}
}
queryResult1={
Object {
"_shards": Object {
Expand Down Expand Up @@ -782,6 +822,16 @@ exports[`Result component Renders result component 1`] = `
className="euiPanel euiPanel--borderRadiusMedium euiPanel--plain euiPanel--noShadow euiPanel--noBorder euiPanel--flexGrowZero euiSplitPanel euiSplitPanel--row"
>
<ResultPanel
queryError={
Object {
"errorResponse": Object {
"body": "",
"statusCode": 200,
},
"queryString": "",
"selectIndex": "",
}
}
queryResult={
Object {
"_shards": Object {
Expand Down Expand Up @@ -3749,6 +3799,16 @@ exports[`Result component Renders result component 1`] = `
</_EuiSplitPanelInner>
</ResultPanel>
<ResultPanel
queryError={
Object {
"errorResponse": Object {
"body": "",
"statusCode": 200,
},
"queryString": "",
"selectIndex": "",
}
}
queryResult={
Object {
"_shards": Object {
Expand Down
Loading