-
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
[Ingest pipelines] Custom processor form #66022
Merged
alisonelizabeth
merged 6 commits into
elastic:feature/pipeline-editor
from
alisonelizabeth:pipeline-editor/custom-processor
May 13, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6af901
add support for custom processor
alisonelizabeth 1eedd62
clean up existing processors
alisonelizabeth b69a946
cleanup
alisonelizabeth 32009a1
fix bug when re-editing processor
alisonelizabeth 5314442
Merge branch 'feature/pipeline-editor' of github.com:elastic/kibana i…
alisonelizabeth f2a746d
Merge branch 'feature/pipeline-editor' into pipeline-editor/custom-pr…
elasticmachine 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
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 |
---|---|---|
|
@@ -4,14 +4,13 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiComboBox } from '@elastic/eui'; | ||
import React, { FunctionComponent } from 'react'; | ||
import { | ||
FIELD_TYPES, | ||
FieldConfig, | ||
UseField, | ||
fieldValidators, | ||
FormRow, | ||
ComboBoxField, | ||
} from '../../../../../../../shared_imports'; | ||
import { types } from '../../map_processor_type_to_form'; | ||
|
||
|
@@ -24,8 +23,17 @@ const { emptyField } = fieldValidators; | |
const typeConfig: FieldConfig = { | ||
type: FIELD_TYPES.COMBO_BOX, | ||
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.typeField.typeFieldLabel', { | ||
defaultMessage: 'Type', | ||
defaultMessage: 'Processor', | ||
}), | ||
deserializer: (value: string | undefined) => { | ||
if (value) { | ||
return [value]; | ||
} | ||
return []; | ||
}, | ||
serializer: (value: string[]) => { | ||
return value[0]; | ||
}, | ||
validations: [ | ||
{ | ||
validator: emptyField( | ||
|
@@ -39,27 +47,21 @@ const typeConfig: FieldConfig = { | |
|
||
export const ProcessorTypeField: FunctionComponent<Props> = ({ initialType }) => { | ||
return ( | ||
<FormRow | ||
title={i18n.translate('xpack.ingestPipelines.pipelineEditor.typeFieldTitle', { | ||
defaultMessage: 'Type', | ||
})} | ||
> | ||
<UseField config={typeConfig} path={'type'} defaultValue={initialType}> | ||
{typeField => { | ||
return ( | ||
<EuiComboBox | ||
onChange={([selected]) => typeField.setValue(selected?.value)} | ||
selectedOptions={ | ||
typeField.value | ||
? [{ value: typeField.value as string, label: typeField.value as string }] | ||
: [] | ||
} | ||
singleSelection={{ asPlainText: true }} | ||
options={types.map(type => ({ label: type, value: type }))} | ||
/> | ||
); | ||
}} | ||
</UseField> | ||
</FormRow> | ||
<UseField | ||
config={typeConfig} | ||
defaultValue={initialType} | ||
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. Just a note: by setting the defaultValue manually you lose the benefit to read it from the form |
||
path="type" | ||
component={ComboBoxField} | ||
componentProps={{ | ||
euiFieldProps: { | ||
fullWidth: true, | ||
options: types.map(type => ({ label: type, value: type })), | ||
noSuggestions: false, | ||
singleSelection: { | ||
asPlainText: true, | ||
}, | ||
}, | ||
}} | ||
/> | ||
); | ||
}; |
90 changes: 90 additions & 0 deletions
90
...nents/pipeline_processors_editor/components/processor_settings_form/processors/custom.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,90 @@ | ||
/* | ||
* 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, { FunctionComponent } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { | ||
FieldConfig, | ||
FIELD_TYPES, | ||
fieldValidators, | ||
UseField, | ||
JsonEditorField, | ||
} from '../../../../../../shared_imports'; | ||
|
||
const { emptyField, isJsonField } = fieldValidators; | ||
|
||
const customConfig: FieldConfig = { | ||
type: FIELD_TYPES.TEXT, | ||
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.customForm.optionsFieldLabel', { | ||
defaultMessage: 'Configuration options', | ||
}), | ||
serializer: (value: string) => { | ||
try { | ||
return JSON.parse(value); | ||
} catch (error) { | ||
// swallow error and return non-parsed value; | ||
return value; | ||
} | ||
}, | ||
deserializer: (value: any) => { | ||
if (value === '') { | ||
return '{\n\n}'; | ||
} | ||
return JSON.stringify(value, null, 2); | ||
}, | ||
validations: [ | ||
{ | ||
validator: emptyField( | ||
i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.customForm.configurationRequiredError', | ||
{ | ||
defaultMessage: 'Configuration options are required.', | ||
} | ||
) | ||
), | ||
}, | ||
{ | ||
validator: isJsonField( | ||
i18n.translate('xpack.ingestPipelines.pipelineEditor.customForm.invalidJsonError', { | ||
defaultMessage: 'The input is not valid.', | ||
}) | ||
), | ||
}, | ||
], | ||
}; | ||
|
||
interface Props { | ||
defaultOptions?: any; | ||
} | ||
|
||
/** | ||
* This is a catch-all component to support settings for custom processors | ||
* or existing processors not yet supported by the UI. | ||
* | ||
* We store the settings in a field called "customOptions" | ||
**/ | ||
export const Custom: FunctionComponent<Props> = ({ defaultOptions }) => { | ||
return ( | ||
<UseField | ||
path="customOptions" | ||
component={JsonEditorField} | ||
config={customConfig} | ||
defaultValue={defaultOptions} | ||
componentProps={{ | ||
euiCodeEditorProps: { | ||
height: '300px', | ||
'aria-label': i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.customForm.optionsFieldAriaLabel', | ||
{ | ||
defaultMessage: 'Configuration options JSON editor', | ||
} | ||
), | ||
}, | ||
}} | ||
/> | ||
); | ||
}; |
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
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.
Thanks for adding these!