From ea059d4a3696abfb7ef6292c215db2fdc73bfddf Mon Sep 17 00:00:00 2001 From: Vadim Kibana <82822460+vadimkibana@users.noreply.github.com> Date: Tue, 15 Feb 2022 16:57:02 +0100 Subject: [PATCH] Use Discover locator to generate URL (#124282) * use Discover locator to generate URL * improve locator check * do not import discover plugin * allow for share plugin to be missing Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../helpers/setup_environment.tsx | 7 ++--- .../add_docs_accordion/add_docs_accordion.tsx | 31 ++++--------------- .../public/application/index.tsx | 4 +-- .../application/mount_management_section.ts | 2 +- 4 files changed, 11 insertions(+), 33 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/setup_environment.tsx b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/setup_environment.tsx index a2c36e204cbea..8e128692c41c5 100644 --- a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/setup_environment.tsx +++ b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/setup_environment.tsx @@ -12,6 +12,7 @@ import { LocationDescriptorObject } from 'history'; import { HttpSetup } from 'kibana/public'; import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; +import { sharePluginMock } from '../../../../../../src/plugins/share/public/mocks'; import { notificationServiceMock, docLinksServiceMock, @@ -48,11 +49,7 @@ const appServices = { notifications: notificationServiceMock.createSetupContract(), history, uiSettings: uiSettingsServiceMock.createSetupContract(), - urlGenerators: { - getUrlGenerator: jest.fn().mockReturnValue({ - createUrl: jest.fn(), - }), - }, + url: sharePluginMock.createStartContract().url, fileUpload: { getMaxBytes: jest.fn().mockReturnValue(100), getMaxBytesFormatted: jest.fn().mockReturnValue('100'), diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/test_pipeline/test_pipeline_tabs/tab_documents/add_docs_accordion/add_docs_accordion.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/test_pipeline/test_pipeline_tabs/tab_documents/add_docs_accordion/add_docs_accordion.tsx index ed817498586a6..e6454b207ab35 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/test_pipeline/test_pipeline_tabs/tab_documents/add_docs_accordion/add_docs_accordion.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/test_pipeline/test_pipeline_tabs/tab_documents/add_docs_accordion/add_docs_accordion.tsx @@ -10,7 +10,6 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiAccordion, EuiText, EuiSpacer, EuiLink } from '@elastic/eui'; -import { UrlGeneratorsDefinition } from 'src/plugins/share/public'; import { useKibana } from '../../../../../../../../shared_imports'; import { useIsMounted } from '../../../../../use_is_mounted'; @@ -18,8 +17,6 @@ import { AddDocumentForm } from '../add_document_form'; import './add_docs_accordion.scss'; -const DISCOVER_URL_GENERATOR_ID = 'DISCOVER_APP_URL_GENERATOR'; - const i18nTexts = { addDocumentsButton: i18n.translate( 'xpack.ingestPipelines.pipelineEditor.addDocumentsAccordion.addDocumentsButtonLabel', @@ -46,34 +43,18 @@ export const AddDocumentsAccordion: FunctionComponent = ({ onAddDocuments useEffect(() => { const getDiscoverUrl = async (): Promise => { - let isDeprecated: UrlGeneratorsDefinition['isDeprecated']; - let createUrl: UrlGeneratorsDefinition['createUrl']; - - // This try/catch may not be necessary once - // https://github.com/elastic/kibana/issues/78344 is addressed - try { - ({ isDeprecated, createUrl } = - services.urlGenerators.getUrlGenerator(DISCOVER_URL_GENERATOR_ID)); - } catch (e) { - // Discover plugin is not enabled + const locator = services.share?.url.locators.get('DISCOVER_APP_LOCATOR'); + if (!locator) { setDiscoverLink(undefined); return; } - - if (isDeprecated) { - setDiscoverLink(undefined); - return; - } - - const discoverUrl = await createUrl({ indexPatternId: undefined }); - - if (isMounted.current) { - setDiscoverLink(discoverUrl); - } + const discoverUrl = await locator.getUrl({ indexPatternId: undefined }); + if (!isMounted.current) return; + setDiscoverLink(discoverUrl); }; getDiscoverUrl(); - }, [isMounted, services.urlGenerators]); + }, [isMounted, services.share]); return (