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

[7.x] [App Search] Add document position indicator to Result component (#112759) #113271

Merged
merged 1 commit into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@ export const Library: React.FC = () => {
/>
<EuiSpacer />

<EuiTitle size="s">
<h3>With a document position</h3>
</EuiTitle>
<EuiSpacer />
<Result
{...{
...props,
resultPosition: 3,
result: {
...props.result,
_meta: {
id: '1',
score: 100,
engine: 'my-engine',
},
},
}}
/>
<EuiSpacer />

<EuiTitle size="s">
<h3>With an id and a score and an engine</h3>
</EuiTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { DraggableProvidedDragHandleProps } from 'react-beautiful-dnd';

import { shallow, ShallowWrapper } from 'enzyme';

import { EuiPanel } from '@elastic/eui';
import { EuiBadge, EuiPanel } from '@elastic/eui';

import { SchemaType } from '../../../shared/schema/types';
import { mountWithIntl } from '../../../test_helpers';

import { Result } from './result';
import { ResultField } from './result_field';
Expand Down Expand Up @@ -87,6 +88,12 @@ describe('Result', () => {

expect(header.prop('documentLink')).toBe('/engines/my-engine/documents/1');
});

it('contains the result position if one is passed', () => {
const wrapper = mountWithIntl(<Result {...props} resultPosition={4} />);
const header = wrapper.find(ResultHeader);
expect(header.find(EuiBadge).text()).toContain('#4');
});
});

describe('actions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Props {
result: ResultType;
isMetaEngine: boolean;
showScore?: boolean;
resultPosition?: number;
shouldLinkToDetailPage?: boolean;
schemaForTypeHighlights?: Schema;
actions?: ResultAction[];
Expand All @@ -44,6 +45,7 @@ export const Result: React.FC<Props> = ({
schemaForTypeHighlights,
actions = [],
dragHandleProps,
resultPosition,
}) => {
const [isOpen, setIsOpen] = useState(false);

Expand Down Expand Up @@ -100,6 +102,7 @@ export const Result: React.FC<Props> = ({
isMetaEngine={isMetaEngine}
documentLink={documentLink}
actions={actions}
resultPosition={resultPosition}
/>
{resultFields
.slice(0, isOpen ? resultFields.length : RESULT_CUTOFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import React from 'react';

import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { EuiBadge, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n/react';

import { ResultActions } from './result_actions';
import { ResultHeaderItem } from './result_header_item';
Expand All @@ -21,6 +23,7 @@ interface Props {
resultMeta: ResultMeta;
actions: ResultAction[];
documentLink?: string;
resultPosition?: number;
}

export const ResultHeader: React.FC<Props> = ({
Expand All @@ -29,6 +32,7 @@ export const ResultHeader: React.FC<Props> = ({
isMetaEngine,
actions,
documentLink,
resultPosition,
}) => {
return (
<header className="appSearchResultHeader">
Expand All @@ -39,6 +43,19 @@ export const ResultHeader: React.FC<Props> = ({
responsive={false}
wrap
>
{resultPosition && (
<EuiFlexItem grow={false}>
<EuiBadge color="hollow">
<FormattedMessage
id="xpack.enterpriseSearch.appSearch.result.resultPositionLabel"
defaultMessage="#{resultPosition}"
values={{
resultPosition,
}}
/>
</EuiBadge>
</EuiFlexItem>
)}
<EuiFlexItem grow>
<ResultHeaderItem
href={documentLink}
Expand Down