Skip to content

Commit

Permalink
fix: prevent parent onclick event trigger
Browse files Browse the repository at this point in the history
Signed-off-by: eugenejahn <[email protected]>
  • Loading branch information
eugenejahn committed Apr 30, 2022
1 parent 542307b commit d205f79
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ExpandableExecutionError } from './ExpandableExecutionError';
import { NodeExecutionChildren } from './NodeExecutionChildren';
import { RowExpander } from './RowExpander';
import { selectedClassName, useExecutionTableStyles } from './styles';
import { calculateNodeExecutionRowLeftSpacing, selectExecution } from './utils';
import { calculateNodeExecutionRowLeftSpacing } from './utils';

interface NodeExecutionRowProps {
abortMetadata?: Admin.IAbortMetadata;
Expand All @@ -35,7 +35,11 @@ const ChildFetchErrorIcon: React.FC<{
disableTouchRipple={true}
size="small"
title={titleStrings.childGroupFetchFailed}
onClick={() => query.refetch()}
onClick={(e: React.MouseEvent<HTMLElement>) => {
// prevent the parent row body onClick event trigger
e.stopPropagation();
query.refetch();
}}
>
<ErrorOutline />
</IconButton>
Expand Down Expand Up @@ -102,7 +106,9 @@ export const NodeExecutionRow: React.FC<NodeExecutionRowProps> = ({
</div>
) : null;

const onClick = () => selectExecution(state, nodeExecution);
// open the side panel for selected execution's detail
// use null in case if there is no execution provided - when it is null, will close side panel
const onClickRow = () => state.setSelectedExecution(nodeExecution?.id ?? null);

return (
<div
Expand All @@ -111,7 +117,7 @@ export const NodeExecutionRow: React.FC<NodeExecutionRowProps> = ({
[selectedClassName]: selected,
})}
style={style}
onClick={onClick}
onClick={onClickRow}
>
<div
className={classnames(tableStyles.rowContent, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export const RowExpander: React.FC<{
disableTouchRipple={true}
size="small"
title={titleStrings.expandRow}
onClick={onClick}
onClick={(e: React.MouseEvent<HTMLElement>) => {
// prevent the parent row body onClick event trigger
e.stopPropagation();
onClick();
}}
>
{expanded ? <ExpandMore /> : <ChevronRight />}
</IconButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Link } from '@material-ui/core';
import { NodeExecution } from 'models/Execution/types';
import * as React from 'react';
import { NodeExecutionsTableState } from './types';
import { selectExecution } from './utils';

/** Renders a link that, when clicked, will trigger selection of the
* given NodeExecution.
Expand All @@ -13,7 +12,13 @@ export const SelectNodeExecutionLink: React.FC<{
linkText: string;
state: NodeExecutionsTableState;
}> = ({ className, execution, linkText, state }) => {
const onClick = () => selectExecution(state, execution);
// open the side panel for selected execution's detail
const onClick = (e: React.MouseEvent<HTMLElement>) => {
// prevent the parent row body onClick event trigger
e.stopPropagation();
// use null in case if there is no execution provided - when it is null will close panel
state.setSelectedExecution(execution?.id ?? null);
};

return (
<Link component="button" className={className} onClick={onClick} variant="body1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ import { nameColumnLeftMarginGridWidth } from './styles';
export function calculateNodeExecutionRowLeftSpacing(level: number, spacing: Spacing) {
return spacing(nameColumnLeftMarginGridWidth + 3 * level);
}

export function selectExecution(state, nodeExecution) {
// use null in case if there is no execution provied - to close panel
state.setSelectedExecution(nodeExecution?.id ?? null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,20 @@ export const ExpandableMonospaceText: React.FC<ExpandableMonospaceTextProps> = (
}) => {
const [expanded, setExpanded] = React.useState(initialExpansionState);
const styles = useExpandableMonospaceTextStyles();
const onClickExpand = () => {
const onClickExpand = (e: React.MouseEvent<HTMLElement>) => {
// prevent the parent row body onClick event trigger
e.stopPropagation();

setExpanded(!expanded);
if (onExpandCollapse) {
onExpandCollapse(!expanded);
}
};
const onClickCopy = () => copyToClipboard(text);
const onClickCopy = (e: React.MouseEvent<HTMLElement>) => {
// prevent the parent row body onClick event trigger
e.stopPropagation();
copyToClipboard(text);
};

const expandButtonText = expanded ? 'Collapse' : 'Click to expand inline';

Expand Down

0 comments on commit d205f79

Please sign in to comment.