-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[ML] Migrate field-type-icon to EUI/React. #19159
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 3 additions & 5 deletions
8
x-pack/plugins/ml/public/components/field_data_card/field_data_card.html
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
32 changes: 32 additions & 0 deletions
32
...gins/ml/public/components/field_type_icon/__snapshots__/field_type_icon_view.test.js.snap
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,32 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`FieldTypeIcon render component inside tooltip wrapper 1`] = ` | ||
<EuiToolTip | ||
content="keyword" | ||
position="left" | ||
> | ||
<span> | ||
<FieldTypeIconContainer | ||
ariaLabel="Aggregatable string field" | ||
className="field-type-icon" | ||
iconChar="t" | ||
/> | ||
</span> | ||
</EuiToolTip> | ||
`; | ||
|
||
exports[`FieldTypeIcon render component when type matches a field type 1`] = ` | ||
<FieldTypeIconContainer | ||
ariaLabel="Aggregatable string field" | ||
className="field-type-icon" | ||
iconChar="t" | ||
/> | ||
`; | ||
|
||
exports[`FieldTypeIcon update component 1`] = ` | ||
<FieldTypeIconContainer | ||
ariaLabel="Aggregatable string field" | ||
className="field-type-icon" | ||
iconChar="t" | ||
/> | ||
`; |
37 changes: 0 additions & 37 deletions
37
x-pack/plugins/ml/public/components/field_type_icon/field_type_icon.html
This file was deleted.
Oops, something went wrong.
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
97 changes: 97 additions & 0 deletions
97
x-pack/plugins/ml/public/components/field_type_icon/field_type_icon_view.js
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,97 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import { EuiToolTip } from '@elastic/eui'; | ||
|
||
// don't use something like plugins/ml/../common | ||
// because it won't work with the jest tests | ||
import { ML_JOB_FIELD_TYPES } from '../../../common/constants/field_types'; | ||
|
||
export function FieldTypeIcon({ tooltipEnabled = false, type }) { | ||
let ariaLabel = ''; | ||
let iconClass = ''; | ||
let iconChar = ''; | ||
|
||
switch (type) { | ||
case ML_JOB_FIELD_TYPES.BOOLEAN: | ||
ariaLabel = 'Boolean field'; | ||
iconClass = 'fa-adjust'; | ||
break; | ||
case ML_JOB_FIELD_TYPES.DATE: | ||
ariaLabel = 'Date field'; | ||
iconClass = 'fa-clock-o'; | ||
break; | ||
case ML_JOB_FIELD_TYPES.NUMBER: | ||
ariaLabel = 'Metric field'; | ||
iconChar = '#'; | ||
break; | ||
case ML_JOB_FIELD_TYPES.GEO_POINT: | ||
ariaLabel = 'Geo-point field'; | ||
iconClass = 'fa-globe'; | ||
break; | ||
case ML_JOB_FIELD_TYPES.KEYWORD: | ||
ariaLabel = 'Aggregatable string field'; | ||
iconChar = 't'; | ||
break; | ||
case ML_JOB_FIELD_TYPES.TEXT: | ||
ariaLabel = 'String field'; | ||
iconClass = 'fa-file-text-o'; | ||
break; | ||
case ML_JOB_FIELD_TYPES.IP: | ||
ariaLabel = 'IP address field'; | ||
iconClass = 'fa-laptop'; | ||
break; | ||
default: | ||
// if type doesn't match one of ML_JOB_FIELD_TYPES | ||
// don't render the component at all | ||
return null; | ||
} | ||
|
||
let className = 'field-type-icon'; | ||
if (iconClass !== '') { | ||
className += ' kuiIcon ' + iconClass; | ||
} | ||
|
||
const containerProps = { | ||
ariaLabel, | ||
className, | ||
iconChar | ||
}; | ||
|
||
if (tooltipEnabled === true) { | ||
// wrap the inner component inside <span> because EuiToolTip doesn't seem | ||
// to support having another component directly inside the tooltip anchor | ||
// see https://github.com/elastic/eui/issues/839 | ||
return ( | ||
<EuiToolTip position="left" content={type}> | ||
<span><FieldTypeIconContainer {...containerProps} /></span> | ||
</EuiToolTip> | ||
); | ||
} | ||
|
||
return <FieldTypeIconContainer {...containerProps} />; | ||
} | ||
FieldTypeIcon.propTypes = { | ||
tooltipEnabled: PropTypes.bool, | ||
type: PropTypes.string | ||
}; | ||
|
||
function FieldTypeIconContainer({ ariaLabel, className, iconChar }) { | ||
return ( | ||
<span className="field-type-icon-container"> | ||
{(iconChar === '') ? ( | ||
<span aria-label={ariaLabel} className={className} /> | ||
) : ( | ||
<span aria-label={ariaLabel} className={className}> | ||
<strong aria-hidden="true">{iconChar}</strong> | ||
</span> | ||
)} | ||
</span> | ||
); | ||
} |
41 changes: 41 additions & 0 deletions
41
x-pack/plugins/ml/public/components/field_type_icon/field_type_icon_view.test.js
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,41 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { shallow } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import { FieldTypeIcon } from './field_type_icon_view'; | ||
|
||
describe('FieldTypeIcon', () => { | ||
|
||
test(`don't render component when type is undefined`, () => { | ||
const wrapper = shallow(<FieldTypeIcon />); | ||
expect(wrapper.isEmptyRender()).toBeTruthy(); | ||
}); | ||
|
||
test(`don't render component when type doesn't match a field type`, () => { | ||
const wrapper = shallow(<FieldTypeIcon type="foo" />); | ||
expect(wrapper.isEmptyRender()).toBeTruthy(); | ||
}); | ||
|
||
test(`render component when type matches a field type`, () => { | ||
const wrapper = shallow(<FieldTypeIcon type="keyword" />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test(`render component inside tooltip wrapper`, () => { | ||
const wrapper = shallow(<FieldTypeIcon type="keyword" tooltipEnabled={true} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test(`update component`, () => { | ||
const wrapper = shallow(<FieldTypeIcon />); | ||
expect(wrapper.isEmptyRender()).toBeTruthy(); | ||
wrapper.setProps({ type: 'keyword' }); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should migrate these Font Awesome icons to EUI icons I think. There are suitable replacements for most of these:
I can't find any suitable replacements for
You should raise an issue in the eui repo for the icons we need added.