mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Canvas: Pan zoom minor refactor (#80337)
* enable context menu for canvas while in panel edit mode * Disable context menu when editing is not enabled in canvas * follow up minor refactor
This commit is contained in:
parent
18b9c8fd5f
commit
8784052ccf
@ -19,6 +19,20 @@ export const SceneTransformWrapper = ({ scene, children: sceneDiv }: SceneTransf
|
||||
scene.scale = scale;
|
||||
};
|
||||
|
||||
const onSceneContainerMouseDown = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
|
||||
// If pan and zoom is disabled or context menu is visible, don't pan
|
||||
if ((!scene.shouldPanZoom || scene.contextMenuVisible) && (e.button === 1 || (e.button === 2 && e.ctrlKey))) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
// If context menu is hidden, ignore left mouse or non-ctrl right mouse for pan
|
||||
if (!scene.contextMenuVisible && !scene.isPanelEditing && e.button === 2 && !e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<TransformWrapper
|
||||
doubleClick={{ mode: 'reset' }}
|
||||
@ -31,7 +45,11 @@ export const SceneTransformWrapper = ({ scene, children: sceneDiv }: SceneTransf
|
||||
disabled={!config.featureToggles.canvasPanelPanZoom || !scene.shouldPanZoom}
|
||||
panning={{ allowLeftClickPan: false }}
|
||||
>
|
||||
<TransformComponent>{sceneDiv}</TransformComponent>
|
||||
<TransformComponent>
|
||||
{/* The <div> element has child elements that allow for mouse events, so we need to disable the linter rule */}
|
||||
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
|
||||
<div onMouseDown={onSceneContainerMouseDown}>{sceneDiv}</div>
|
||||
</TransformComponent>
|
||||
</TransformWrapper>
|
||||
);
|
||||
};
|
||||
|
@ -668,30 +668,8 @@ export class Scene {
|
||||
const isTooltipValid = (this.tooltip?.element?.data?.links?.length ?? 0) > 0;
|
||||
const canShowElementTooltip = !this.isEditingEnabled && isTooltipValid;
|
||||
|
||||
const onSceneContainerMouseDown = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
|
||||
// If pan and zoom is disabled or context menu is visible, don't pan
|
||||
if ((!this.shouldPanZoom || this.contextMenuVisible) && (e.button === 1 || (e.button === 2 && e.ctrlKey))) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
// If context menu is hidden, ignore left mouse or non-ctrl right mouse for pan
|
||||
if (!this.contextMenuVisible && !this.isPanelEditing && e.button === 2 && !e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
||||
const sceneDiv = (
|
||||
// The <div> element has child elements that allow for mouse events, so we need to disable the linter rule
|
||||
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
||||
<div
|
||||
key={this.revId}
|
||||
className={this.styles.wrap}
|
||||
style={this.style}
|
||||
ref={this.setRef}
|
||||
onMouseDown={onSceneContainerMouseDown}
|
||||
>
|
||||
<div key={this.revId} className={this.styles.wrap} style={this.style} ref={this.setRef}>
|
||||
{this.connections.render()}
|
||||
{this.root.render()}
|
||||
{this.isEditingEnabled && (
|
||||
|
Loading…
Reference in New Issue
Block a user