Skip to content

Commit 31a1cc0

Browse files
authored
[App Search] Add a Result Component (#85046)
1 parent a4caffa commit 31a1cc0

32 files changed

+923
-48
lines changed

x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { EuiPageContent, EuiBasicTable } from '@elastic/eui';
1414

1515
import { Loading } from '../../../shared/loading';
1616
import { DocumentDetail } from '.';
17-
import { ResultFieldValue } from '../result_field_value';
17+
import { ResultFieldValue } from '../result';
1818

1919
describe('DocumentDetail', () => {
2020
const values = {

x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { i18n } from '@kbn/i18n';
2323
import { Loading } from '../../../shared/loading';
2424
import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome';
2525
import { FlashMessages } from '../../../shared/flash_messages';
26-
import { ResultFieldValue } from '../result_field_value';
26+
import { ResultFieldValue } from '../result';
2727

2828
import { DocumentDetailLogic } from './document_detail_logic';
2929
import { FieldDetails } from './types';

x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail_logic.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jest.mock('../../../shared/flash_messages', () => ({
2828
import { setQueuedSuccessMessage, flashAPIErrors } from '../../../shared/flash_messages';
2929

3030
import { DocumentDetailLogic } from './document_detail_logic';
31+
import { InternalSchemaTypes } from '../../../shared/types';
3132

3233
describe('DocumentDetailLogic', () => {
3334
const DEFAULT_VALUES = {
@@ -61,7 +62,7 @@ describe('DocumentDetailLogic', () => {
6162
describe('actions', () => {
6263
describe('setFields', () => {
6364
it('should set fields to the provided value and dataLoading to false', () => {
64-
const fields = [{ name: 'foo', value: ['foo'], type: 'string' }];
65+
const fields = [{ name: 'foo', value: ['foo'], type: 'string' as InternalSchemaTypes }];
6566

6667
mount({
6768
dataLoading: true,

x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/search_experience/search_experience.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
.sui-results-container {
33
flex-grow: 1;
44
padding: 0;
5+
6+
> li + li {
7+
margin-top: $euiSize;
8+
}
59
}
610

711
.documentsSearchExperience__sidebar {

x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/search_experience/search_experience_content.test.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ describe('SearchExperienceContent', () => {
4343
it('passes engineName to the result view', () => {
4444
const props = {
4545
result: {
46+
id: {
47+
raw: '1',
48+
},
49+
_meta: {
50+
id: '1',
51+
scopedId: '1',
52+
score: 100,
53+
engine: 'my-engine',
54+
},
4655
foo: {
4756
raw: 'bar',
4857
},
@@ -51,7 +60,7 @@ describe('SearchExperienceContent', () => {
5160

5261
const wrapper = shallow(<SearchExperienceContent />);
5362
const resultView: any = wrapper.find(Results).prop('resultView');
54-
expect(resultView(props)).toEqual(<ResultView engineName="engine1" {...props} />);
63+
expect(resultView(props)).toEqual(<ResultView {...props} />);
5564
});
5665

5766
it('renders pagination', () => {

x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/search_experience/search_experience_content.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,18 @@ import { useValues } from 'kea';
1414

1515
import { ResultView } from './views';
1616
import { Pagination } from './pagination';
17+
import { Props as ResultViewProps } from './views/result_view';
1718
import { useSearchContextState } from './hooks';
1819
import { DocumentCreationButton } from '../document_creation_button';
1920
import { AppLogic } from '../../../app_logic';
2021
import { EngineLogic } from '../../engine';
2122
import { DOCS_PREFIX } from '../../../routes';
2223

23-
// TODO This is temporary until we create real Result type
24-
interface Result {
25-
[key: string]: {
26-
raw: string | string[] | number | number[] | undefined;
27-
};
28-
}
29-
3024
export const SearchExperienceContent: React.FC = () => {
3125
const { resultSearchTerm, totalResults, wasSearched } = useSearchContextState();
3226

3327
const { myRole } = useValues(AppLogic);
34-
const { engineName, isMetaEngine } = useValues(EngineLogic);
28+
const { isMetaEngine } = useValues(EngineLogic);
3529

3630
if (!wasSearched) return null;
3731

@@ -49,8 +43,8 @@ export const SearchExperienceContent: React.FC = () => {
4943
<EuiSpacer />
5044
<Results
5145
titleField="id"
52-
resultView={(props: { result: Result }) => {
53-
return <ResultView {...props} engineName={engineName} />;
46+
resultView={(props: ResultViewProps) => {
47+
return <ResultView {...props} />;
5448
}}
5549
/>
5650
<EuiSpacer />

x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/search_experience/views/result_view.test.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@ import React from 'react';
99
import { shallow } from 'enzyme';
1010

1111
import { ResultView } from '.';
12+
import { Result } from '../../../result/result';
1213

1314
describe('ResultView', () => {
1415
const result = {
1516
id: {
1617
raw: '1',
1718
},
19+
title: {
20+
raw: 'A title',
21+
},
22+
_meta: {
23+
id: '1',
24+
scopedId: '1',
25+
score: 100,
26+
engine: 'my-engine',
27+
},
1828
};
1929

2030
it('renders', () => {
21-
const wrapper = shallow(<ResultView result={result} engineName="engine1" />);
22-
expect(wrapper.find('div').length).toBe(1);
31+
const wrapper = shallow(<ResultView result={result} />);
32+
expect(wrapper.find(Result).exists()).toBe(true);
2333
});
2434
});

x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/search_experience/views/result_view.tsx

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,18 @@
55
*/
66

77
import React from 'react';
8-
import { EuiPanel, EuiSpacer } from '@elastic/eui';
98

10-
import { EuiLinkTo } from '../../../../../shared/react_router_helpers';
9+
import { Result as ResultType } from '../../../result/types';
10+
import { Result } from '../../../result/result';
1111

12-
// TODO replace this with a real result type when we implement a more sophisticated
13-
// ResultView
14-
interface Result {
15-
[key: string]: {
16-
raw: string | string[] | number | number[] | undefined;
17-
};
12+
export interface Props {
13+
result: ResultType;
1814
}
1915

20-
interface Props {
21-
engineName: string;
22-
result: Result;
23-
}
24-
25-
export const ResultView: React.FC<Props> = ({ engineName, result }) => {
26-
// TODO Replace this entire component when we migrate StuiResult
16+
export const ResultView: React.FC<Props> = ({ result }) => {
2717
return (
2818
<li>
29-
<EuiPanel>
30-
<EuiLinkTo to={`/engines/${engineName}/documents/${result.id.raw}`}>
31-
<strong>{result.id.raw}</strong>
32-
</EuiLinkTo>
33-
{Object.entries(result).map(([key, value]) => (
34-
<div key={key} style={{ wordBreak: 'break-all' }}>
35-
{key}: {value.raw}
36-
</div>
37-
))}
38-
</EuiPanel>
39-
<EuiSpacer />
19+
<Result result={result} />
4020
</li>
4121
);
4222
};

x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { InternalSchemaTypes } from '../../../shared/types';
8+
79
export interface FieldDetails {
810
name: string;
911
value: string | string[];
10-
type: string;
12+
type: InternalSchemaTypes;
1113
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { Library } from './library';

0 commit comments

Comments
 (0)