Remove dead code about workflow leaf nodes (#10901)

Leaf nodes is no longer a concept in the workflow diagrams. This PR
removes dead code.

Closes https://github.com/twentyhq/core-team-issues/issues/386
This commit is contained in:
Baptiste Devessier
2025-03-14 18:33:19 +01:00
committed by GitHub
parent 1bc30e9b21
commit 5b7b58c85f
20 changed files with 5 additions and 207 deletions
@@ -21,7 +21,6 @@ describe('generateWorkflowDiagram', () => {
expect(result.nodes[0]).toMatchObject({
data: {
nodeType: 'trigger',
isLeafNode: false,
},
});
});
@@ -88,7 +87,6 @@ describe('generateWorkflowDiagram', () => {
nodeType: 'action',
actionType: 'CODE',
name: step.name,
isLeafNode: false,
});
}
});
@@ -121,7 +121,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"icon": "IconPlaylistAdd",
"isLeafNode": false,
"name": "Company created",
"nodeType": "trigger",
"runStatus": "success",
@@ -136,7 +135,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 1",
"nodeType": "action",
"runStatus": "failure",
@@ -150,7 +148,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 2",
"nodeType": "action",
"runStatus": "not-executed",
@@ -164,7 +161,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 3",
"nodeType": "action",
"runStatus": "not-executed",
@@ -300,7 +296,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"icon": "IconPlaylistAdd",
"isLeafNode": false,
"name": "Company created",
"nodeType": "trigger",
"runStatus": "success",
@@ -315,7 +310,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 1",
"nodeType": "action",
"runStatus": "success",
@@ -329,7 +323,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 2",
"nodeType": "action",
"runStatus": "success",
@@ -343,7 +336,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 3",
"nodeType": "action",
"runStatus": "success",
@@ -464,7 +456,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"icon": "IconPlaylistAdd",
"isLeafNode": false,
"name": "Company created",
"nodeType": "trigger",
"runStatus": "success",
@@ -479,7 +470,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 1",
"nodeType": "action",
"runStatus": "running",
@@ -493,7 +483,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 2",
"nodeType": "action",
"runStatus": "not-executed",
@@ -507,7 +496,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 3",
"nodeType": "action",
"runStatus": "not-executed",
@@ -661,7 +649,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"icon": "IconPlaylistAdd",
"isLeafNode": false,
"name": "Company created",
"nodeType": "trigger",
"runStatus": "success",
@@ -676,7 +663,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 1",
"nodeType": "action",
"runStatus": "success",
@@ -690,7 +676,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 2",
"nodeType": "action",
"runStatus": "running",
@@ -704,7 +689,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 3",
"nodeType": "action",
"runStatus": "not-executed",
@@ -718,7 +702,6 @@ describe('generateWorkflowRunDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "Step 4",
"nodeType": "action",
"runStatus": "not-executed",
@@ -36,7 +36,6 @@ describe('getWorkflowVersionDiagram', () => {
"nodes": [
{
"data": {
"isLeafNode": false,
"nodeType": "empty-trigger",
},
"id": "trigger",
@@ -75,7 +74,6 @@ describe('getWorkflowVersionDiagram', () => {
{
"data": {
"icon": "IconPlaylistAdd",
"isLeafNode": false,
"name": "Record is created",
"nodeType": "trigger",
"triggerType": "DATABASE_EVENT",
@@ -144,7 +142,6 @@ describe('getWorkflowVersionDiagram', () => {
{
"data": {
"icon": "IconPlaylistAdd",
"isLeafNode": false,
"name": "Company created",
"nodeType": "trigger",
"triggerType": "DATABASE_EVENT",
@@ -158,7 +155,6 @@ describe('getWorkflowVersionDiagram', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "",
"nodeType": "action",
},
@@ -1,69 +0,0 @@
import { WorkflowStep, WorkflowTrigger } from '@/workflow/types/Workflow';
import { generateWorkflowDiagram } from '@/workflow/workflow-diagram/utils/generateWorkflowDiagram';
import { markLeafNodes } from '../markLeafNodes';
describe('markLeafNodes', () => {
const createTrigger = (): WorkflowTrigger => ({
name: 'Company created',
type: 'DATABASE_EVENT',
settings: {
eventName: 'company.created',
outputSchema: {},
},
});
const createStep = (id: string): WorkflowStep => ({
id,
name: `Step ${id}`,
type: 'CODE',
valid: true,
settings: {
errorHandlingOptions: {
retryOnFailure: { value: true },
continueOnFailure: { value: false },
},
input: {
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
serverlessFunctionVersion: '1',
serverlessFunctionInput: {},
},
outputSchema: {},
},
});
it('handles empty workflow with only trigger', () => {
const trigger = createTrigger();
const steps: WorkflowStep[] = [];
const diagram = generateWorkflowDiagram({ trigger, steps });
const diagramWithLeafNodes = markLeafNodes(diagram);
expect(diagramWithLeafNodes.nodes).toHaveLength(1);
expect(diagramWithLeafNodes.nodes[0].data.isLeafNode).toBe(true);
});
it('handles workflow with single step', () => {
const trigger = createTrigger();
const steps = [createStep('step1')];
const diagram = generateWorkflowDiagram({ trigger, steps });
const diagramWithLeafNodes = markLeafNodes(diagram);
expect(diagramWithLeafNodes.nodes).toHaveLength(2);
expect(diagramWithLeafNodes.nodes[0].data.isLeafNode).toBe(false);
expect(diagramWithLeafNodes.nodes[1].data.isLeafNode).toBe(true);
});
it('handles workflow with two steps', () => {
const trigger = createTrigger();
const steps = [createStep('step1'), createStep('step2')];
const diagram = generateWorkflowDiagram({ trigger, steps });
const diagramWithLeafNodes = markLeafNodes(diagram);
expect(diagramWithLeafNodes.nodes).toHaveLength(3);
expect(diagramWithLeafNodes.nodes[0].data.isLeafNode).toBe(false);
expect(diagramWithLeafNodes.nodes[1].data.isLeafNode).toBe(false);
expect(diagramWithLeafNodes.nodes[2].data.isLeafNode).toBe(true);
});
});
@@ -9,7 +9,6 @@ it('Preserves the properties defined in the previous version but not in the next
nodeType: 'action',
name: '',
actionType: 'CODE',
isLeafNode: true,
},
id: '1',
position: { x: 0, y: 0 },
@@ -25,7 +24,6 @@ it('Preserves the properties defined in the previous version but not in the next
nodeType: 'action',
name: '',
actionType: 'CODE',
isLeafNode: true,
},
id: '1',
position: { x: 0, y: 0 },
@@ -42,7 +40,6 @@ it('Preserves the properties defined in the previous version but not in the next
{
"data": {
"actionType": "CODE",
"isLeafNode": true,
"name": "",
"nodeType": "action",
},
@@ -66,7 +63,6 @@ it('Replaces duplicated properties with the next value', () => {
nodeType: 'action',
name: '',
actionType: 'CODE',
isLeafNode: true,
},
id: '1',
position: { x: 0, y: 0 },
@@ -81,7 +77,6 @@ it('Replaces duplicated properties with the next value', () => {
nodeType: 'action',
name: '2',
actionType: 'CODE',
isLeafNode: false,
},
id: '1',
position: { x: 0, y: 0 },
@@ -98,7 +93,6 @@ it('Replaces duplicated properties with the next value', () => {
{
"data": {
"actionType": "CODE",
"isLeafNode": false,
"name": "2",
"nodeType": "action",
},
@@ -55,7 +55,6 @@ export const generateWorkflowDiagram = ({
nodeType: 'action',
actionType: step.type,
name: step.name,
isLeafNode: false,
} satisfies WorkflowDiagramStepNodeData,
position: {
x: xPos,
@@ -99,7 +99,6 @@ export const generateWorkflowRunDiagram = ({
nodeType: 'action',
actionType: step.type,
name: step.name,
isLeafNode: false,
runStatus,
},
position: {
@@ -64,7 +64,6 @@ export const getWorkflowDiagramTriggerNode = ({
triggerType: trigger.type,
name: isDefined(trigger.name) ? trigger.name : triggerDefaultLabel,
icon: triggerIcon,
isLeafNode: false,
} satisfies WorkflowDiagramStepNodeData,
position: {
x: 0,
@@ -1,31 +0,0 @@
import {
WorkflowDiagram,
WorkflowDiagramNode,
} from '@/workflow/workflow-diagram/types/WorkflowDiagram';
import { isCreateStepNode } from '@/workflow/workflow-diagram/utils/isCreateStepNode';
export const markLeafNodes = ({
nodes,
edges,
}: WorkflowDiagram): WorkflowDiagram => {
const sourceNodeIds = new Set(edges.map((edge) => edge.source));
const updatedNodes = nodes.map((node) => {
if (isCreateStepNode(node)) {
return node;
}
return {
...node,
data: {
...node.data,
isLeafNode: !sourceNodeIds.has(node.id),
},
};
});
return {
nodes: updatedNodes as WorkflowDiagramNode[],
edges,
};
};