From 902beffce51d547094ea249d1fbbb70a879165d6 Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Thu, 23 Nov 2023 17:10:45 +0100 Subject: [PATCH] fix(editor): Disable context menu actions in read-only mode (#7789) Github issue / Community forum post (link here to close automatically): --- .../components/ContextMenu/ContextMenu.vue | 25 +- packages/editor-ui/src/components/Sticky.vue | 22 +- .../__snapshots__/useContextMenu.test.ts.snap | 375 +++++++++++++----- .../__tests__/useContextMenu.test.ts | 33 ++ .../src/composables/useContextMenu.ts | 20 +- .../src/plugins/i18n/locales/en.json | 3 +- 6 files changed, 361 insertions(+), 117 deletions(-) diff --git a/packages/editor-ui/src/components/ContextMenu/ContextMenu.vue b/packages/editor-ui/src/components/ContextMenu/ContextMenu.vue index c6b195f136..1113468ffe 100644 --- a/packages/editor-ui/src/components/ContextMenu/ContextMenu.vue +++ b/packages/editor-ui/src/components/ContextMenu/ContextMenu.vue @@ -4,38 +4,47 @@ import { N8nActionDropdown } from 'n8n-design-system'; import type { INode } from 'n8n-workflow'; import { watch, ref } from 'vue'; -const { isOpen, actions, position, targetNodes, target, close } = useContextMenu(); -const contextMenu = ref>(); +const contextMenu = useContextMenu(); +const { position, isOpen, actions, target } = contextMenu; +const dropdown = ref>(); const emit = defineEmits<{ (event: 'action', action: ContextMenuAction, nodes: INode[]): void }>(); watch( isOpen, () => { if (isOpen) { - contextMenu.value?.open(); + dropdown.value?.open(); } else { - contextMenu.value?.close(); + dropdown.value?.close(); } }, { flush: 'post' }, ); function onActionSelect(item: string) { - emit('action', item as ContextMenuAction, targetNodes.value); + const action = item as ContextMenuAction; + contextMenu._dispatchAction(action); + emit('action', action, contextMenu.targetNodes.value); } function onVisibleChange(open: boolean) { if (!open) { - close(); + contextMenu.close(); } }