-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ResultActions component + DRY out link behavior
- Create new separate ResultActions component - Pass actions array through to header and have haeder in charge of conditional visibility / FlexItem wrapper (this matches the other header items) - shouldLinkToDetailPage: instead of generating custom JSX, just have it be a standard action and append it to the actions array Link behavior: - ResultHeaderItem - switch to EuiLinkTo, no need for extra wrapper - ResultHeader - DRY out unnecessary extra path generation - instead pass down a conditional documentLink instead of a bool
- Loading branch information
Showing
8 changed files
with
189 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...nterprise_search/public/applications/app_search/components/result/result_actions.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...ins/enterprise_search/public/applications/app_search/components/result/result_actions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) => { | ||
return ( | ||
<EuiFlexGroup gutterSize="s" responsive={false}> | ||
{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> | ||
); | ||
}; |
Oops, something went wrong.