Canvas: Support context menu in panel edit mode (#80335)

pull/80391/head
Nathan Marrs 1 year ago committed by GitHub
parent eb64209301
commit c40b2f90ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      public/app/features/canvas/runtime/scene.tsx
  2. 5
      public/app/plugins/panel/canvas/components/CanvasContextMenu.tsx

@ -665,34 +665,36 @@ export class Scene {
}; };
render() { render() {
const canShowContextMenu = this.isPanelEditing || (!this.isPanelEditing && this.isEditingEnabled);
const isTooltipValid = (this.tooltip?.element?.data?.links?.length ?? 0) > 0; const isTooltipValid = (this.tooltip?.element?.data?.links?.length ?? 0) > 0;
const canShowElementTooltip = !this.isEditingEnabled && isTooltipValid; 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 = ( const sceneDiv = (
// TODO: Address this eslint error // 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 // eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div <div
key={this.revId} key={this.revId}
className={this.styles.wrap} className={this.styles.wrap}
style={this.style} style={this.style}
ref={this.setRef} ref={this.setRef}
onMouseDown={(e) => { onMouseDown={onSceneContainerMouseDown}
// If pan and zoom is disabled and middle mouse or ctrl + right mouse, 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 && e.button === 2 && !e.ctrlKey) {
e.preventDefault();
e.stopPropagation();
}
}}
> >
{this.connections.render()} {this.connections.render()}
{this.root.render()} {this.root.render()}
{canShowContextMenu && ( {this.isEditingEnabled && (
<Portal> <Portal>
<CanvasContextMenu <CanvasContextMenu
scene={this} scene={this}

@ -71,6 +71,7 @@ export const CanvasContextMenu = ({ scene, panel, onVisibilityChange }: Props) =
}; };
const renderMenuItems = () => { const renderMenuItems = () => {
// This is disabled when panel is in edit mode because opening inline editor over panel editor is not ideal UX
const openCloseEditorMenuItem = !scene.isPanelEditing && ( const openCloseEditorMenuItem = !scene.isPanelEditing && (
<MenuItem <MenuItem
label={inlineEditorOpen ? 'Close Editor' : 'Open Editor'} label={inlineEditorOpen ? 'Close Editor' : 'Open Editor'}
@ -139,7 +140,7 @@ export const CanvasContextMenu = ({ scene, panel, onVisibilityChange }: Props) =
return submenuItems; return submenuItems;
}; };
const addItemMenuItem = !scene.isPanelEditing && ( const addItemMenuItem = (
<MenuItem <MenuItem
label="Add item" label="Add item"
className={styles.menuItem} className={styles.menuItem}
@ -148,7 +149,7 @@ export const CanvasContextMenu = ({ scene, panel, onVisibilityChange }: Props) =
/> />
); );
const setBackgroundMenuItem = !scene.isPanelEditing && ( const setBackgroundMenuItem = (
<MenuItem <MenuItem
label={'Set background'} label={'Set background'}
onClick={() => { onClick={() => {

Loading…
Cancel
Save