From 5b8bd6b6d04d12399bad1bbd26a2fb92edd401f1 Mon Sep 17 00:00:00 2001 From: Melissa Date: Thu, 1 Sep 2022 15:53:55 -0600 Subject: [PATCH] remove linkMenu --- .../spike_analysis_table/links_menu.tsx | 172 ------------------ 1 file changed, 172 deletions(-) delete mode 100644 x-pack/plugins/aiops/public/components/spike_analysis_table/links_menu.tsx diff --git a/x-pack/plugins/aiops/public/components/spike_analysis_table/links_menu.tsx b/x-pack/plugins/aiops/public/components/spike_analysis_table/links_menu.tsx deleted file mode 100644 index d606e0ae15fb..000000000000 --- a/x-pack/plugins/aiops/public/components/spike_analysis_table/links_menu.tsx +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { escapeKuery } from '@kbn/es-query'; -import React, { FC, useEffect, useMemo, useState } from 'react'; -import { FormattedMessage } from '@kbn/i18n-react'; -import { i18n } from '@kbn/i18n'; -import type { ChangePoint } from '@kbn/ml-agg-utils'; -import { - EuiButtonIcon, - EuiContextMenuItem, - EuiContextMenuPanel, - EuiPopover, - EuiProgress, - EuiToolTip, -} from '@elastic/eui'; -import { useAiOpsKibana } from '../../kibana_context'; -import { SEARCH_QUERY_LANGUAGE } from '../../application/utils/search_utils'; - -interface LinksMenuProps { - changePoint: ChangePoint; - dataViewId?: string; -} - -export const LinksMenu: FC = ({ changePoint, dataViewId }) => { - const [isPopoverOpen, setPopoverOpen] = useState(false); - const onButtonClick = setPopoverOpen.bind(null, !isPopoverOpen); - const closePopover = setPopoverOpen.bind(null, false); - const [openInDiscoverUrl, setOpenInDiscoverUrl] = useState(); - const [discoverUrlError, setDiscoverUrlError] = useState(); - - const aiOpsKibana = useAiOpsKibana(); - const { - services: { application, share, data }, - } = aiOpsKibana; - - useEffect(() => { - let unmounted = false; - - if (!application.capabilities.discover?.show) { - const discoverNotEnabled = i18n.translate( - 'xpack.ml.anomaliesTable.linksMenu.discoverNotEnabledErrorMessage', - { - defaultMessage: 'Discover is not enabled', - } - ); - - if (!unmounted) { - setDiscoverUrlError(discoverNotEnabled); - } - return; - } - - const discoverLocator = share.url.locators.get('DISCOVER_APP_LOCATOR'); - if (!discoverLocator) { - const discoverLocatorMissing = i18n.translate( - 'xpack.ml.anomaliesTable.linksMenu.discoverLocatorMissingErrorMessage', - { - defaultMessage: 'No locator for Discover detected', - } - ); - - if (!unmounted) { - setDiscoverUrlError(discoverLocatorMissing); - } - return; - } - - if (!dataViewId && !unmounted) { - const autoGeneratedDiscoverLinkError = i18n.translate( - 'xpack.ml.anomaliesTable.linksMenu.autoGeneratedDiscoverLinkErrorMessage', - { - defaultMessage: 'Unable to link to Discover; no data view exists for this index', - } - ); - - setDiscoverUrlError(autoGeneratedDiscoverLinkError); - return; - } - - const generateDiscoverUrl = async () => { - const url = await discoverLocator.getRedirectUrl({ - indexPatternId: dataViewId, - timeRange: data.query.timefilter.timefilter.getTime(), - filters: data.query.filterManager.getFilters(), - query: { - language: SEARCH_QUERY_LANGUAGE.KUERY, - query: `${escapeKuery(changePoint.fieldName)}:${escapeKuery( - String(changePoint.fieldValue) - )}`, - }, - }); - - if (!unmounted) { - setOpenInDiscoverUrl(url); - } - }; - - generateDiscoverUrl(); - - return () => { - unmounted = true; - }; - }, [application.capabilities.discover?.show]); - - const contextMenuItems = useMemo(() => { - const items = []; - // Add item from the start, but disable it during the URL generation. - const isLoading = discoverUrlError === undefined && openInDiscoverUrl === undefined; - - items.push( - - {discoverUrlError ? ( - - - - ) : ( - - )} - {isLoading ? : null} - - ); - - return items; - }, [openInDiscoverUrl, discoverUrlError]); - - const button = ( - - ); - - return ( -
- - - -
- ); -};