Skip to content
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

[7.x] [Ingest Pipelines] Processor forms for processors A-D (#72849) #74949

Merged
merged 1 commit into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { OnXJsonEditorUpdateHandler, XJsonEditor } from './xjson_editor';
export { XJsonEditor } from './xjson_editor';
export { TextEditor } from './text_editor';
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 { EuiPanel } from '@elastic/eui';
import React, { FunctionComponent } from 'react';
import { EuiFormRow } from '@elastic/eui';
import {
CodeEditor,
FieldHook,
getFieldValidityAndErrorMessage,
} from '../../../../../../shared_imports';

interface Props {
field: FieldHook<string>;
editorProps: { [key: string]: any };
}

export const TextEditor: FunctionComponent<Props> = ({ field, editorProps }) => {
const { value, helpText, setValue, label } = field;
const { errorMessage } = getFieldValidityAndErrorMessage(field);

return (
<EuiFormRow
label={label}
helpText={helpText}
isInvalid={typeof errorMessage === 'string'}
error={errorMessage}
fullWidth
>
<EuiPanel paddingSize="s" hasShadow={false}>
<CodeEditor value={value} onChange={setValue} {...(editorProps as any)} />
</EuiPanel>
</EuiFormRow>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiPanel } from '@elastic/eui';
import { XJsonLang } from '@kbn/monaco';
import React, { FunctionComponent, useCallback } from 'react';
import { EuiFormRow } from '@elastic/eui';
import {
CodeEditor,
FieldHook,
getFieldValidityAndErrorMessage,
Monaco,
} from '../../../../../../shared_imports';
import { FieldHook, Monaco } from '../../../../../../shared_imports';

export type OnXJsonEditorUpdateHandler<T = { [key: string]: any }> = (arg: {
data: {
raw: string;
format(): T;
};
validate(): boolean;
isValid: boolean | undefined;
}) => void;
import { TextEditor } from './text_editor';

interface Props {
field: FieldHook<string>;
editorProps: { [key: string]: any };
}

export const XJsonEditor: FunctionComponent<Props> = ({ field, editorProps }) => {
const { value, helpText, setValue, label } = field;
const { value, setValue } = field;
const { xJson, setXJson, convertToJson } = Monaco.useXJsonMode(value);
const { errorMessage } = getFieldValidityAndErrorMessage(field);

const onChange = useCallback(
(s) => {
Expand All @@ -42,25 +27,18 @@ export const XJsonEditor: FunctionComponent<Props> = ({ field, editorProps }) =>
[setValue, setXJson, convertToJson]
);
return (
<EuiFormRow
label={label}
helpText={helpText}
isInvalid={typeof errorMessage === 'string'}
error={errorMessage}
fullWidth
>
<EuiPanel paddingSize="s" hasShadow={false}>
<CodeEditor
value={xJson}
languageId={XJsonLang.ID}
editorDidMount={(m) => {
XJsonLang.registerGrammarChecker(m);
}}
options={{ minimap: { enabled: false } }}
onChange={onChange}
{...(editorProps as any)}
/>
</EuiPanel>
</EuiFormRow>
<TextEditor
field={field}
editorProps={{
value: xJson,
languageId: XJsonLang.ID,
options: { minimap: { enabled: false } },
editorDidMount: (m: any) => {
XJsonLang.registerGrammarChecker(m);
},
onChange,
...editorProps,
}}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ export const ManageProcessorForm: FunctionComponent<Props> = ({
const handleSubmit = useCallback(
async (data: FormData, isValid: boolean) => {
if (isValid) {
const { type, customOptions, ...options } = data;
const { type, customOptions, fields } = data;
onSubmit({
type,
options: customOptions ? customOptions : options,
options: customOptions ? customOptions : fields,
});
}
},
[onSubmit]
);

const maybeProcessorOptions = processor?.options;
const { form } = useForm({
defaultValue: processor?.options,
defaultValue: { fields: maybeProcessorOptions ?? {} },
onSubmit: handleSubmit,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
EuiFlyoutHeader,
EuiFlyoutBody,
EuiFlyoutFooter,
EuiSpacer,
EuiTabs,
EuiTab,
EuiTitle,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
} from '@elastic/eui';

import { Form, FormDataProvider, FormHook } from '../../../../../shared_imports';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { FunctionComponent } from 'react';
import { EuiHorizontalRule } from '@elastic/eui';
import { EuiHorizontalRule, EuiSpacer } from '@elastic/eui';

import { FormDataProvider } from '../../../../../shared_imports';
import { ProcessorInternal } from '../../types';
Expand Down Expand Up @@ -36,6 +36,7 @@ export const ProcessorSettingsFields: FunctionComponent<Props> = ({ processor })
return (
<>
<formDescriptor.FieldsComponent />
<EuiSpacer size="m" />
<CommonProcessorFields />
</>
);
Expand Down
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, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';

import {
FIELD_TYPES,
fieldValidators,
UseField,
ComboBoxField,
} from '../../../../../../shared_imports';

import { FieldsConfig } from './shared';
import { FieldNameField } from './common_fields/field_name_field';

const { emptyField } = fieldValidators;

const fieldsConfig: FieldsConfig = {
value: {
type: FIELD_TYPES.COMBO_BOX,
deserializer: (v) => (Array.isArray(v) ? v : [String(v)]),
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.appendForm.valueFieldLabel', {
defaultMessage: 'Value',
}),
helpText: i18n.translate('xpack.ingestPipelines.pipelineEditor.appendForm.valueFieldHelpText', {
defaultMessage: 'The value to be appended by this processor.',
}),
validations: [
{
validator: emptyField(
i18n.translate('xpack.ingestPipelines.pipelineEditor.appendForm.valueRequiredError', {
defaultMessage: 'A value to set is required.',
})
),
},
],
},
};

export const Append: FunctionComponent = () => {
return (
<>
<FieldNameField
helpText={i18n.translate('xpack.ingestPipelines.pipelineEditor.appendForm.fieldHelpText', {
defaultMessage: 'The field to be appended to.',
})}
/>

<UseField config={fieldsConfig.value} component={ComboBoxField} path="fields.value" />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 { FIELD_TYPES, UseField, Field } from '../../../../../../shared_imports';

import { FieldsConfig } from './shared';
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { FieldNameField } from './common_fields/field_name_field';

const fieldsConfig: FieldsConfig = {
target_field: {
type: FIELD_TYPES.TEXT,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.bytesForm.targetFieldLabel', {
defaultMessage: 'Target field (optional)',
}),
helpText: i18n.translate('xpack.ingestPipelines.pipelineEditor.bytesForm.targetFieldHelpText', {
defaultMessage: 'The field to assign the converted value to',
}),
},
};

export const Bytes: FunctionComponent = () => {
return (
<>
<FieldNameField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.bytesForm.fieldNameHelpText',
{ defaultMessage: 'The field to convert.' }
)}
/>

<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />

<IgnoreMissingField />
</>
);
};
Loading