fix(editor): Allow pinning of AI root nodes (#9060)
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
@@ -1,20 +1,15 @@
|
||||
import type { XYPosition } from '@/Interface';
|
||||
import {
|
||||
NOT_DUPLICATABE_NODE_TYPES,
|
||||
PIN_DATA_NODE_TYPES_DENYLIST,
|
||||
STICKY_NODE_TYPE,
|
||||
} from '@/constants';
|
||||
import { NOT_DUPLICATABE_NODE_TYPES, STICKY_NODE_TYPE } from '@/constants';
|
||||
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||
import { useSourceControlStore } from '@/stores/sourceControl.store';
|
||||
import { useUIStore } from '@/stores/ui.store';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import type { IActionDropdownItem } from 'n8n-design-system/src/components/N8nActionDropdown/ActionDropdown.vue';
|
||||
import { NodeHelpers, NodeConnectionType } from 'n8n-workflow';
|
||||
import type { INode, INodeTypeDescription } from 'n8n-workflow';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { getMousePosition } from '../utils/nodeViewUtils';
|
||||
import { useI18n } from './useI18n';
|
||||
import { useDataSchema } from './useDataSchema';
|
||||
import { usePinnedData } from './usePinnedData';
|
||||
|
||||
export type ContextMenuTarget =
|
||||
| { source: 'canvas' }
|
||||
@@ -47,7 +42,7 @@ export const useContextMenu = (onAction: ContextMenuActionCallback = () => {}) =
|
||||
const nodeTypesStore = useNodeTypesStore();
|
||||
const workflowsStore = useWorkflowsStore();
|
||||
const sourceControlStore = useSourceControlStore();
|
||||
const { getInputDataWithPinned } = useDataSchema();
|
||||
|
||||
const i18n = useI18n();
|
||||
|
||||
const isReadOnly = computed(
|
||||
@@ -83,13 +78,6 @@ export const useContextMenu = (onAction: ContextMenuActionCallback = () => {}) =
|
||||
return canAddNodeOfType(nodeType);
|
||||
};
|
||||
|
||||
const canPinNode = (node: INode): boolean => {
|
||||
const nodeType = nodeTypesStore.getNodeType(node.type, node.typeVersion);
|
||||
const dataToPin = getInputDataWithPinned(node);
|
||||
if (!nodeType || dataToPin.length === 0) return false;
|
||||
return nodeType.outputs.length === 1 && !PIN_DATA_NODE_TYPES_DENYLIST.includes(node.type);
|
||||
};
|
||||
|
||||
const hasPinData = (node: INode): boolean => {
|
||||
return !!workflowsStore.pinDataByNodeName(node.name);
|
||||
};
|
||||
@@ -159,16 +147,6 @@ export const useContextMenu = (onAction: ContextMenuActionCallback = () => {}) =
|
||||
...selectionActions,
|
||||
];
|
||||
} else {
|
||||
const nonMainInputs = (node: INode) => {
|
||||
const workflow = workflowsStore.getCurrentWorkflow();
|
||||
const workflowNode = workflow.getNode(node.name);
|
||||
const nodeType = nodeTypesStore.getNodeType(node.type, node.typeVersion);
|
||||
const inputs = NodeHelpers.getNodeInputs(workflow, workflowNode!, nodeType!);
|
||||
const inputNames = NodeHelpers.getConnectionTypes(inputs);
|
||||
|
||||
return !!inputNames.find((inputName) => inputName !== NodeConnectionType.Main);
|
||||
};
|
||||
|
||||
const menuActions: IActionDropdownItem[] = [
|
||||
!onlyStickies && {
|
||||
id: 'toggle_activation',
|
||||
@@ -184,7 +162,7 @@ export const useContextMenu = (onAction: ContextMenuActionCallback = () => {}) =
|
||||
? i18n.baseText('contextMenu.unpin', i18nOptions)
|
||||
: i18n.baseText('contextMenu.pin', i18nOptions),
|
||||
shortcut: { keys: ['p'] },
|
||||
disabled: nodes.some(nonMainInputs) || isReadOnly.value || !nodes.every(canPinNode),
|
||||
disabled: isReadOnly.value || !nodes.every((n) => usePinnedData(n).canPinNode(true)),
|
||||
},
|
||||
{
|
||||
id: 'copy',
|
||||
|
||||
Reference in New Issue
Block a user