Skip to content

Commit c0c4524

Browse files
committed
address PR feedback
- Update form schema and form schema types - simplify the save handler - refactor processors_title to processors_header
1 parent 1284555 commit c0c4524

File tree

8 files changed

+58
-161
lines changed

8 files changed

+58
-161
lines changed

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ import { Pipeline, Processor } from '../../../../common/types';
1313

1414
import './pipeline_form.scss';
1515

16-
import {
17-
OnUpdateHandlerArg,
18-
OnUpdateHandler,
19-
SerializeResult,
20-
} from '../pipeline_processors_editor';
16+
import { OnUpdateHandlerArg, OnUpdateHandler } from '../pipeline_processors_editor';
2117

2218
import { PipelineRequestFlyout } from './pipeline_request_flyout';
2319
import { PipelineTestFlyout } from './pipeline_test_flyout';
2420
import { PipelineFormFields } from './pipeline_form_fields';
2521
import { PipelineFormError } from './pipeline_form_error';
2622
import { pipelineFormSchema } from './schema';
23+
import { PipelineForm as IPipelineForm } from './types';
2724

2825
export interface PipelineFormProps {
2926
onSave: (pipeline: Pipeline) => void;
@@ -34,12 +31,11 @@ export interface PipelineFormProps {
3431
isEditing?: boolean;
3532
}
3633

37-
const defaultFormValue = Object.freeze({
34+
const defaultFormValue: Pipeline = Object.freeze({
3835
name: '',
3936
description: '',
4037
processors: [],
4138
on_failure: [],
42-
version: '',
4339
});
4440

4541
export const PipelineForm: React.FunctionComponent<PipelineFormProps> = ({
@@ -70,30 +66,24 @@ export const PipelineForm: React.FunctionComponent<PipelineFormProps> = ({
7066

7167
const processorStateRef = useRef<OnUpdateHandlerArg>();
7268

73-
const handleSave: FormConfig['onSubmit'] = async (formData, isValid) => {
74-
let override: SerializeResult | undefined;
75-
69+
const handleSave: FormConfig<IPipelineForm>['onSubmit'] = async (formData, isValid) => {
7670
if (!isValid) {
7771
return;
7872
}
7973

8074
if (processorStateRef.current) {
8175
const state = processorStateRef.current;
8276
if (await state.validate()) {
83-
override = state.getData();
84-
} else {
85-
return;
77+
onSave({ ...formData, ...state.getData() });
8678
}
8779
}
88-
89-
onSave({ ...formData, ...(override || {}) } as Pipeline);
9080
};
9181

9282
const handleTestPipelineClick = () => {
9383
setIsTestingPipeline(true);
9484
};
9585

96-
const { form } = useForm({
86+
const { form } = useForm<IPipelineForm>({
9787
schema: pipelineFormSchema,
9888
defaultValue: defaultFormValues,
9989
onSubmit: handleSave,

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
OnDoneLoadJsonHandler,
2121
} from '../pipeline_processors_editor';
2222

23-
import { ProcessorsTitle } from './processors_title';
23+
import { ProcessorsHeader } from './processors_header';
2424
import { OnFailureProcessorsTitle } from './on_failure_processors_title';
2525

2626
interface Props {
@@ -134,7 +134,7 @@ export const PipelineFormFields: React.FunctionComponent<Props> = ({
134134
<div className="pipelineProcessorsEditor">
135135
<EuiFlexGroup gutterSize="m" responsive={false} direction="column">
136136
<EuiFlexItem grow={false}>
137-
<ProcessorsTitle
137+
<ProcessorsHeader
138138
onLoadJson={onLoadJson}
139139
onTestPipelineClick={onTestPipelineClick}
140140
isTestButtonDisabled={isTestButtonDisabled}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface Props {
1919
onLoadJson: OnDoneLoadJsonHandler;
2020
}
2121

22-
export const ProcessorsTitle: FunctionComponent<Props> = ({
22+
export const ProcessorsHeader: FunctionComponent<Props> = ({
2323
onTestPipelineClick,
2424
isTestButtonDisabled,
2525
onLoadJson,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { i18n } from '@kbn/i18n';
8+
import { FormSchema, FIELD_TYPES, fieldValidators, fieldFormatters } from '../../../shared_imports';
9+
10+
import { PipelineForm } from './types';
11+
12+
const { emptyField } = fieldValidators;
13+
const { toInt } = fieldFormatters;
14+
15+
export const pipelineFormSchema: FormSchema<PipelineForm> = {
16+
name: {
17+
type: FIELD_TYPES.TEXT,
18+
label: i18n.translate('xpack.ingestPipelines.form.nameFieldLabel', {
19+
defaultMessage: 'Name',
20+
}),
21+
validations: [
22+
{
23+
validator: emptyField(
24+
i18n.translate('xpack.ingestPipelines.form.pipelineNameRequiredError', {
25+
defaultMessage: 'Name is required.',
26+
})
27+
),
28+
},
29+
],
30+
},
31+
description: {
32+
type: FIELD_TYPES.TEXTAREA,
33+
label: i18n.translate('xpack.ingestPipelines.form.descriptionFieldLabel', {
34+
defaultMessage: 'Description (optional)',
35+
}),
36+
},
37+
version: {
38+
type: FIELD_TYPES.NUMBER,
39+
label: i18n.translate('xpack.ingestPipelines.form.versionFieldLabel', {
40+
defaultMessage: 'Version (optional)',
41+
}),
42+
formatters: [toInt],
43+
},
44+
};

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/schema.tsx

Lines changed: 0 additions & 138 deletions
This file was deleted.

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
import { Pipeline } from '../../../../common/types';
88

99
export type ReadProcessorsFunction = () => Pick<Pipeline, 'processors' | 'on_failure'>;
10+
11+
export type PipelineForm = Omit<Pipeline, 'processors' | 'on_failure'>;

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/load_from_json/modal_provider.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
88
import React, { FunctionComponent, useRef, useState } from 'react';
99
import { EuiConfirmModal, EuiOverlayMask, EuiSpacer, EuiText, EuiCallOut } from '@elastic/eui';
1010

11-
import {
12-
JsonEditor,
13-
OnJsonEditorUpdateHandler,
14-
} from '../../../../../../../../../src/plugins/es_ui_shared/public';
11+
import { JsonEditor, OnJsonEditorUpdateHandler } from '../../../../../shared_imports';
1512

1613
import { Processor } from '../../../../../../common/types';
1714

x-pack/plugins/ingest_pipelines/public/shared_imports.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export {
2222
UseRequestConfig,
2323
WithPrivileges,
2424
Monaco,
25+
JsonEditor,
26+
OnJsonEditorUpdateHandler,
2527
} from '../../../../src/plugins/es_ui_shared/public/';
2628

2729
export {

0 commit comments

Comments
 (0)