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:
@@ -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 { selectors } from '@grafana/e2e-selectors';
|
||||||
import { useClickAway } from 'react-use';
|
import { useClickAway } from 'react-use';
|
||||||
import { Portal } from '../Portal/Portal';
|
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();
|
const header = renderHeader && renderHeader();
|
||||||
return (
|
return (
|
||||||
<Portal>
|
<Portal>
|
||||||
@@ -61,6 +55,7 @@ export const ContextMenu: React.FC<ContextMenuProps> = React.memo(({ x, y, onClo
|
|||||||
ref={menuRef}
|
ref={menuRef}
|
||||||
style={positionStyles}
|
style={positionStyles}
|
||||||
ariaLabel={selectors.components.Menu.MenuComponent('Context')}
|
ariaLabel={selectors.components.Menu.MenuComponent('Context')}
|
||||||
|
onClick={onClose}
|
||||||
>
|
>
|
||||||
{itemsGroup?.map((group, index) => (
|
{itemsGroup?.map((group, index) => (
|
||||||
<MenuGroup key={`${group.label}${index}`} label={group.label} ariaLabel={group.label}>
|
<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}
|
target={item.target}
|
||||||
icon={item.icon}
|
icon={item.icon}
|
||||||
active={item.active}
|
active={item.active}
|
||||||
onClick={onClick}
|
onClick={item.onClick}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</MenuGroup>
|
</MenuGroup>
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ export class LinkSrv implements LinkService {
|
|||||||
const info: LinkModel<T> = {
|
const info: LinkModel<T> = {
|
||||||
href: locationUtil.assureBaseUrl(href.replace(/\n/g, '')),
|
href: locationUtil.assureBaseUrl(href.replace(/\n/g, '')),
|
||||||
title: replaceVariables ? replaceVariables(link.title || '') : link.title,
|
title: replaceVariables ? replaceVariables(link.title || '') : link.title,
|
||||||
target: link.targetBlank ? '_blank' : '_self',
|
target: link.targetBlank ? '_blank' : undefined,
|
||||||
origin,
|
origin,
|
||||||
onClick,
|
onClick,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user