-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Migrates ml-form-label to EUI/React. #21059
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f2c65e5
[ML] Migrates ml-form-label to a EUI/React based directive. JsonToolt…
walterra b121dc7
[ML] Add jest tests.
walterra 0bb4939
[ML] Allow the className of form-label to be overwritten when in an a…
walterra 2073221
[ML] Copied and adapted form-label directive description to component…
walterra 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
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/ml/public/components/form_label/__snapshots__/form_label.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,28 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`FormLabel Basic initialization 1`] = ` | ||
<React.Fragment> | ||
<label | ||
className="euiFormLabel" | ||
id="ml_aria_label_undefined" | ||
/> | ||
<Component | ||
position="top" | ||
/> | ||
</React.Fragment> | ||
`; | ||
|
||
exports[`FormLabel Full initialization 1`] = ` | ||
<React.Fragment> | ||
<label | ||
className="euiFormLabel" | ||
id="ml_aria_label_uid" | ||
> | ||
Label Text | ||
</label> | ||
<Component | ||
id="uid" | ||
position="top" | ||
/> | ||
</React.Fragment> | ||
`; |
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
x-pack/plugins/ml/public/components/form_label/form_label.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,32 @@ | ||
/* | ||
* 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 { FormLabel } from './form_label'; | ||
|
||
describe('FormLabel', () => { | ||
|
||
test('Basic initialization', () => { | ||
const wrapper = shallow(<FormLabel />); | ||
const props = wrapper.props(); | ||
expect(props.labelId).toBeUndefined(); | ||
expect(wrapper.find('label').text()).toBe(''); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('Full initialization', () => { | ||
const labelId = 'uid'; | ||
const labelText = 'Label Text'; | ||
const wrapper = shallow(<FormLabel labelId={labelId}>{labelText}</FormLabel>); | ||
|
||
const labelElement = wrapper.find('label'); | ||
expect(labelElement.props().id).toBe(`ml_aria_label_${labelId}`); | ||
expect(labelElement.text()).toBe(labelText); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
x-pack/plugins/ml/public/components/form_label/form_label_directive.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,52 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import angular from 'angular'; | ||
import { uiModules } from 'ui/modules'; | ||
const module = uiModules.get('apps/ml', ['react']); | ||
|
||
import { FormLabel } from './form_label'; | ||
|
||
// directive for creating a form label including a hoverable icon | ||
// to provide additional information in a tooltip. label and tooltip | ||
// text elements get unique ids based on label-id so they can be | ||
// referenced by attributes, for example: | ||
// | ||
// <ml-form-label label-id="uid">Label Text</ml-form-label> | ||
// <input | ||
// type="text" | ||
// aria-labelledby="ml_aria_label_uid" | ||
// aria-describedby="ml_aria_description_uid" | ||
// /> | ||
module.directive('mlFormLabel', function () { | ||
return { | ||
scope: { | ||
labelId: '@' | ||
}, | ||
restrict: 'E', | ||
replace: false, | ||
transclude: true, | ||
link: (scope, element, attrs, ctrl, transclude) => { | ||
const props = { | ||
labelId: scope.labelId, | ||
labelClassName: 'kuiFormLabel', | ||
// transclude the label text/elements from the angular template | ||
// to the labelRef from the react component. | ||
ref: c => angular.element(c.labelRef.current).append(transclude()) | ||
}; | ||
|
||
ReactDOM.render( | ||
React.createElement(FormLabel, props), | ||
element[0] | ||
); | ||
} | ||
}; | ||
}); |
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 |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
|
||
|
||
|
||
import './form_label'; | ||
import './form_label_directive'; | ||
import './styles/main.less'; |
54 changes: 54 additions & 0 deletions
54
x-pack/plugins/ml/public/components/json_tooltip/__snapshots__/json_tooltip.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,54 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`JsonTooltip Initialization with a non-existing tooltip attribute doesn't throw an error 1`] = ` | ||
<span | ||
aria-hidden="true" | ||
className="ml-info-icon" | ||
> | ||
<EuiIconTip | ||
aria-label="Info" | ||
content="" | ||
type="questionInCircle" | ||
/> | ||
<span | ||
className="ml-info-tooltip-text" | ||
id="ml_aria_description_non_existing_attribute" | ||
/> | ||
</span> | ||
`; | ||
|
||
exports[`JsonTooltip Initialize with existing tooltip attribute 1`] = ` | ||
<span | ||
aria-hidden="true" | ||
className="ml-info-icon" | ||
> | ||
<EuiIconTip | ||
aria-label="Info" | ||
content="Unique identifier for job, can use lowercase alphanumeric and underscores." | ||
type="questionInCircle" | ||
/> | ||
<span | ||
className="ml-info-tooltip-text" | ||
id="ml_aria_description_new_job_id" | ||
> | ||
Unique identifier for job, can use lowercase alphanumeric and underscores. | ||
</span> | ||
</span> | ||
`; | ||
|
||
exports[`JsonTooltip Plain initialization doesn't throw an error 1`] = ` | ||
<span | ||
aria-hidden="true" | ||
className="ml-info-icon" | ||
> | ||
<EuiIconTip | ||
aria-label="Info" | ||
content="" | ||
type="questionInCircle" | ||
/> | ||
<span | ||
className="ml-info-tooltip-text" | ||
id="ml_aria_description_undefined" | ||
/> | ||
</span> | ||
`; |
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
36 changes: 36 additions & 0 deletions
36
x-pack/plugins/ml/public/components/json_tooltip/json_tooltip.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,36 @@ | ||
/* | ||
* 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 { JsonTooltip } from './json_tooltip'; | ||
import tooltips from './tooltips.json'; | ||
|
||
describe('JsonTooltip', () => { | ||
|
||
test(`Plain initialization doesn't throw an error`, () => { | ||
const wrapper = shallow(<JsonTooltip />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test(`Initialization with a non-existing tooltip attribute doesn't throw an error`, () => { | ||
const id = 'non_existing_attribute'; | ||
const wrapper = shallow(<JsonTooltip id={id} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('Initialize with existing tooltip attribute', () => { | ||
const id = 'new_job_id'; | ||
const wrapper = shallow(<JsonTooltip id={id} />); | ||
|
||
// test the rendered span element which should be referenced by aria-describedby | ||
const span = wrapper.find('span.ml-info-tooltip-text'); | ||
expect(span.props().id).toBe(`ml_aria_description_${id}`); | ||
expect(span.text()).toBe(tooltips[id].text); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.
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.
Isn't it worth keeping in most of this comment which explains what the component does and just remove the Angular parts?
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.
I adapted the text here in 2073221. I originally copied it to
form_label_directive
but you're right of course, once the angular part is gone, we need the comment here.