-
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 Node Pipelines] New patterns component for Grok processor #76533
Merged
jloleysens
merged 26 commits into
elastic:master
from
jloleysens:ingest-node/grok/new-patterns-component-use-array
Sep 24, 2020
Merged
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
329188d
wip, issues with use fields getting cleared somehow
jloleysens ca45ac6
New drag and drop text list component
jloleysens 2c87c65
remove box shadow from editor fields
jloleysens 10d1d12
Style grok patterns based on drag and drop in component templates
jloleysens 32228bc
fix i18n
jloleysens 8f365fa
Merge branch 'master' of github.com:elastic/kibana into ingest-node/g…
jloleysens 1be8bfc
update use_array - maintain the same API though
jloleysens e59e7de
Merge branch 'master' into ingest-node/grok/new-patterns-component-us…
elasticmachine f4a29c4
Merge branch 'master' into ingest-node/grok/new-patterns-component-us…
elasticmachine e4489fe
Merge branch 'master' of github.com:elastic/kibana into ingest-node/g…
jloleysens c8e6f1c
Grok processor should use the new use array interface
jloleysens 8fd740c
fix patterns field validation to check validity of pattern entires
jloleysens 1dd2f78
fix drag item styling
jloleysens 25ff6be
fix use of form in use effect and update behaviour of submit button
jloleysens cbc94d2
added smoke test for grok component
jloleysens dec25dc
fix i18n
jloleysens 7a847b0
Merge branch 'master' into ingest-node/grok/new-patterns-component-us…
elasticmachine 9f65205
Merge branch 'master' into ingest-node/grok/new-patterns-component-us…
elasticmachine 6852cb8
Implement PR feedback
jloleysens 6a85bac
Merge branch 'master' of github.com:elastic/kibana into ingest-node/g…
jloleysens f5c707b
Merge branch 'master' into ingest-node/grok/new-patterns-component-us…
elasticmachine c4235f9
Implemented design feedback
jloleysens eb632de
Merge branch 'master' into ingest-node/grok/new-patterns-component-us…
elasticmachine e856141
Merge branch 'master' into ingest-node/grok/new-patterns-component-us…
elasticmachine 9e72584
Merge branch 'master' into ingest-node/grok/new-patterns-component-us…
elasticmachine de6f2d6
Merge branch 'master' into ingest-node/grok/new-patterns-component-us…
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
24 changes: 24 additions & 0 deletions
24
...ors_editor/components/manage_processor_form/field_components/drag_and_drop_text_list.scss
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,24 @@ | ||
.pipelineProcessorsEditor__form__dragAndDropList { | ||
&__panel { | ||
box-shadow: none; | ||
} | ||
|
||
&__grabIcon { | ||
margin-right: $euiSizeS; | ||
} | ||
|
||
&__removeButton { | ||
margin-left: $euiSizeS; | ||
} | ||
|
||
&__errorIcon { | ||
margin-left: -$euiSizeXL; | ||
} | ||
|
||
&__item { | ||
background-color: $euiColorEmptyShade; | ||
padding-top: $euiSizeM; | ||
padding-bottom: $euiSizeM; | ||
border-bottom: $euiBorderThin; | ||
} | ||
} |
181 changes: 181 additions & 0 deletions
181
...sors_editor/components/manage_processor_form/field_components/drag_and_drop_text_list.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,181 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import React, { useState, useCallback, memo } from 'react'; | ||
import uuid from 'uuid'; | ||
import { | ||
EuiButtonEmpty, | ||
EuiButtonIcon, | ||
EuiDragDropContext, | ||
EuiDraggable, | ||
EuiDroppable, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiIcon, | ||
EuiPanel, | ||
EuiSpacer, | ||
EuiFieldText, | ||
EuiIconTip, | ||
} from '@elastic/eui'; | ||
|
||
import { | ||
UseField, | ||
ArrayItem, | ||
ValidationFunc, | ||
getFieldValidityAndErrorMessage, | ||
} from '../../../../../../shared_imports'; | ||
|
||
import './drag_and_drop_text_list.scss'; | ||
|
||
interface Props { | ||
value: ArrayItem[]; | ||
onMove: (sourceIdx: number, destinationIdx: number) => void; | ||
onAdd: () => void; | ||
onRemove: (id: number) => void; | ||
addLabel: string; | ||
/** | ||
* Validation to be applied to every text item | ||
*/ | ||
textValidation?: ValidationFunc<any, string, string>; | ||
} | ||
|
||
const i18nTexts = { | ||
removeItemButtonAriaLabel: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.dragAndDropList.removeItemLabel', | ||
{ defaultMessage: 'Remove item' } | ||
), | ||
}; | ||
|
||
function DragAndDropTextListComponent({ | ||
value, | ||
onMove, | ||
onAdd, | ||
onRemove, | ||
addLabel, | ||
textValidation, | ||
}: Props): JSX.Element { | ||
const [droppableId] = useState(() => uuid.v4()); | ||
|
||
const onDragEnd = useCallback( | ||
({ source, destination }) => { | ||
if (source && destination) { | ||
onMove(source.index, destination.index); | ||
} | ||
}, | ||
[onMove] | ||
); | ||
return ( | ||
<EuiPanel | ||
className="pipelineProcessorsEditor__form__dragAndDropList__panel" | ||
hasShadow={false} | ||
paddingSize="s" | ||
> | ||
<EuiDragDropContext onDragEnd={onDragEnd}> | ||
<EuiDroppable droppableId={droppableId}> | ||
{value.map((item, idx) => { | ||
return ( | ||
<EuiDraggable | ||
customDragHandle | ||
spacing="none" | ||
draggableId={String(item.id)} | ||
index={idx} | ||
key={item.id} | ||
> | ||
{(provided) => { | ||
return ( | ||
<EuiFlexGroup | ||
className="pipelineProcessorsEditor__form__dragAndDropList__item" | ||
justifyContent="center" | ||
alignItems="center" | ||
gutterSize="none" | ||
> | ||
<EuiFlexItem grow={false}> | ||
<div {...provided.dragHandleProps}> | ||
<EuiIcon | ||
className="pipelineProcessorsEditor__form__dragAndDropList__grabIcon" | ||
type="grab" | ||
/> | ||
</div> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<UseField<string> | ||
path={item.path} | ||
config={{ | ||
validations: textValidation | ||
? [{ validator: textValidation }] | ||
: undefined, | ||
}} | ||
readDefaultValueOnForm={!item.isNew} | ||
> | ||
{(field) => { | ||
const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage( | ||
field | ||
); | ||
return ( | ||
<EuiFlexGroup gutterSize="none" alignItems="center"> | ||
<EuiFlexItem> | ||
<EuiFieldText | ||
isInvalid={isInvalid} | ||
value={field.value} | ||
onChange={field.onChange} | ||
compressed | ||
fullWidth | ||
/> | ||
</EuiFlexItem> | ||
{typeof errorMessage === 'string' && ( | ||
<EuiFlexItem grow={false}> | ||
<div className="pipelineProcessorsEditor__form__dragAndDropList__errorIcon"> | ||
<EuiIconTip | ||
aria-label={errorMessage} | ||
content={errorMessage} | ||
type="alert" | ||
color="danger" | ||
/> | ||
</div> | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
); | ||
}} | ||
</UseField> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
{value.length > 1 ? ( | ||
<EuiButtonIcon | ||
aria-label={i18nTexts.removeItemButtonAriaLabel} | ||
className="pipelineProcessorsEditor__form__dragAndDropList__removeButton" | ||
iconType="minusInCircle" | ||
color="danger" | ||
onClick={() => onRemove(item.id)} | ||
/> | ||
) : ( | ||
// Render a no-op placeholder button | ||
<EuiIcon | ||
className="pipelineProcessorsEditor__form__dragAndDropList__removeButton" | ||
type="empty" | ||
/> | ||
)} | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}} | ||
</EuiDraggable> | ||
); | ||
})} | ||
</EuiDroppable> | ||
</EuiDragDropContext> | ||
{value.length ? <EuiSpacer size="s" /> : null} | ||
<EuiButtonEmpty iconType="plusInCircle" onClick={onAdd}> | ||
{addLabel} | ||
</EuiButtonEmpty> | ||
</EuiPanel> | ||
); | ||
} | ||
|
||
export const DragAndDropTextList = memo( | ||
DragAndDropTextListComponent | ||
) as typeof DragAndDropTextListComponent; |
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
5 changes: 5 additions & 0 deletions
5
...line_processors_editor/components/manage_processor_form/field_components/text_editor.scss
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,5 @@ | ||
.pipelineProcessorsEditor__form__textEditor { | ||
&__panel { | ||
box-shadow: none; | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
...ents/pipeline_processors_editor/components/manage_processor_form/processors/grok.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,56 @@ | ||
/* | ||
* 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 { mount } from 'enzyme'; | ||
|
||
import { | ||
uiSettingsServiceMock, | ||
i18nServiceMock, | ||
} from '../../../../../../../../../../src/core/public/mocks'; | ||
|
||
import { Form, useForm, KibanaContextProvider } from '../../../../../../shared_imports'; | ||
import { Grok } from './grok'; | ||
|
||
// @ts-ignore | ||
window.Worker = function () { | ||
this.postMessage = () => {}; | ||
(this as any).terminate = () => {}; | ||
}; | ||
|
||
describe('<Grok/>', () => { | ||
const setup = (props?: { defaultValue: Record<string, any> }) => { | ||
function MyComponent() { | ||
const { form } = useForm({ defaultValue: props?.defaultValue }); | ||
const i18n = i18nServiceMock.createStartContract(); | ||
return ( | ||
<KibanaContextProvider | ||
services={{ uiSettings: uiSettingsServiceMock.createSetupContract() }} | ||
> | ||
<i18n.Context> | ||
<Form form={form}> | ||
<Grok /> | ||
</Form> | ||
</i18n.Context> | ||
</KibanaContextProvider> | ||
); | ||
} | ||
return mount(<MyComponent />); | ||
}; | ||
|
||
beforeAll(() => { | ||
// disable all react-beautiful-dnd development warnings | ||
(window as any)['__react-beautiful-dnd-disable-dev-warnings'] = true; | ||
}); | ||
|
||
afterAll(() => { | ||
// enable all react-beautiful-dnd development warnings | ||
(window as any)['__react-beautiful-dnd-disable-dev-warnings'] = false; | ||
}); | ||
test('smoke', () => { | ||
setup({ defaultValue: { type: 'grok', fields: { patterns: ['test'] } } }); | ||
}); | ||
}); |
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.
Cool! I didn't know about the "empty" icon 👍