Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.11] [Synthetics] Fix and refactor table row click actions for test runs table (#166915) #169195

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { EuiButtonIcon, EuiFlyout, EuiFlyoutBody, EuiFlyoutHeader, EuiTitle } from '@elastic/eui';
import React, { useState } from 'react';
import React, { useState, MouseEvent } from 'react';
import { useUnifiedDocViewerServices } from '@kbn/unified-doc-viewer-plugin/public';
import { buildDataTableRecord } from '@kbn/discover-utils';
import { UnifiedDocViewer } from '@kbn/unified-doc-viewer-plugin/public';
Expand Down Expand Up @@ -56,12 +56,20 @@ export const ViewDocument = ({ ping }: { ping: Ping }) => {
data-test-subj="syntheticsViewDocumentButton"
iconType="inspect"
title={INSPECT_DOCUMENT}
onClick={() => {
onClick={(evt: MouseEvent<HTMLButtonElement>) => {
evt.stopPropagation();
setIsFlyoutVisible(true);
}}
/>
{isFlyoutVisible && (
<EuiFlyout onClose={() => setIsFlyoutVisible(false)} ownFocus={true}>
<EuiFlyout
onClose={() => setIsFlyoutVisible(false)}
ownFocus={true}
onClick={(evt: MouseEvent) => {
// needed to prevent propagation to the table row click
evt.stopPropagation();
}}
>
<EuiFlyoutHeader>
<EuiTitle size="m">
<h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export const JourneyScreenshotPreview: React.FC<StepImagePopoverProps> = ({
);

const onImgClick = useCallback(
(_evt: MouseEvent<HTMLImageElement>) => {
(evt: MouseEvent<HTMLImageElement>) => {
// needed to prevent propagation to the table row click
evt.stopPropagation();
setIsImageEverClicked(true);
setIsImageDialogOpen(true);
setIsImagePopoverOpen(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const EmptyThumbnail = ({
const noDataMessage = unavailableMessage ?? SCREENSHOT_NOT_AVAILABLE;

return (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<div
data-test-subj="stepScreenshotPlaceholder"
role="img"
Expand All @@ -62,6 +63,15 @@ export const EmptyThumbnail = ({
border: euiTheme.border.thin,
...(borderRadius ? { borderRadius } : {}),
}}
onClick={(e) => {
// We don't want the placeholder to be clickable
e.stopPropagation();
e.preventDefault();
}}
onKeyDown={(e) => {
// We don't want the placeholder to be clickable
e.stopPropagation();
}}
>
{isLoading && animateLoading ? (
<EuiSkeletonRectangle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const JourneyScreenshotDialog = ({
<EuiOutsideClickDetector onOutsideClick={onClose}>
<EuiModal
onClose={(evt?: KeyboardEvent<HTMLDivElement> | MouseEvent<HTMLButtonElement>) => {
// for table row click to work
evt?.stopPropagation?.();
onClose();
}}
Expand All @@ -127,6 +128,10 @@ export const JourneyScreenshotDialog = ({
animateLoading={false}
hasBorder={false}
size={'full'}
onClick={(evt) => {
// for table row click to work
evt.stopPropagation();
}}
/>
</ModalBodyStyled>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const TestRunsTable = ({
name: MESSAGE_LABEL,
textOnly: true,
css: css`
max-width: 600px;
max-width: 500px;
`,
render: (errorMessage: string) => (
<EuiText size="s">{errorMessage?.length > 0 ? errorMessage : '-'}</EuiText>
Expand Down Expand Up @@ -269,31 +269,16 @@ export const TestRunsTable = ({
return {
'data-test-subj': `row-${item.monitor.check_group}`,
onClick: (evt: MouseEvent) => {
const targetElem = evt.target as HTMLElement;
const isTableRow =
targetElem.parentElement?.classList.contains('euiTableCellContent') ||
targetElem.parentElement?.classList.contains('euiTableCellContent__text') ||
targetElem?.classList.contains('euiTableCellContent') ||
targetElem?.classList.contains('euiBadge__text');
// we dont want to capture image click event
if (
isTableRow &&
targetElem.tagName !== 'IMG' &&
targetElem.tagName !== 'path' &&
targetElem.tagName !== 'BUTTON' &&
!targetElem.parentElement?.classList.contains('euiLink')
) {
if (item.monitor.type !== MONITOR_TYPES.BROWSER) {
toggleDetails(item, expandedRows, setExpandedRows);
} else {
history.push(
getTestRunDetailRelativeLink({
monitorId,
checkGroup: item.monitor.check_group,
locationId: selectedLocation?.id,
})
);
}
if (item.monitor.type !== MONITOR_TYPES.BROWSER) {
toggleDetails(item, expandedRows, setExpandedRows);
} else {
history.push(
getTestRunDetailRelativeLink({
monitorId,
checkGroup: item.monitor.check_group,
locationId: selectedLocation?.id,
})
);
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
* 2.0.
*/

import React from 'react';
import React, { Dispatch, SetStateAction, MouseEvent } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiButtonIcon } from '@elastic/eui';
import { Ping } from '../../../../../../../../common/runtime_types';
import { PingListExpandedRowComponent } from '../expanded_row';
type PingExpandedRowMap = Record<string, JSX.Element>;

export const toggleDetails = (
ping: Ping,
expandedRows: Record<string, JSX.Element>,
setExpandedRows: (update: Record<string, JSX.Element>) => any
expandedRows: PingExpandedRowMap,
setExpandedRows: Dispatch<SetStateAction<PingExpandedRowMap>>
) => {
// prevent expanding on row click if not expandable
if (!rowShouldExpand(ping)) {
Expand Down Expand Up @@ -48,14 +49,18 @@ export function rowShouldExpand(item: Ping) {

interface Props {
item: Ping;
expandedRows: Record<string, JSX.Element>;
setExpandedRows: (val: Record<string, JSX.Element>) => void;
expandedRows: PingExpandedRowMap;
setExpandedRows: Dispatch<SetStateAction<PingExpandedRowMap>>;
}
export const ExpandRowColumn = ({ item, expandedRows, setExpandedRows }: Props) => {
return (
<EuiButtonIcon
data-test-subj="uptimePingListExpandBtn"
onClick={() => toggleDetails(item, expandedRows, setExpandedRows)}
onClick={(evt: MouseEvent<HTMLButtonElement>) => {
// for table row click
evt.stopPropagation();
toggleDetails(item, expandedRows, setExpandedRows);
}}
isDisabled={!rowShouldExpand(item)}
aria-label={
expandedRows[item.docId]
Expand Down