-
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
[Runtime fields editor] Form UI #81766
Merged
sebelga
merged 18 commits into
elastic:feature/runtime-field-editor
from
sebelga:runtime-fields/ui-form
Oct 30, 2020
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
42175b5
Setup runtimeField x-pack plugin
sebelga 1f2affd
Add basic form with initial tests
sebelga 7aed6ed
Mappings editor: import constant and type from runtimeField plugin
sebelga e190c9d
Fix imports and TS types
sebelga abd5290
Mappings editor: fix runtimeType to not allow to clear field
sebelga c74b7b3
Add field validations
sebelga 4c98da8
Tiny refactor
sebelga 898ada0
Add "Learn more about syntax" link
sebelga 25dd15d
Add defaultValue prop to form
sebelga 6c78fe2
Add onChange prop to form
sebelga 5294e05
Memoize form
sebelga 9e6911d
Update plugin-list.asciidoc
sebelga 91d1def
Correct i18nrc plugin order
sebelga 4b45b7f
Fix i18n & TS issues
sebelga 5b5b30f
Merge branch 'feature/runtime-field-editor' into runtime-fields/ui-form
kibanamachine df4f5c3
Set runtimeFields plugin size
sebelga aa38e3f
Merge branch 'feature/runtime-field-editor' into runtime-fields/ui-form
kibanamachine 8018cde
Merge branch 'feature/runtime-field-editor' into runtime-fields/ui-form
kibanamachine 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,3 +98,4 @@ pageLoadAssetSize: | |
visualizations: 295025 | ||
visualize: 57431 | ||
watcher: 43598 | ||
runtimeFields: 26275 |
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
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
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
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
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
], | ||
"configPath": ["xpack", "runtime_fields"], | ||
"requiredBundles": [ | ||
"kibanaReact", | ||
"esUiShared" | ||
] | ||
} |
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/runtime_fields/public/__jest__/setup_environment.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,44 @@ | ||
/* | ||
* 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'; | ||
|
||
jest.mock('../../../../../src/plugins/kibana_react/public', () => { | ||
const original = jest.requireActual('../../../../../src/plugins/kibana_react/public'); | ||
|
||
const CodeEditorMock = (props: any) => ( | ||
<input | ||
data-test-subj={props['data-test-subj'] || 'mockCodeEditor'} | ||
data-value={props.value} | ||
value={props.value} | ||
onChange={(syntheticEvent: any) => { | ||
props.onChange([syntheticEvent['0']]); | ||
}} | ||
/> | ||
); | ||
|
||
return { | ||
...original, | ||
CodeEditor: CodeEditorMock, | ||
}; | ||
}); | ||
|
||
jest.mock('@elastic/eui', () => { | ||
const original = jest.requireActual('@elastic/eui'); | ||
|
||
return { | ||
...original, | ||
EuiComboBox: (props: any) => ( | ||
<input | ||
data-test-subj={props['data-test-subj'] || 'mockComboBox'} | ||
data-currentvalue={props.selectedOptions} | ||
value={props.selectedOptions[0]?.value} | ||
onChange={async (syntheticEvent: any) => { | ||
props.onChange([syntheticEvent['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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { RuntimeFieldForm } from './runtime_field_form'; |
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/runtime_fields/public/components/runtime_field_form/index.ts
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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { RuntimeFieldForm } from './runtime_field_form'; |
89 changes: 89 additions & 0 deletions
89
...k/plugins/runtime_fields/public/components/runtime_field_form/runtime_field_form.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,89 @@ | ||
/* | ||
* 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 { act } from 'react-dom/test-utils'; | ||
|
||
import '../../__jest__/setup_environment'; | ||
import { registerTestBed, TestBed } from '../../test_utils'; | ||
import { RuntimeField } from '../../types'; | ||
import { RuntimeFieldForm, Props, FormState } from './runtime_field_form'; | ||
|
||
const setup = (props?: Props) => | ||
registerTestBed(RuntimeFieldForm, { | ||
memoryRouter: { | ||
wrapComponent: false, | ||
}, | ||
})(props) as TestBed; | ||
|
||
const docsBaseUri = 'https://jestTest.elastic.co'; | ||
|
||
describe('Runtime field form', () => { | ||
let testBed: TestBed; | ||
let onChange: jest.Mock<Props['onChange']> = jest.fn(); | ||
|
||
const lastOnChangeCall = (): FormState[] => onChange.mock.calls[onChange.mock.calls.length - 1]; | ||
|
||
beforeEach(() => { | ||
onChange = jest.fn(); | ||
}); | ||
|
||
test('should render expected 3 fields (name, returnType, script)', () => { | ||
testBed = setup({ docsBaseUri }); | ||
const { exists } = testBed; | ||
|
||
expect(exists('nameField')).toBe(true); | ||
expect(exists('typeField')).toBe(true); | ||
expect(exists('scriptField')).toBe(true); | ||
}); | ||
|
||
test('should have a link to learn more about painless syntax', () => { | ||
testBed = setup({ docsBaseUri }); | ||
const { exists, find } = testBed; | ||
|
||
expect(exists('painlessSyntaxLearnMoreLink')).toBe(true); | ||
expect(find('painlessSyntaxLearnMoreLink').props().href).toContain(docsBaseUri); | ||
}); | ||
|
||
test('should accept a "defaultValue" prop', () => { | ||
const defaultValue: RuntimeField = { | ||
name: 'foo', | ||
type: 'date', | ||
script: 'test=123', | ||
}; | ||
testBed = setup({ defaultValue, docsBaseUri }); | ||
const { find } = testBed; | ||
|
||
expect(find('nameField.input').props().value).toBe(defaultValue.name); | ||
expect(find('typeField').props().value).toBe(defaultValue.type); | ||
expect(find('scriptField').props().value).toBe(defaultValue.script); | ||
}); | ||
|
||
test('should accept an "onChange" prop to forward the form state', async () => { | ||
const defaultValue: RuntimeField = { | ||
name: 'foo', | ||
type: 'date', | ||
script: 'test=123', | ||
}; | ||
testBed = setup({ onChange, defaultValue, docsBaseUri }); | ||
|
||
expect(onChange).toHaveBeenCalled(); | ||
|
||
let lastState = lastOnChangeCall()[0]; | ||
expect(lastState.isValid).toBe(undefined); | ||
expect(lastState.isSubmitted).toBe(false); | ||
expect(lastState.submit).toBeDefined(); | ||
|
||
let data; | ||
await act(async () => { | ||
({ data } = await lastState.submit()); | ||
}); | ||
expect(data).toEqual(defaultValue); | ||
|
||
// Make sure that both isValid and isSubmitted state are now "true" | ||
lastState = lastOnChangeCall()[0]; | ||
expect(lastState.isValid).toBe(true); | ||
expect(lastState.isSubmitted).toBe(true); | ||
}); | ||
}); |
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.
Can we add a readme? I understand it might not contain much info at this point and is subject to change.
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 have the README.md ready in my following PR 😊