From 82e9d59121a6d2e8e2ed684e7174ea12fe5bdbfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 12 Mar 2021 07:25:14 +0100 Subject: [PATCH] GraphContextMenu: Fixes add annotation action & data links that cause full page reload (#31915) * GraphContextMenu: Fixes add annotation action * Fixed issue with data links causing full page reload * A better solution to closing context menu --- .../src/components/ContextMenu/ContextMenu.tsx | 11 +++-------- public/app/features/panel/panellinks/link_srv.ts | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/grafana-ui/src/components/ContextMenu/ContextMenu.tsx b/packages/grafana-ui/src/components/ContextMenu/ContextMenu.tsx index d448e9c8efd..cc106c22ad0 100644 --- a/packages/grafana-ui/src/components/ContextMenu/ContextMenu.tsx +++ b/packages/grafana-ui/src/components/ContextMenu/ContextMenu.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useState, useLayoutEffect, useCallback } from 'react'; +import React, { useRef, useState, useLayoutEffect } from 'react'; import { selectors } from '@grafana/e2e-selectors'; import { useClickAway } from 'react-use'; import { Portal } from '../Portal/Portal'; @@ -47,12 +47,6 @@ export const ContextMenu: React.FC = React.memo(({ x, y, onClo } }); - const onClick = useCallback(() => { - if (onClose) { - onClose(); - } - }, [onClose]); - const header = renderHeader && renderHeader(); return ( @@ -61,6 +55,7 @@ export const ContextMenu: React.FC = React.memo(({ x, y, onClo ref={menuRef} style={positionStyles} ariaLabel={selectors.components.Menu.MenuComponent('Context')} + onClick={onClose} > {itemsGroup?.map((group, index) => ( @@ -73,7 +68,7 @@ export const ContextMenu: React.FC = React.memo(({ x, y, onClo target={item.target} icon={item.icon} active={item.active} - onClick={onClick} + onClick={item.onClick} /> ))} diff --git a/public/app/features/panel/panellinks/link_srv.ts b/public/app/features/panel/panellinks/link_srv.ts index 7b4d94430bb..5541e9b2542 100644 --- a/public/app/features/panel/panellinks/link_srv.ts +++ b/public/app/features/panel/panellinks/link_srv.ts @@ -324,7 +324,7 @@ export class LinkSrv implements LinkService { const info: LinkModel = { href: locationUtil.assureBaseUrl(href.replace(/\n/g, '')), title: replaceVariables ? replaceVariables(link.title || '') : link.title, - target: link.targetBlank ? '_blank' : '_self', + target: link.targetBlank ? '_blank' : undefined, origin, onClick, };