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
This commit is contained in:
Torkel Ödegaard 2021-03-12 07:25:14 +01:00 committed by GitHub
parent 34105a6db8
commit 82e9d59121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 9 deletions

View File

@ -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<ContextMenuProps> = React.memo(({ x, y, onClo
}
});
const onClick = useCallback(() => {
if (onClose) {
onClose();
}
}, [onClose]);
const header = renderHeader && renderHeader();
return (
<Portal>
@ -61,6 +55,7 @@ export const ContextMenu: React.FC<ContextMenuProps> = React.memo(({ x, y, onClo
ref={menuRef}
style={positionStyles}
ariaLabel={selectors.components.Menu.MenuComponent('Context')}
onClick={onClose}
>
{itemsGroup?.map((group, index) => (
<MenuGroup key={`${group.label}${index}`} label={group.label} ariaLabel={group.label}>
@ -73,7 +68,7 @@ export const ContextMenu: React.FC<ContextMenuProps> = React.memo(({ x, y, onClo
target={item.target}
icon={item.icon}
active={item.active}
onClick={onClick}
onClick={item.onClick}
/>
))}
</MenuGroup>

View File

@ -324,7 +324,7 @@ export class LinkSrv implements LinkService {
const info: LinkModel<T> = {
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,
};