From 156692cbfbf62309d23190baad5651544ed737c7 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Mon, 17 Aug 2020 14:25:26 -0400 Subject: [PATCH] [Ingest pipelines] Add KibanaContextProvider as dependency of processor editor (#75018) --- .../on_failure_processors_title.tsx | 9 +++-- .../pipeline_form/pipeline_form_fields.tsx | 7 +--- .../pipeline_form/processors_header.tsx | 9 +++-- .../pipeline_processors_editor.helpers.tsx | 34 +++++++++++++++++-- .../pipeline_processors_editor.test.tsx | 7 ---- .../manage_processor_form.container.tsx | 14 ++++---- .../test_pipeline/flyout_provider.tsx | 11 +++--- .../flyout_tabs/tab_documents.tsx | 7 ++-- .../context/context.tsx | 6 ---- .../context/processors_context.tsx | 13 ------- .../pipeline_processors_editor/types.ts | 9 ----- 11 files changed, 62 insertions(+), 64 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/on_failure_processors_title.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/on_failure_processors_title.tsx index d223653442819..d2c001b0aaa13 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/on_failure_processors_title.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/on_failure_processors_title.tsx @@ -8,10 +8,10 @@ import React, { FunctionComponent } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { usePipelineProcessorsContext } from '../pipeline_processors_editor/context'; +import { useKibana } from '../../../shared_imports'; export const OnFailureProcessorsTitle: FunctionComponent = () => { - const { links } = usePipelineProcessorsContext(); + const { services } = useKibana(); return ( { values={{ learnMoreLink: ( {i18n.translate( diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx index 32beb61039a90..3a97e6408b144 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx @@ -10,7 +10,7 @@ import { EuiSpacer, EuiSwitch, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { Processor } from '../../../../common/types'; -import { getUseField, getFormRow, Field, useKibana } from '../../../shared_imports'; +import { getUseField, getFormRow, Field } from '../../../shared_imports'; import { ProcessorsEditorContextProvider, @@ -45,8 +45,6 @@ export const PipelineFormFields: React.FunctionComponent = ({ hasVersion, onEditorFlyoutOpen, }) => { - const { services } = useKibana(); - const [isVersionVisible, setIsVersionVisible] = useState(hasVersion); return ( @@ -123,9 +121,6 @@ export const PipelineFormFields: React.FunctionComponent = ({ diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/processors_header.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/processors_header.tsx index 3e8cd999a484a..1f27d611e54d4 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/processors_header.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/processors_header.tsx @@ -9,7 +9,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiLink, EuiText, EuiTitle } from '@elastic/ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { usePipelineProcessorsContext } from '../pipeline_processors_editor/context'; +import { useKibana } from '../../../shared_imports'; import { LoadFromJsonButton, @@ -22,7 +22,7 @@ export interface Props { } export const ProcessorsHeader: FunctionComponent = ({ onLoadJson }) => { - const { links } = usePipelineProcessorsContext(); + const { services } = useKibana(); return ( = ({ onLoadJson }) => { defaultMessage="The processors used to pre-process documents before indexing. {learnMoreLink}" values={{ learnMoreLink: ( - + {i18n.translate( 'xpack.ingestPipelines.pipelineEditor.processorsDocumentationLink', { diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.helpers.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.helpers.tsx index 5ac43953e79bc..2e7a47e0c93de 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.helpers.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.helpers.tsx @@ -5,6 +5,11 @@ */ import { act } from 'react-dom/test-utils'; import React from 'react'; + +import { notificationServiceMock, scopedHistoryMock } from 'src/core/public/mocks'; + +import { LocationDescriptorObject } from 'history'; +import { KibanaContextProvider } from 'src/plugins/kibana_react/public'; import { registerTestBed, TestBed } from '../../../../../../../test_utils'; import { ProcessorsEditorContextProvider, @@ -13,6 +18,13 @@ import { GlobalOnFailureProcessorsEditor, } from '../'; +import { + breadcrumbService, + uiMetricService, + documentationService, + apiService, +} from '../../../services'; + jest.mock('@elastic/eui', () => { const original = jest.requireActual('@elastic/eui'); @@ -60,11 +72,27 @@ jest.mock('react-virtualized', () => { }; }); +const history = scopedHistoryMock.create(); +history.createHref.mockImplementation((location: LocationDescriptorObject) => { + return `${location.pathname}?${location.search}`; +}); + +const appServices = { + breadcrumbs: breadcrumbService, + metric: uiMetricService, + documentation: documentationService, + api: apiService, + notifications: notificationServiceMock.createSetupContract(), + history, +}; + const testBedSetup = registerTestBed( (props: Props) => ( - - - + + + + + ), { doMountAsync: false, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.test.tsx index d3c5df02c837e..b12f324528167 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.test.tsx @@ -3,11 +3,9 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { notificationServiceMock } from 'src/core/public/mocks'; import { setup, SetupResult } from './pipeline_processors_editor.helpers'; import { Pipeline } from '../../../../../common/types'; -import { apiService } from '../../../services'; const testProcessors: Pick = { processors: [ @@ -46,11 +44,6 @@ describe('Pipeline Editor', () => { }, onFlyoutOpen: jest.fn(), onUpdate, - links: { - esDocsBasePath: 'test', - }, - toasts: notificationServiceMock.createSetupContract().toasts, - api: apiService, }); }); diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/manage_processor_form.container.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/manage_processor_form.container.tsx index 84551ce152099..083529921b0a7 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/manage_processor_form.container.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/manage_processor_form.container.tsx @@ -6,11 +6,10 @@ import React, { FunctionComponent, useCallback, useEffect } from 'react'; -import { useForm, OnFormUpdateArg, FormData } from '../../../../../shared_imports'; +import { useForm, OnFormUpdateArg, FormData, useKibana } from '../../../../../shared_imports'; import { ProcessorInternal } from '../../types'; import { ManageProcessorForm as ViewComponent } from './manage_processor_form'; -import { usePipelineProcessorsContext } from '../../context'; export type ManageProcessorFormOnSubmitArg = Omit; @@ -33,9 +32,7 @@ export const ManageProcessorForm: FunctionComponent = ({ onSubmit, ...rest }) => { - const { - links: { esDocsBasePath }, - } = usePipelineProcessorsContext(); + const { services } = useKibana(); const handleSubmit = useCallback( async (data: FormData, isValid: boolean) => { @@ -67,6 +64,11 @@ export const ManageProcessorForm: FunctionComponent = ({ }, [onFormUpdate]); return ( - + ); }; diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/flyout_provider.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/flyout_provider.tsx index ad88259e3bcc4..53aeb9fdc08ba 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/flyout_provider.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/flyout_provider.tsx @@ -17,6 +17,8 @@ import { EuiCallOut, } from '@elastic/eui'; +import { useKibana } from '../../../../../shared_imports'; + import { usePipelineProcessorsContext, useTestConfigContext } from '../../context'; import { serialize } from '../../serialize'; @@ -27,10 +29,9 @@ export interface Props { } export const FlyoutProvider: React.FunctionComponent = ({ children }) => { + const { services } = useKibana(); const { state: { processors }, - api, - toasts, } = usePipelineProcessorsContext(); const serializedProcessors = serialize(processors.state); @@ -53,7 +54,7 @@ export const FlyoutProvider: React.FunctionComponent = ({ children }) => setIsExecuting(true); setExecuteError(null); - const { error, data: output } = await api.simulatePipeline({ + const { error, data: output } = await services.api.simulatePipeline({ documents, verbose, pipeline: { ...serializedProcessors }, @@ -68,7 +69,7 @@ export const FlyoutProvider: React.FunctionComponent = ({ children }) => setExecuteOutput(output); - toasts.addSuccess( + services.notifications.toasts.addSuccess( i18n.translate('xpack.ingestPipelines.testPipelineFlyout.successNotificationText', { defaultMessage: 'Pipeline executed', }), @@ -79,7 +80,7 @@ export const FlyoutProvider: React.FunctionComponent = ({ children }) => setSelectedTab('output'); }, - [serializedProcessors, api, toasts] + [services.api, services.notifications.toasts, serializedProcessors] ); useEffect(() => { diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/flyout_tabs/tab_documents.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/flyout_tabs/tab_documents.tsx index 593347f8b2343..794d935571210 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/flyout_tabs/tab_documents.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/flyout_tabs/tab_documents.tsx @@ -17,9 +17,10 @@ import { Form, useForm, FormConfig, + useKibana, } from '../../../../../../shared_imports'; -import { usePipelineProcessorsContext, useTestConfigContext, TestConfig } from '../../../context'; +import { useTestConfigContext, TestConfig } from '../../../context'; import { documentsSchema } from './schema'; @@ -31,7 +32,7 @@ interface Props { } export const DocumentsTab: React.FunctionComponent = ({ handleExecute, isExecuting }) => { - const { links } = usePipelineProcessorsContext(); + const { services } = useKibana(); const { setCurrentTestConfig, testConfig } = useTestConfigContext(); const { verbose: cachedVerbose, documents: cachedDocuments } = testConfig; @@ -71,7 +72,7 @@ export const DocumentsTab: React.FunctionComponent = ({ handleExecute, is values={{ learnMoreLink: ( diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/context/context.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/context/context.tsx index 1ccfcc8e19755..a1ea0fd9d0b9e 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/context/context.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/context/context.tsx @@ -18,9 +18,6 @@ interface Props extends ProcessorsContextProps { export const ProcessorsEditorContextProvider: FunctionComponent = ({ children, - links, - api, - toasts, onUpdate, value, onFlyoutOpen, @@ -29,9 +26,6 @@ export const ProcessorsEditorContextProvider: FunctionComponent = ({ diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/context/processors_context.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/context/processors_context.tsx index 7124efc4905a7..f83803da7bf91 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/context/processors_context.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/context/processors_context.tsx @@ -15,10 +15,7 @@ import React, { useRef, } from 'react'; -import { NotificationsSetup } from 'src/core/public'; - import { Processor } from '../../../../../common/types'; -import { ApiService } from '../../../services'; import { EditorMode, @@ -27,7 +24,6 @@ import { OnUpdateHandlerArg, ContextValue, ContextValueState, - Links, ProcessorInternal, } from '../types'; @@ -51,9 +47,6 @@ import { getValue } from '../utils'; const PipelineProcessorsContext = createContext({} as any); export interface Props { - links: Links; - api: ApiService; - toasts: NotificationsSetup['toasts']; value: { processors: Processor[]; onFailure?: Processor[]; @@ -66,9 +59,6 @@ export interface Props { } export const PipelineProcessorsContextProvider: FunctionComponent = ({ - links, - api, - toasts, value: { processors: originalProcessors, onFailure: originalOnFailureProcessors }, onUpdate, onFlyoutOpen, @@ -211,9 +201,6 @@ export const PipelineProcessorsContextProvider: FunctionComponent = ({ return (