mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
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.
This commit is contained in:
parent
d0def9eef1
commit
1eb059de11
3 changed files with 68 additions and 55 deletions
|
@ -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 && (
|
||||
<EuiFlexItem grow={false}>
|
||||
{/* Popover is used instead of EuiTooltip until the resolution of https://github.com/elastic/eui/issues/5604 */}
|
||||
<EuiPopover
|
||||
repositionOnScroll={true}
|
||||
ownFocus={false}
|
||||
initialFocus={''}
|
||||
button={
|
||||
<EuiButton
|
||||
css={{ width: '100%' }}
|
||||
fill
|
||||
size="s"
|
||||
color="success"
|
||||
iconType="play"
|
||||
disabled={!isValid || isTestRunInProgress || !hasServiceManagedLocation}
|
||||
data-test-subj={'monitorTestNowRunBtn'}
|
||||
onClick={() => 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}
|
||||
</EuiButton>
|
||||
}
|
||||
isOpen={isPopoverOpen}
|
||||
<EuiOutsideClickDetector
|
||||
onOutsideClick={() => {
|
||||
setIsPopoverOpen(false);
|
||||
}}
|
||||
>
|
||||
<EuiText style={{ width: 260, outline: 'none' }}>
|
||||
<p>
|
||||
{isTestRunInProgress
|
||||
? TEST_SCHEDULED_LABEL
|
||||
: isOnlyPrivateLocations || (isValid && !hasServiceManagedLocation)
|
||||
? PRIVATE_AVAILABLE_LABEL
|
||||
: TEST_NOW_DESCRIPTION}
|
||||
</p>
|
||||
</EuiText>
|
||||
</EuiPopover>
|
||||
<EuiPopover
|
||||
repositionOnScroll={true}
|
||||
ownFocus={false}
|
||||
initialFocus={''}
|
||||
button={
|
||||
<EuiButton
|
||||
css={{ width: '100%' }}
|
||||
fill
|
||||
size="s"
|
||||
color="success"
|
||||
iconType="play"
|
||||
disabled={!isValid || isTestRunInProgress || !isAnyPublicLocationSelected}
|
||||
data-test-subj={'monitorTestNowRunBtn'}
|
||||
onClick={() => 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}
|
||||
</EuiButton>
|
||||
}
|
||||
isOpen={isPopoverOpen}
|
||||
>
|
||||
<EuiText style={{ width: 260, outline: 'none' }}>
|
||||
<p>
|
||||
{isTestRunInProgress
|
||||
? TEST_SCHEDULED_LABEL
|
||||
: isOnlyPrivateLocations || (isValid && !isAnyPublicLocationSelected)
|
||||
? PRIVATE_AVAILABLE_LABEL
|
||||
: TEST_NOW_DESCRIPTION}
|
||||
</p>
|
||||
</EuiText>
|
||||
</EuiPopover>
|
||||
</EuiOutsideClickDetector>
|
||||
</EuiFlexItem>
|
||||
)}
|
||||
|
||||
|
|
|
@ -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 (
|
||||
<EuiToolTip content={labels.PRIVATE_AVAILABLE_LABEL}>
|
||||
<>--</>
|
||||
|
|
|
@ -212,7 +212,7 @@ export const MonitorListComponent: ({
|
|||
<TestNowColumn
|
||||
monitorId={item.monitor_id}
|
||||
configId={item.configId}
|
||||
selectedMonitor={item.state.summaryPings[0]}
|
||||
summaryPings={item.state.summaryPings}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue