Skip to content

Commit 1aa0ef4

Browse files
address review feedback
1 parent 53f278b commit 1aa0ef4

File tree

10 files changed

+71
-59
lines changed

10 files changed

+71
-59
lines changed

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/processor_form/add_processor_form.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export interface Props {
3333
form: FormHook<Fields>;
3434
onOpen: () => void;
3535
esDocsBasePath: string;
36-
getDefaultProcessorOptions: () => Fields;
3736
closeFlyout: () => void;
3837
handleSubmit: (shouldCloseFlyout?: boolean) => Promise<void>;
3938
}
@@ -67,7 +66,6 @@ export const AddProcessorForm: FunctionComponent<Props> = ({
6766
onOpen,
6867
form,
6968
esDocsBasePath,
70-
getDefaultProcessorOptions,
7169
closeFlyout,
7270
handleSubmit,
7371
}) => {
@@ -110,7 +108,7 @@ export const AddProcessorForm: FunctionComponent<Props> = ({
110108
</EuiFlexGroup>
111109
</EuiFlyoutHeader>
112110
<EuiFlyoutBody>
113-
<ProcessorSettingsFields getDefaultProcessorOptions={getDefaultProcessorOptions} />
111+
<ProcessorSettingsFields />
114112
</EuiFlyoutBody>
115113
<EuiFlyoutFooter>
116114
<EuiFlexGroup justifyContent="flexEnd">

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/processor_form/edit_processor_form.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ import { Fields } from './processor_form.container';
3434

3535
export interface Props {
3636
isOnFailure: boolean;
37-
processor: ProcessorInternal;
3837
form: FormHook<Fields>;
3938
onOpen: () => void;
4039
esDocsBasePath: string;
41-
getDefaultProcessorOptions: () => Fields;
4240
closeFlyout: () => void;
4341
resetProcessors: () => void;
4442
handleSubmit: (shouldCloseFlyout?: boolean) => Promise<void>;
43+
getProcessor: () => ProcessorInternal;
4544
}
4645

4746
const updateButtonLabel = i18n.translate(
@@ -94,12 +93,11 @@ const getFlyoutTitle = (isOnFailure: boolean) => {
9493
};
9594

9695
export const EditProcessorForm: FunctionComponent<Props> = ({
97-
processor,
96+
getProcessor,
9897
form,
9998
isOnFailure,
10099
onOpen,
101100
esDocsBasePath,
102-
getDefaultProcessorOptions,
103101
closeFlyout,
104102
handleSubmit,
105103
resetProcessors,
@@ -111,6 +109,8 @@ export const EditProcessorForm: FunctionComponent<Props> = ({
111109
isExecutingPipeline,
112110
} = testPipelineData;
113111

112+
const processor = getProcessor();
113+
114114
const processorOutput =
115115
processor &&
116116
testOutputPerProcessor &&
@@ -149,12 +149,7 @@ export const EditProcessorForm: FunctionComponent<Props> = ({
149149
/>
150150
);
151151
} else {
152-
flyoutContent = (
153-
<ProcessorSettingsFields
154-
processor={processor}
155-
getDefaultProcessorOptions={getDefaultProcessorOptions}
156-
/>
157-
);
152+
flyoutContent = <ProcessorSettingsFields processor={processor} />;
158153
}
159154

160155
return (
@@ -203,7 +198,7 @@ export const EditProcessorForm: FunctionComponent<Props> = ({
203198
if (tab.id === 'output') {
204199
await handleSubmit(false);
205200
} else {
206-
form.reset({ defaultValue: getDefaultProcessorOptions() });
201+
form.reset({ defaultValue: { fields: processor.options } });
207202
}
208203
setActiveTab(tab.id);
209204
}}

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/processor_form/processor_form.container.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React, { FunctionComponent, useCallback, useEffect } from 'react';
7+
import React, { FunctionComponent, useCallback, useEffect, useRef } from 'react';
88

99
import { useForm, OnFormUpdateArg, FormData, useKibana } from '../../../../../shared_imports';
1010
import { ProcessorInternal } from '../../types';
@@ -29,34 +29,36 @@ interface Props {
2929
onOpen: () => void;
3030
onClose: () => void;
3131
processor?: ProcessorInternal;
32-
unsavedFormData?: Omit<ProcessorInternal, 'id'>;
3332
}
3433

3534
export const ProcessorFormContainer: FunctionComponent<Props> = ({
3635
processor,
3736
onFormUpdate,
3837
onSubmit,
39-
unsavedFormData,
4038
onClose,
4139
...rest
4240
}) => {
4341
const { services } = useKibana();
4442

45-
const getDefaultProcessorOptions = (): Fields => {
46-
let defaultFields;
43+
// We need to keep track of the processor form state if the user
44+
// has made config changes, navigated between tabs (Configuration vs. Output)
45+
// and has not yet submitted the form
46+
const unsavedFormState = useRef<ProcessorInternal['options'] | undefined>();
4747

48-
if (unsavedFormData) {
49-
const { options } = unsavedFormData;
50-
defaultFields = { fields: options };
48+
const getProcessor = useCallback((): ProcessorInternal => {
49+
let options;
50+
51+
if (unsavedFormState?.current) {
52+
options = unsavedFormState.current;
5153
} else {
52-
defaultFields = { fields: processor?.options ?? {} };
54+
options = processor?.options ?? {};
5355
}
5456

55-
return defaultFields;
56-
};
57+
return { ...processor, options } as ProcessorInternal;
58+
}, [processor, unsavedFormState]);
5759

5860
const { form } = useForm({
59-
defaultValue: getDefaultProcessorOptions(),
61+
defaultValue: { fields: getProcessor().options },
6062
});
6163

6264
const handleSubmit = useCallback(
@@ -65,9 +67,13 @@ export const ProcessorFormContainer: FunctionComponent<Props> = ({
6567

6668
if (isValid) {
6769
const { type, customOptions, fields } = data as FormData;
70+
const options = customOptions ? customOptions : fields;
71+
72+
unsavedFormState.current = options;
73+
6874
onSubmit({
6975
type,
70-
options: customOptions ? customOptions : fields,
76+
options,
7177
});
7278

7379
if (shouldCloseFlyout) {
@@ -78,12 +84,12 @@ export const ProcessorFormContainer: FunctionComponent<Props> = ({
7884
[form, onClose, onSubmit]
7985
);
8086

81-
const resetProcessors = () => {
87+
const resetProcessors = useCallback(() => {
8288
onSubmit({
8389
type: processor!.type,
8490
options: processor?.options || {},
8591
});
86-
};
92+
}, [onSubmit, processor]);
8793

8894
useEffect(() => {
8995
const subscription = form.subscribe(onFormUpdate);
@@ -99,9 +105,8 @@ export const ProcessorFormContainer: FunctionComponent<Props> = ({
99105
return (
100106
<EditProcessorForm
101107
{...rest}
102-
processor={processor!}
103108
form={form}
104-
getDefaultProcessorOptions={getDefaultProcessorOptions}
109+
getProcessor={getProcessor}
105110
esDocsBasePath={services.documentation.getEsDocsBasePath()}
106111
closeFlyout={onClose}
107112
resetProcessors={resetProcessors}
@@ -113,7 +118,6 @@ export const ProcessorFormContainer: FunctionComponent<Props> = ({
113118
<AddProcessorForm
114119
{...rest}
115120
form={form}
116-
getDefaultProcessorOptions={getDefaultProcessorOptions}
117121
esDocsBasePath={services.documentation.getEsDocsBasePath()}
118122
closeFlyout={onClose}
119123
handleSubmit={handleSubmit}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
.processorOutput {
2-
&__callOutCodeBlock > pre {
3-
background: transparent;
2+
&__callOut {
3+
&--customIcon {
4+
.euiCallOutHeader {
5+
align-items: center;
6+
}
7+
}
8+
&__codeBlock > pre {
9+
background: transparent;
10+
}
411
}
512
}

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/processor_form/processor_output/processor_output.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ export const ProcessorOutput: FunctionComponent<Props> = ({
112112
const getOutputContent = () => {
113113
switch (status) {
114114
case 'skipped':
115-
return <EuiCallOut title={i18nTexts.skippedCalloutTitle} iconType={SkippedIcon} />;
115+
return (
116+
<EuiCallOut
117+
title={i18nTexts.skippedCalloutTitle}
118+
iconType={SkippedIcon}
119+
className="processorOutput__callOut processorOutput__callOut--customIcon"
120+
/>
121+
);
116122
case 'dropped':
117123
return <EuiCallOut title={i18nTexts.droppedCalloutTitle} iconType="indexClose" />;
118124
case 'success':
@@ -127,11 +133,16 @@ export const ProcessorOutput: FunctionComponent<Props> = ({
127133
return <NoOutputCallOut />;
128134
case 'error':
129135
return (
130-
<EuiCallOut iconType={ErrorIcon} title={i18nTexts.processorErrorTitle} color="danger">
136+
<EuiCallOut
137+
iconType={ErrorIcon}
138+
title={i18nTexts.processorErrorTitle}
139+
color="danger"
140+
className="processorOutput__callOut processorOutput__callOut--customIcon"
141+
>
131142
<EuiCodeBlock
132143
language="json"
133144
paddingSize="none"
134-
className="processorOutput__callOutCodeBlock"
145+
className="processorOutput__callOut__codeBlock"
135146
transparentBackground
136147
>
137148
{JSON.stringify(error, null, 2)}
@@ -144,9 +155,10 @@ export const ProcessorOutput: FunctionComponent<Props> = ({
144155
iconType={ErrorIgnoredIcon}
145156
title={i18nTexts.processorIgnoredErrorTitle}
146157
color="warning"
158+
className="processorOutput__callOut processorOutput__callOut--customIcon"
147159
>
148160
<EuiCodeBlock
149-
className="processorOutput__callOutCodeBlock"
161+
className="processorOutput__callOut__codeBlock"
150162
language="json"
151163
paddingSize="none"
152164
transparentBackground

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/processor_form/processor_settings_fields.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@ import { ProcessorInternal } from '../../types';
1313
import { getProcessorDescriptor } from '../shared';
1414
import { CommonProcessorFields, ProcessorTypeField } from './processors/common_fields';
1515
import { Custom } from './processors/custom';
16-
import { Fields } from './processor_form.container';
1716

1817
export interface Props {
1918
processor?: ProcessorInternal;
20-
getDefaultProcessorOptions: () => Fields;
2119
}
2220

23-
export const ProcessorSettingsFields: FunctionComponent<Props> = ({
24-
processor,
25-
getDefaultProcessorOptions,
26-
}) => {
21+
export const ProcessorSettingsFields: FunctionComponent<Props> = ({ processor }) => {
2722
return (
2823
<>
2924
<ProcessorTypeField initialType={processor?.type} />
@@ -33,7 +28,6 @@ export const ProcessorSettingsFields: FunctionComponent<Props> = ({
3328
<FormDataProvider pathsToWatch="type">
3429
{(arg: any) => {
3530
const { type } = arg;
36-
const { fields: defaultOptions } = getDefaultProcessorOptions();
3731

3832
if (type?.length) {
3933
const formDescriptor = getProcessorDescriptor(type as any);
@@ -59,7 +53,7 @@ export const ProcessorSettingsFields: FunctionComponent<Props> = ({
5953
</>
6054
);
6155
}
62-
return <Custom defaultOptions={defaultOptions} />;
56+
return <Custom defaultOptions={processor?.options} />;
6357
}
6458

6559
// If the user has not yet defined a type, we do not show any settings fields
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.documentsDropdownPanel {
2+
min-width: 200px;
3+
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import {
1717
EuiSpacer,
1818
} from '@elastic/eui';
1919

20-
import { Document } from '../../types';
20+
import { Document } from '../../../types';
2121

22-
import { TestPipelineFlyoutTab } from '../test_pipeline/test_pipeline_flyout_tabs';
22+
import { TestPipelineFlyoutTab } from '../test_pipeline_flyout_tabs';
23+
24+
import './documents_dropdown.scss';
2325

2426
const i18nTexts = {
2527
dropdownLabel: i18n.translate(
@@ -82,6 +84,7 @@ export const DocumentsDropdown: FunctionComponent<Props> = ({
8284
withTitle
8385
repositionOnScroll
8486
data-test-subj="documentsDropdown"
87+
panelClassName="documentsDropdownPanel"
8588
>
8689
<EuiSelectable
8790
singleSelection
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
export { DocumentsDropdown } from './documents_dropdown';

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/context/processors_context.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@ export const PipelineProcessorsContextProvider: FunctionComponent<Props> = ({
106106
validate: () => Promise.resolve(true),
107107
});
108108

109-
// We need to keep track of the processor form state if the user
110-
// has made config changes, navigated between tabs (Configuration vs. Output)
111-
// and has not yet submitted the form
112-
const [unsavedProcessorFormData, setUnsavedProcessorFormData] = useState<
113-
Omit<ProcessorInternal, 'id'> | undefined
114-
>(undefined);
115-
116109
const onFormUpdate = useCallback<(arg: OnFormUpdateArg<any>) => void>(
117110
({ isValid, validate }) => {
118111
setFormState({
@@ -156,8 +149,6 @@ export const PipelineProcessorsContextProvider: FunctionComponent<Props> = ({
156149
});
157150
break;
158151
case 'managingProcessor':
159-
setUnsavedProcessorFormData(processorTypeAndOptions);
160-
161152
processorsDispatch({
162153
type: 'updateProcessor',
163154
payload: {
@@ -179,7 +170,6 @@ export const PipelineProcessorsContextProvider: FunctionComponent<Props> = ({
179170
const onCloseSettingsForm = useCallback(() => {
180171
setMode({ id: 'idle' });
181172
setFormState({ validate: () => Promise.resolve(true) });
182-
setUnsavedProcessorFormData(undefined);
183173
}, [setFormState, setMode]);
184174

185175
const onTreeAction = useCallback<OnActionHandler>(
@@ -250,7 +240,6 @@ export const PipelineProcessorsContextProvider: FunctionComponent<Props> = ({
250240
onFormUpdate={onFormUpdate}
251241
onSubmit={onSubmit}
252242
onClose={onCloseSettingsForm}
253-
unsavedFormData={unsavedProcessorFormData}
254243
/>
255244
) : undefined}
256245
{mode.id === 'removingProcessor' && (

0 commit comments

Comments
 (0)