-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create separate type for diagram node and edge and extract …
…util function in separate file
- Loading branch information
Showing
4 changed files
with
59 additions
and
48 deletions.
There are no files selected for viewing
7 changes: 5 additions & 2 deletions
7
packages/twenty-front/src/modules/workflow/types/WorkflowDiagram.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/twenty-front/src/modules/workflow/utils/addCreateStepNodes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
WorkflowDiagram, | ||
WorkflowDiagramEdge, | ||
WorkflowDiagramNode, | ||
} from '@/workflow/types/WorkflowDiagram'; | ||
import { MarkerType } from '@xyflow/react'; | ||
import { v4 } from 'uuid'; | ||
|
||
export const addCreateStepNodes = ({ nodes, edges }: WorkflowDiagram) => { | ||
const nodesWithoutTargets = nodes.filter((node) => | ||
edges.every((edge) => edge.source !== node.id), | ||
); | ||
|
||
const updatedNodes: Array<WorkflowDiagramNode> = nodes.slice(); | ||
const updatedEdges: Array<WorkflowDiagramEdge> = edges.slice(); | ||
|
||
for (const node of nodesWithoutTargets) { | ||
const newCreateStepNode: WorkflowDiagramNode = { | ||
id: v4(), | ||
type: 'create-step', | ||
data: {}, | ||
position: { x: 0, y: 0 }, | ||
}; | ||
|
||
updatedNodes.push(newCreateStepNode); | ||
|
||
updatedEdges.push({ | ||
id: v4(), | ||
source: node.id, | ||
target: newCreateStepNode.id, | ||
markerEnd: { | ||
type: MarkerType.ArrowClosed, | ||
}, | ||
}); | ||
} | ||
|
||
return { | ||
nodes: updatedNodes, | ||
edges: updatedEdges, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters