From a1aa8d820d42b4532d1043676bade901ced7a6d5 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Thu, 24 Sep 2020 12:41:57 -0400 Subject: [PATCH] handle url generator error when discover plugin is disabled --- .../add_document_form.tsx | 4 +++- .../add_documents_accordion.tsx | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/test_pipeline_flyout_tabs/add_document_form.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/test_pipeline_flyout_tabs/add_document_form.tsx index 2646836651bed..340cf1af92300 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/test_pipeline_flyout_tabs/add_document_form.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/test_pipeline_flyout_tabs/add_document_form.tsx @@ -196,7 +196,9 @@ export const AddDocumentForm: FunctionComponent = ({ onAddDocuments }) => - {i18nTexts.addDocumentSuccessMessage} + + {i18nTexts.addDocumentSuccessMessage} + diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/test_pipeline_flyout_tabs/add_documents_accordion/add_documents_accordion.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/test_pipeline_flyout_tabs/add_documents_accordion/add_documents_accordion.tsx index 0d246342dadb0..88ced6e9e94dd 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/test_pipeline_flyout_tabs/add_documents_accordion/add_documents_accordion.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/test_pipeline/test_pipeline_flyout_tabs/add_documents_accordion/add_documents_accordion.tsx @@ -9,6 +9,7 @@ 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'; @@ -16,6 +17,8 @@ import { AddDocumentForm } from '../add_document_form'; import './add_documents_accordion.scss'; +const DISCOVER_URL_GENERATOR_ID = 'DISCOVER_APP_URL_GENERATOR'; + const i18nTexts = { addDocumentsButton: i18n.translate( 'xpack.ingestPipelines.pipelineEditor.addDocumentsAccordion.addDocumentsButtonLabel', @@ -36,9 +39,20 @@ export const AddDocumentsAccordion: FunctionComponent = ({ onAddDocuments useEffect(() => { const getDiscoverUrl = async (): Promise => { - const { isDeprecated, createUrl } = services.urlGenerators.getUrlGenerator( - 'DISCOVER_APP_URL_GENERATOR' - ); + 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 + setDiscoverLink(undefined); + return; + } if (isDeprecated) { setDiscoverLink(undefined);