Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Cleanup Workflow.ts a bit, and add some unit tests (no-changelog) #9858

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ vi.mock('@/composables/useToast', () => ({
vi.mock('@/composables/useWorkflowHelpers', () => ({
useWorkflowHelpers: vi.fn().mockReturnValue({
getCurrentWorkflow: vi.fn(),
checkReadyForExecution: vi.fn(),
saveCurrentWorkflow: vi.fn(),
getWorkflowDataToSave: vi.fn(),
}),
Expand Down
80 changes: 0 additions & 80 deletions packages/editor-ui/src/composables/useWorkflowHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
PLACEHOLDER_EMPTY_WORKFLOW_ID,
PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
VIEWS,
WEBHOOK_NODE_TYPE,
} from '@/constants';

import type {
Expand All @@ -15,15 +14,12 @@ import type {
INodeConnection,
INodeCredentials,
INodeExecutionData,
INodeIssues,
INodeParameters,
INodeProperties,
INodeType,
INodeTypes,
IRunExecutionData,
IWebhookDescription,
IWorkflowDataProxyAdditionalKeys,
IWorkflowIssues,
IWorkflowSettings,
NodeParameterValue,
Workflow,
Expand Down Expand Up @@ -531,81 +527,6 @@ export function useWorkflowHelpers(options: { router: ReturnType<typeof useRoute
return count;
}

/** Checks if everything in the workflow is complete and ready to be executed */
function checkReadyForExecution(workflow: Workflow, lastNodeName?: string) {
let node: INode;
let nodeType: INodeType | undefined;
let nodeIssues: INodeIssues | null = null;
const workflowIssues: IWorkflowIssues = {};

let checkNodes = Object.keys(workflow.nodes);
if (lastNodeName) {
checkNodes = workflow.getParentNodes(lastNodeName);
checkNodes.push(lastNodeName);
} else {
// As webhook nodes always take precedence check first
// if there are any
let checkWebhook: string[] = [];
for (const nodeName of Object.keys(workflow.nodes)) {
if (
workflow.nodes[nodeName].disabled !== true &&
workflow.nodes[nodeName].type === WEBHOOK_NODE_TYPE
) {
const childNodes = workflow.getChildNodes(nodeName);
checkWebhook = [nodeName, ...checkWebhook, ...childNodes];
}
}

if (checkWebhook.length) {
checkNodes = checkWebhook;
} else {
// If no webhook nodes got found try to find another trigger node
const startNode = workflow.getStartNode();
if (startNode !== undefined) {
checkNodes = [...workflow.getChildNodes(startNode.name), startNode.name];

// For the short-listed checkNodes, we also need to check them for any
// connected sub-nodes
for (const nodeName of checkNodes) {
const childNodes = workflow.getParentNodes(nodeName, 'ALL_NON_MAIN');
checkNodes.push(...childNodes);
}
}
}
}

for (const nodeName of checkNodes) {
nodeIssues = null;
node = workflow.nodes[nodeName];

if (node.disabled === true) {
// Ignore issues on disabled nodes
continue;
}

nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);

if (nodeType === undefined) {
// Node type is not known
nodeIssues = {
typeUnknown: true,
};
} else {
nodeIssues = nodeHelpers.getNodeIssues(nodeType.description, node, workflow, ['execution']);
}

if (nodeIssues !== null) {
workflowIssues[node.name] = nodeIssues;
}
}

if (Object.keys(workflowIssues).length === 0) {
return null;
}

return workflowIssues;
}

async function getWorkflowDataToSave() {
const workflowNodes = workflowsStore.allNodes;
const workflowConnections = workflowsStore.allConnections;
Expand Down Expand Up @@ -1222,7 +1143,6 @@ export function useWorkflowHelpers(options: { router: ReturnType<typeof useRoute
executeData,
getNodeTypesMaxCount,
getNodeTypeCount,
checkReadyForExecution,
getWorkflowDataToSave,
getNodeDataToSave,
getWebhookExpressionValue,
Expand Down
Loading