Skip to content

Commit

Permalink
[8.11] [Synthetics] Fix and refactor table row click actions for test…
Browse files Browse the repository at this point in the history
… runs table (#166915) (#169195)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[Synthetics] Fix and refactor table row click actions for test runs
table (#166915)](#166915)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2023-10-18T06:33:53Z","message":"[Synthetics]
Fix and refactor table row click actions for test runs table
(#166915)","sha":"1d2d6e4cc6ff9a1dcc523906995a1797dbfd5478","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:uptime","release_note:skip","v8.11.0","v8.12.0"],"number":166915,"url":"https://github.com/elastic/kibana/pull/166915","mergeCommit":{"message":"[Synthetics]
Fix and refactor table row click actions for test runs table
(#166915)","sha":"1d2d6e4cc6ff9a1dcc523906995a1797dbfd5478"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/166915","number":166915,"mergeCommit":{"message":"[Synthetics]
Fix and refactor table row click actions for test runs table
(#166915)","sha":"1d2d6e4cc6ff9a1dcc523906995a1797dbfd5478"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
  • Loading branch information
kibanamachine and shahzad31 authored Oct 18, 2023
1 parent 397fe2e commit 108a687
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 36 deletions.
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

0 comments on commit 108a687

Please sign in to comment.