Node Graph: Always show context menu (#56876)

* Ensure context menu always appears

* Close the context menu after selecting the alternative layout

Co-authored-by: Hamas Shafiq <hamas.shafiq@grafana.com>
This commit is contained in:
Joey Tawadrous 2022-10-24 09:14:42 +01:00 committed by GitHub
parent 73c215ae41
commit 52dbd67a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,17 +28,25 @@ export function useContextMenu(
const onNodeOpen = useCallback(
(event: MouseEvent<SVGElement>, node: NodeDatum) => {
const extraNodeItem = config.gridLayout
? [
{
label: 'Show in Graph layout',
onClick: (node: NodeDatum) => {
setFocusedNodeId(node.id);
setConfig({ ...config, gridLayout: false });
},
},
]
: undefined;
let label = 'Show in Grid layout';
let showGridLayout = true;
if (config.gridLayout) {
label = 'Show in Graph layout';
showGridLayout = false;
}
const extraNodeItem = [
{
label: label,
onClick: (node: NodeDatum) => {
setFocusedNodeId(node.id);
setConfig({ ...config, gridLayout: showGridLayout });
setMenu(undefined);
},
},
];
const renderer = getItemsRenderer(getLinks(nodes, node.dataFrameRowIndex), node, extraNodeItem);
if (renderer) {