refactor: Use NodeConnectionType consistently across the code base (no-changelog) (#10595)

This commit is contained in:
Ricardo Espinoza
2024-08-29 09:55:53 -04:00
committed by GitHub
parent 1491cbd228
commit c4eb3746d7
521 changed files with 2259 additions and 1999 deletions

View File

@@ -6,7 +6,7 @@ import { createPinia, setActivePinia } from 'pinia';
import { useSourceControlStore } from '@/stores/sourceControl.store';
import { useUIStore } from '@/stores/ui.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { NodeHelpers } from 'n8n-workflow';
import { NodeConnectionType, NodeHelpers } from 'n8n-workflow';
const nodeFactory = (data: Partial<INodeUi> = {}): INodeUi => ({
id: faker.string.uuid(),
@@ -95,7 +95,10 @@ describe('useContextMenu', () => {
const { open, isOpen, actions, targetNodeIds } = useContextMenu();
const basicChain = nodeFactory({ type: BASIC_CHAIN_NODE_TYPE });
vi.spyOn(workflowsStore, 'getNodeById').mockReturnValue(basicChain);
vi.spyOn(NodeHelpers, 'getConnectionTypes').mockReturnValue(['main', 'ai_languageModel']);
vi.spyOn(NodeHelpers, 'getConnectionTypes').mockReturnValue([
NodeConnectionType.Main,
NodeConnectionType.AiLanguageModel,
]);
open(mockEvent, { source: 'node-right-click', nodeId: basicChain.id });
expect(isOpen.value).toBe(true);

View File

@@ -1,7 +1,12 @@
import { createPinia, setActivePinia } from 'pinia';
import { mock, mockClear } from 'vitest-mock-extended';
import type { BrowserJsPlumbInstance } from '@jsplumb/browser-ui';
import type { INode, INodeTypeDescription, Workflow } from 'n8n-workflow';
import {
NodeConnectionType,
type INode,
type INodeTypeDescription,
type Workflow,
} from 'n8n-workflow';
import { useNodeBase } from '@/composables/useNodeBase';
import { useWorkflowsStore } from '@/stores/workflows.store';
@@ -16,8 +21,8 @@ describe('useNodeBase', () => {
const jsPlumbInstance = mock<BrowserJsPlumbInstance>();
const nodeTypeDescription = mock<INodeTypeDescription>({
inputs: ['main'],
outputs: ['main'],
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
});
const workflowObject = mock<Workflow>();
const node = mock<INode>();

View File

@@ -68,7 +68,6 @@ import * as NodeViewUtils from '@/utils/nodeViewUtils';
import { isValidNodeConnectionType } from '@/utils/typeGuards';
import type { Connection } from '@vue-flow/core';
import type {
ConnectionTypes,
IConnection,
IConnections,
INode,
@@ -905,7 +904,7 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
}
}
let outputs: Array<ConnectionTypes | INodeOutputConfiguration> = [];
let outputs: Array<NodeConnectionType | INodeOutputConfiguration> = [];
try {
// It fails when the outputs are an expression. As those nodes have
// normally no outputs by default and the only reason we need the
@@ -1154,7 +1153,7 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
return false;
}
let inputs: Array<ConnectionTypes | INodeInputConfiguration> = [];
let inputs: Array<NodeConnectionType | INodeInputConfiguration> = [];
if (targetNodeType) {
inputs =
NodeHelpers.getNodeInputs(editableWorkflowObject.value, workflowNode, targetNodeType) ||

View File

@@ -10,7 +10,6 @@ import {
import { NodeHelpers, NodeConnectionType } from 'n8n-workflow';
import type {
ConnectionTypes,
INodeInputConfiguration,
INodeTypeDescription,
INodeOutputConfiguration,
@@ -57,8 +56,8 @@ export function useNodeBase({
const nodeId = computed<string>(() => data.value?.id ?? '');
const inputs = ref<Array<ConnectionTypes | INodeInputConfiguration>>([]);
const outputs = ref<Array<ConnectionTypes | INodeOutputConfiguration>>([]);
const inputs = ref<Array<NodeConnectionType | INodeInputConfiguration>>([]);
const outputs = ref<Array<NodeConnectionType | INodeOutputConfiguration>>([]);
const createAddInputEndpointSpec = (
connectionName: NodeConnectionType,
@@ -139,7 +138,7 @@ export function useNodeBase({
inputConfiguration = value;
}
const inputName: ConnectionTypes = inputConfiguration.type;
const inputName: NodeConnectionType = inputConfiguration.type;
const rootCategoryInputName =
inputName === NodeConnectionType.Main ? NodeConnectionType.Main : 'other';
@@ -366,7 +365,7 @@ export function useNodeBase({
outputs.value.forEach((_value, i) => {
const outputConfiguration = outputConfigurations[i];
const outputName: ConnectionTypes = outputConfiguration.type;
const outputName: NodeConnectionType = outputConfiguration.type;
const rootCategoryOutputName =
outputName === NodeConnectionType.Main ? NodeConnectionType.Main : 'other';
@@ -536,12 +535,12 @@ export function useNodeBase({
addOutputEndpoints(node, nodeTypeData);
}
function getEndpointColor(connectionType: ConnectionTypes) {
function getEndpointColor(connectionType: NodeConnectionType) {
return `--node-type-${connectionType}-color`;
}
function getInputConnectionStyle(
connectionType: ConnectionTypes,
connectionType: NodeConnectionType,
nodeTypeData: INodeTypeDescription,
): EndpointOptions {
if (connectionType === NodeConnectionType.Main) {
@@ -559,7 +558,7 @@ export function useNodeBase({
}
const createSupplementalConnectionType = (
connectionName: ConnectionTypes,
connectionName: NodeConnectionType,
): EndpointOptions => ({
endpoint: createAddInputEndpointSpec(
connectionName as NodeConnectionType,
@@ -571,12 +570,12 @@ export function useNodeBase({
}
function getOutputConnectionStyle(
connectionType: ConnectionTypes,
connectionType: NodeConnectionType,
outputConfiguration: INodeOutputConfiguration,
nodeTypeData: INodeTypeDescription,
): EndpointOptions {
const createSupplementalConnectionType = (
connectionName: ConnectionTypes,
connectionName: NodeConnectionType,
): EndpointOptions => ({
endpoint: createDiamondOutputEndpointSpec(),
paintStyle: NodeViewUtils.getOutputEndpointStyle(

View File

@@ -12,7 +12,7 @@ import {
WEBHOOK_NODE_TYPE,
} from '@/constants';
import { NodeHelpers, NodeConnectionType, ExpressionEvaluatorProxy } from 'n8n-workflow';
import { NodeHelpers, ExpressionEvaluatorProxy, NodeConnectionType } from 'n8n-workflow';
import type {
INodeProperties,
INodeCredentialDescription,
@@ -20,7 +20,6 @@ import type {
INodeIssues,
ICredentialType,
INodeIssueObjectProperty,
ConnectionTypes,
INodeInputConfiguration,
Workflow,
INodeExecutionData,
@@ -342,7 +341,7 @@ export function useNodeHelpers() {
const foundIssues: INodeIssueObjectProperty = {};
const workflowNode = workflow.getNode(node.name);
let inputs: Array<ConnectionTypes | INodeInputConfiguration> = [];
let inputs: Array<NodeConnectionType | INodeInputConfiguration> = [];
if (nodeType && workflowNode) {
inputs = NodeHelpers.getNodeInputs(workflow, workflowNode, nodeType);
}
@@ -571,7 +570,7 @@ export function useNodeHelpers() {
runIndex = 0,
outputIndex = 0,
paneType: NodePanelType = 'output',
connectionType: ConnectionTypes = NodeConnectionType.Main,
connectionType: NodeConnectionType = NodeConnectionType.Main,
): INodeExecutionData[] {
//TODO: check if this needs to be fixed in different place
if (
@@ -617,7 +616,7 @@ export function useNodeHelpers() {
function getInputData(
connectionsData: ITaskDataConnections,
outputIndex: number,
connectionType: ConnectionTypes = NodeConnectionType.Main,
connectionType: NodeConnectionType = NodeConnectionType.Main,
): INodeExecutionData[] {
return connectionsData?.[connectionType]?.[outputIndex] ?? [];
}
@@ -627,7 +626,7 @@ export function useNodeHelpers() {
node: string | null,
runIndex: number,
outputIndex: number,
connectionType: ConnectionTypes = NodeConnectionType.Main,
connectionType: NodeConnectionType = NodeConnectionType.Main,
): IBinaryKeyData[] {
if (node === null) {
return [];