From 99bbf33045d1da9953f3cd3633e52ed90093e8e5 Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Thu, 23 Nov 2023 12:07:41 +0100 Subject: [PATCH 1/2] Disable context menu actions in read-only mode --- .../components/ContextMenu/ContextMenu.vue | 25 ++- packages/editor-ui/src/components/Sticky.vue | 22 +- .../__snapshots__/useContextMenu.test.ts.snap | 189 +++++++++++++++++- .../__tests__/useContextMenu.test.ts | 33 +++ .../src/composables/useContextMenu.ts | 20 +- .../src/plugins/i18n/locales/en.json | 3 +- 6 files changed, 268 insertions(+), 24 deletions(-) diff --git a/packages/editor-ui/src/components/ContextMenu/ContextMenu.vue b/packages/editor-ui/src/components/ContextMenu/ContextMenu.vue index c6b195f136183..d5692726ef4fc 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(item as ContextMenuAction); + emit('action', action, contextMenu.targetNodes.value); } function onVisibleChange(open: boolean) { if (!open) { - close(); + contextMenu.close(); } }