NodeGraph: Fix overlaps preventing opening an edge context menu when nodes were too close (#68571)

This commit is contained in:
Andrej Ocenas 2023-05-17 15:22:21 +02:00 committed by GitHub
parent 71e7ec1c83
commit 14936f85df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 18 deletions

View File

@ -32,6 +32,7 @@ const getStyles = (theme: GrafanaTheme2, hovering: HoverState) => ({
text: css`
fill: ${theme.colors.text.primary};
pointer-events: none;
`,
titleText: css`
@ -57,6 +58,12 @@ const getStyles = (theme: GrafanaTheme2, hovering: HoverState) => ({
background-color: ${tinycolor(theme.colors.background.primary).setAlpha(0.8).toHex8String()};
}
`,
clickTarget: css`
fill: none;
stroke: none;
pointer-events: fill;
`,
});
export const Node = memo(function Node(props: {
@ -76,24 +83,11 @@ export const Node = memo(function Node(props: {
}
return (
<g
data-node-id={node.id}
className={styles.mainGroup}
onMouseEnter={() => {
onMouseEnter(node.id);
}}
onMouseLeave={() => {
onMouseLeave(node.id);
}}
onClick={(event) => {
onClick(event, node);
}}
aria-label={`Node: ${node.title}`}
>
<g data-node-id={node.id} className={styles.mainGroup} aria-label={`Node: ${node.title}`}>
<circle className={styles.mainCircle} r={nodeR} cx={node.x} cy={node.y} />
{isHovered && <circle className={styles.hoverCircle} r={nodeR - 3} cx={node.x} cy={node.y} strokeWidth={2} />}
<ColorCircle node={node} />
<g className={styles.text}>
<g className={styles.text} style={{ pointerEvents: 'none' }}>
<NodeContents node={node} hovering={hovering} />
<foreignObject
x={node.x - (isHovered ? 100 : 50)}
@ -108,6 +102,23 @@ export const Node = memo(function Node(props: {
</div>
</foreignObject>
</g>
<rect
data-testid={`node-click-rect-${node.id}`}
onMouseEnter={() => {
onMouseEnter(node.id);
}}
onMouseLeave={() => {
onMouseLeave(node.id);
}}
onClick={(event) => {
onClick(event, node);
}}
className={styles.clickTarget}
x={node.x - nodeR - 5}
y={node.y - nodeR - 5}
width={nodeR * 2 + 10}
height={nodeR * 2 + 50}
/>
</g>
);
});

View File

@ -89,7 +89,7 @@ describe('NodeGraph', () => {
const origError = console.error;
console.error = jest.fn();
const node = await screen.findByLabelText(/Node: service:0/);
const node = await screen.findByTestId('node-click-rect-0');
await userEvent.click(node);
await screen.findByText(/Node traces/);

View File

@ -232,12 +232,12 @@ function EdgeHeader(props: { edge: EdgeDatum; edges: DataFrame }) {
const rows = [];
if (valueSource && valueTarget) {
rows.push(<HeaderRow label={'Source → Target'} value={`${valueSource}${valueTarget}`} />);
rows.push(<HeaderRow key={'header-row'} label={'Source → Target'} value={`${valueSource}${valueTarget}`} />);
}
for (const f of [fields.mainStat, fields.secondaryStat, ...fields.details]) {
if (f && f.values[index]) {
rows.push(<FieldRow field={f} index={index} />);
rows.push(<FieldRow key={`field-row-${index}`} field={f} index={index} />);
}
}