From 3eca7864ed1c6ea433d4cc8c3d62beb9f15cb0d1 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Tue, 1 Jun 2021 02:43:49 -0400 Subject: [PATCH] NodeGraph: Fix error when clicking link in a context menu (#34817) (#34830) * Add prevent default if onClick exists * Apply field overrides (cherry picked from commit fcdab32750d435d0e125e9ae7f36e6f0661165e3) Co-authored-by: Andrej Ocenas --- .../src/components/Menu/MenuItem.tsx | 11 ++++++++- .../features/explore/NodeGraphContainer.tsx | 24 +++++++++++++++---- .../panel/nodeGraph/useContextMenu.tsx | 1 + 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/grafana-ui/src/components/Menu/MenuItem.tsx b/packages/grafana-ui/src/components/Menu/MenuItem.tsx index 2dec14c4901..130dab295d3 100644 --- a/packages/grafana-ui/src/components/Menu/MenuItem.tsx +++ b/packages/grafana-ui/src/components/Menu/MenuItem.tsx @@ -43,7 +43,16 @@ export const MenuItem: React.FC = React.memo( href={url ? url : undefined} target={target} className={styles.link} - onClick={onClick} + onClick={ + onClick + ? (event) => { + if (!(event.ctrlKey || event.metaKey || event.shiftKey) && onClick) { + event.preventDefault(); + onClick(event); + } + } + : undefined + } rel={target === '_blank' ? 'noopener noreferrer' : undefined} > {icon && } {label} diff --git a/public/app/features/explore/NodeGraphContainer.tsx b/public/app/features/explore/NodeGraphContainer.tsx index 24f576c976b..f54fca048a6 100644 --- a/public/app/features/explore/NodeGraphContainer.tsx +++ b/public/app/features/explore/NodeGraphContainer.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { useToggle } from 'react-use'; -import { Badge, Collapse, useStyles2 } from '@grafana/ui'; -import { DataFrame, GrafanaTheme2, TimeRange } from '@grafana/data'; +import { Badge, Collapse, useStyles2, useTheme2 } from '@grafana/ui'; +import { applyFieldOverrides, DataFrame, GrafanaTheme2, TimeRange } from '@grafana/data'; import { css } from '@emotion/css'; import { ExploreId, StoreState } from '../../types'; import { splitOpen } from './state/main'; @@ -30,10 +30,26 @@ interface Props { export function UnconnectedNodeGraphContainer(props: Props & ConnectedProps) { const { dataFrames, range, splitOpen, withTraceView } = props; const getLinks = useLinks(range, splitOpen); + const theme = useTheme2(); const styles = useStyles2(getStyles); - const { nodes } = useCategorizeFrames(dataFrames); + // This is implicit dependency that is needed for links to work. At some point when replacing variables in the link + // it requires field to have a display property which is added by the overrides even though we don't add any field + // overrides in explore. + const frames = applyFieldOverrides({ + fieldConfig: { + defaults: {}, + overrides: [], + }, + data: dataFrames, + // We don't need proper replace here as it is only used in getLinks and we use getFieldLinks + replaceVariables: (value) => value, + theme, + }); + + const { nodes } = useCategorizeFrames(frames); const [open, toggleOpen] = useToggle(false); + const countWarning = withTraceView && nodes[0]?.length > 1000 ? ( ({nodes[0].length} nodes, can be slow to load) @@ -53,7 +69,7 @@ export function UnconnectedNodeGraphContainer(props: Props & ConnectedProps toggleOpen() : undefined} >
- +
); diff --git a/public/app/plugins/panel/nodeGraph/useContextMenu.tsx b/public/app/plugins/panel/nodeGraph/useContextMenu.tsx index daf87c69e52..e14fd30b586 100644 --- a/public/app/plugins/panel/nodeGraph/useContextMenu.tsx +++ b/public/app/plugins/panel/nodeGraph/useContextMenu.tsx @@ -108,6 +108,7 @@ function mapMenuItem(item: T) { label={link.label} ariaLabel={link.ariaLabel || link.label} onClick={link.onClick ? () => link.onClick?.(item) : undefined} + target={'_self'} /> ); };