From 92be06292dbdebaf8d454ee0a27dfd83e07b58a0 Mon Sep 17 00:00:00 2001 From: Abdul Wahab Zahid Date: Tue, 4 Oct 2022 21:03:51 +0200 Subject: [PATCH] Fix: Consider all summary pings to determine if monitor is only fleet managed. (#142004) * Consider all ping to determine if monitor is only fleet managed. * Close popover on outside click as the built-in functionality is buggy. * Handle the case where only private locations are selected among a mix of locations. (cherry picked from commit 1eb059de111082dc0ff35f260340a2114fb2d92f) --- .../action_bar/action_bar.tsx | 109 ++++++++++-------- .../monitor_list/columns/test_now_col.tsx | 12 +- .../overview/monitor_list/monitor_list.tsx | 2 +- 3 files changed, 68 insertions(+), 55 deletions(-) diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/action_bar/action_bar.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/action_bar/action_bar.tsx index 0cae34a05e35..6823206dc4b8 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/action_bar/action_bar.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/action_bar/action_bar.tsx @@ -14,6 +14,7 @@ import { EuiButtonEmpty, EuiText, EuiPopover, + EuiOutsideClickDetector, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; @@ -71,8 +72,10 @@ export const ActionBar = ({ const mouseMoveTimeoutIds = useRef<[number, number]>([0, 0]); const isReadOnly = monitor[ConfigKey.MONITOR_SOURCE_TYPE] === SourceType.PROJECT; - const hasServiceManagedLocation = monitor.locations?.some((loc) => loc.isServiceManaged); - const isOnlyPrivateLocations = !locations.some((loc) => loc.isServiceManaged); + const isAnyPublicLocationSelected = monitor.locations?.some((loc) => loc.isServiceManaged); + const isOnlyPrivateLocations = + !locations.some((loc) => loc.isServiceManaged) || + ((monitor.locations?.length ?? 0) > 0 && !isAnyPublicLocationSelected); const { data, status } = useFetcher(() => { if (!isSaving || !isValid) { @@ -150,55 +153,61 @@ export const ActionBar = ({ {onTestNow && ( {/* Popover is used instead of EuiTooltip until the resolution of https://github.com/elastic/eui/issues/5604 */} - onTestNow()} - onMouseOver={() => { - // We need this custom logic to display a popover even when button is disabled. - clearTimeout(mouseMoveTimeoutIds.current[1]); - if (mouseMoveTimeoutIds.current[0] === 0) { - mouseMoveTimeoutIds.current[0] = setTimeout(() => { - clearTimeout(mouseMoveTimeoutIds.current[1]); - setIsPopoverOpen(true); - }, 250) as unknown as number; - } - }} - onMouseOut={() => { - // We need this custom logic to display a popover even when button is disabled. - clearTimeout(mouseMoveTimeoutIds.current[1]); - mouseMoveTimeoutIds.current[1] = setTimeout(() => { - clearTimeout(mouseMoveTimeoutIds.current[0]); - setIsPopoverOpen(false); - mouseMoveTimeoutIds.current = [0, 0]; - }, 100) as unknown as number; - }} - > - {testRun ? RE_RUN_TEST_LABEL : RUN_TEST_LABEL} - - } - isOpen={isPopoverOpen} + { + setIsPopoverOpen(false); + }} > - -

- {isTestRunInProgress - ? TEST_SCHEDULED_LABEL - : isOnlyPrivateLocations || (isValid && !hasServiceManagedLocation) - ? PRIVATE_AVAILABLE_LABEL - : TEST_NOW_DESCRIPTION} -

-
-
+ onTestNow()} + onMouseOver={() => { + // We need this custom logic to display a popover even when button is disabled. + clearTimeout(mouseMoveTimeoutIds.current[1]); + if (mouseMoveTimeoutIds.current[0] === 0) { + mouseMoveTimeoutIds.current[0] = setTimeout(() => { + clearTimeout(mouseMoveTimeoutIds.current[1]); + setIsPopoverOpen(true); + }, 250) as unknown as number; + } + }} + onMouseOut={() => { + // We need this custom logic to display a popover even when button is disabled. + clearTimeout(mouseMoveTimeoutIds.current[1]); + mouseMoveTimeoutIds.current[1] = setTimeout(() => { + clearTimeout(mouseMoveTimeoutIds.current[0]); + setIsPopoverOpen(false); + mouseMoveTimeoutIds.current = [0, 0]; + }, 100) as unknown as number; + }} + > + {testRun ? RE_RUN_TEST_LABEL : RUN_TEST_LABEL} + + } + isOpen={isPopoverOpen} + > + +

+ {isTestRunInProgress + ? TEST_SCHEDULED_LABEL + : isOnlyPrivateLocations || (isValid && !isAnyPublicLocationSelected) + ? PRIVATE_AVAILABLE_LABEL + : TEST_NOW_DESCRIPTION} +

+
+
+
)} diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/overview/monitor_list/columns/test_now_col.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/overview/monitor_list/columns/test_now_col.tsx index 17e8047ac64c..390994646d08 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/overview/monitor_list/columns/test_now_col.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/overview/monitor_list/columns/test_now_col.tsx @@ -5,8 +5,8 @@ * 2.0. */ +import React, { useMemo } from 'react'; import { EuiButtonIcon, EuiLoadingSpinner, EuiToolTip } from '@elastic/eui'; -import React from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { Ping } from '../../../../../../common/runtime_types'; import { testNowMonitorAction } from '../../../../state/actions'; @@ -16,17 +16,21 @@ import * as labels from '../translations'; export const TestNowColumn = ({ monitorId, configId, - selectedMonitor, + summaryPings, }: { monitorId: string; configId?: string; - selectedMonitor: Ping; + summaryPings: Ping[]; }) => { const dispatch = useDispatch(); const testNowRun = useSelector(testNowRunSelector(configId)); - if (selectedMonitor.monitor.fleet_managed) { + const isOnFleetManaged = useMemo(() => { + return summaryPings.every((ping) => !!ping.monitor.fleet_managed); + }, [summaryPings]); + + if (isOnFleetManaged) { return ( <>-- diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/overview/monitor_list/monitor_list.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/overview/monitor_list/monitor_list.tsx index 4ca114264fec..e0cc20d963a8 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/overview/monitor_list/monitor_list.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/overview/monitor_list/monitor_list.tsx @@ -212,7 +212,7 @@ export const MonitorListComponent: ({ ), },