-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[App Search] Results follow-up #96709
Changes from 1 commit
c4627d5
f8cf5dd
bd1384c
032fc94
08d2798
f99baf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,11 @@ import { DraggableProvidedDragHandleProps } from 'react-beautiful-dnd'; | |
|
||
import './result.scss'; | ||
|
||
import { EuiButtonIcon, EuiPanel, EuiFlexGroup, EuiFlexItem, EuiIcon } from '@elastic/eui'; | ||
import { EuiPanel, EuiIcon } from '@elastic/eui'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { ReactRouterHelper } from '../../../shared/react_router_helpers/eui_components'; | ||
|
||
import { KibanaLogic } from '../../../shared/kibana'; | ||
import { Schema } from '../../../shared/types'; | ||
|
||
import { ENGINE_DOCUMENT_DETAIL_PATH } from '../../routes'; | ||
|
@@ -56,48 +55,26 @@ export const Result: React.FC<Props> = ({ | |
[result] | ||
); | ||
const numResults = resultFields.length; | ||
const documentLink = generateEncodedPath(ENGINE_DOCUMENT_DETAIL_PATH, { | ||
engineName: resultMeta.engine, | ||
documentId: resultMeta.id, | ||
}); | ||
|
||
const typeForField = (fieldName: string) => { | ||
if (schemaForTypeHighlights) return schemaForTypeHighlights[fieldName]; | ||
}; | ||
|
||
const ResultActions = () => { | ||
if (!shouldLinkToDetailPage && !actions.length) return null; | ||
return ( | ||
<EuiFlexItem grow={false}> | ||
<EuiFlexGroup gutterSize="s"> | ||
{shouldLinkToDetailPage && ( | ||
<ReactRouterHelper to={documentLink}> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonIcon | ||
iconType="eye" | ||
data-test-subj="DocumentDetailLink" | ||
aria-label={i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.result.documentDetailLink', | ||
{ defaultMessage: 'Visit document details' } | ||
)} | ||
/> | ||
</EuiFlexItem> | ||
</ReactRouterHelper> | ||
)} | ||
{actions.map(({ onClick, title, iconType, iconColor }) => ( | ||
<EuiFlexItem key={title}> | ||
<EuiButtonIcon | ||
iconType={iconType} | ||
onClick={onClick} | ||
color={iconColor ? iconColor : 'primary'} | ||
aria-label={title} | ||
/> | ||
</EuiFlexItem> | ||
))} | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
); | ||
}; | ||
const documentLink = shouldLinkToDetailPage | ||
? generateEncodedPath(ENGINE_DOCUMENT_DETAIL_PATH, { | ||
engineName: resultMeta.engine, | ||
documentId: resultMeta.id, | ||
}) | ||
: undefined; | ||
if (shouldLinkToDetailPage && documentLink) { | ||
actions.unshift({ | ||
cee-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onClick: () => KibanaLogic.values.navigateToUrl(documentLink), | ||
title: i18n.translate('xpack.enterpriseSearch.appSearch.result.documentDetailLink', { | ||
defaultMessage: 'Visit document details', | ||
}), | ||
iconType: 'eye', | ||
}); | ||
} | ||
cee-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<EuiPanel | ||
|
@@ -120,8 +97,8 @@ export const Result: React.FC<Props> = ({ | |
resultMeta={resultMeta} | ||
showScore={!!showScore} | ||
isMetaEngine={isMetaEngine} | ||
shouldLinkToDetailPage={shouldLinkToDetailPage} | ||
actions={<ResultActions />} | ||
documentLink={documentLink} | ||
actions={actions} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could have left this as |
||
/> | ||
{resultFields | ||
.slice(0, isOpen ? resultFields.length : RESULT_CUTOFF) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { EuiButtonIcon, EuiButtonIconColor } from '@elastic/eui'; | ||
|
||
import { ResultActions } from './result_actions'; | ||
|
||
describe('ResultActions', () => { | ||
const actions = [ | ||
{ | ||
title: 'Hide', | ||
onClick: jest.fn(), | ||
iconType: 'eyeClosed', | ||
iconColor: 'danger' as EuiButtonIconColor, | ||
}, | ||
{ | ||
title: 'Bookmark', | ||
onClick: jest.fn(), | ||
iconType: 'starFilled', | ||
iconColor: undefined, | ||
}, | ||
]; | ||
|
||
const wrapper = shallow(<ResultActions actions={actions} />); | ||
const buttons = wrapper.find(EuiButtonIcon); | ||
|
||
it('renders an action button for each action passed', () => { | ||
expect(buttons).toHaveLength(2); | ||
}); | ||
|
||
it('passes icon props correctly', () => { | ||
expect(buttons.first().prop('iconType')).toEqual('eyeClosed'); | ||
expect(buttons.first().prop('color')).toEqual('danger'); | ||
|
||
expect(buttons.last().prop('iconType')).toEqual('starFilled'); | ||
// Note that no iconColor was passed so it was defaulted to primary | ||
expect(buttons.last().prop('color')).toEqual('primary'); | ||
}); | ||
|
||
it('passes click events', () => { | ||
buttons.first().simulate('click'); | ||
expect(actions[0].onClick).toHaveBeenCalled(); | ||
|
||
buttons.last().simulate('click'); | ||
expect(actions[1].onClick).toHaveBeenCalled(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
|
||
import { ResultAction } from './types'; | ||
|
||
interface Props { | ||
actions: ResultAction[]; | ||
} | ||
|
||
export const ResultActions: React.FC<Props> = ({ actions }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call on moving this out to its own component, this simplifies things greatly. |
||
return ( | ||
<EuiFlexGroup gutterSize="s" responsive={false}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{actions.map(({ onClick, title, iconType, iconColor }) => ( | ||
<EuiFlexItem key={title} grow={false}> | ||
<EuiButtonIcon | ||
iconType={iconType} | ||
onClick={onClick} | ||
color={iconColor ? iconColor : 'primary'} | ||
aria-label={title} | ||
title={title} | ||
/> | ||
</EuiFlexItem> | ||
))} | ||
</EuiFlexGroup> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this got moved to the new
result_actions.test.tsx