Skip to content

Commit 88c76bc

Browse files
committed
support switch and predicate nodes
1 parent 07f7a5e commit 88c76bc

9 files changed

Lines changed: 53 additions & 45 deletions

File tree

otoroshi/javascript/src/extensions/workflows/Flow.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import React from 'react';
33
import { Node } from './flow/Node'
44
import { GroupNode } from './flow/GroupNode'
55
import { CustomEdge } from './flow/CustomEdge'
6-
import { AddNode } from './nodes/AddNode'
76
import { ReactFlow, Background, Controls } from '@xyflow/react';
87
import '@xyflow/react/dist/style.css';
9-
import { StartNode } from './nodes/StartNode';
108

119
export function Flow({ nodes, onClick, edges, onNodesChange, onEdgesChange, onConnect, onConnectEnd, onGroupNodeClick, setRfInstance }) {
1210

@@ -26,8 +24,7 @@ export function Flow({ nodes, onClick, edges, onNodesChange, onEdgesChange, onCo
2624
connectionLineType='simplebezier'
2725
nodeTypes={{
2826
simple: Node,
29-
group: GroupNode,
30-
AddNode: AddNode,
27+
group: GroupNode
3128
}}
3229
edgeTypes={{
3330
customEdge: CustomEdge,

otoroshi/javascript/src/extensions/workflows/WorkflowsDesigner.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,25 @@ const buildGraph = (workflows, addInformationsToNode, targetId, handleId) => {
327327
animated: true,
328328
})
329329
} else {
330-
if(workflow.predicate) {
330+
if (workflow.predicate !== undefined) {
331331
// sub path of switch group
332-
console.log("HERE")
332+
333+
const predicate = buildGraph([{
334+
kind: 'predicate'
335+
}], addInformationsToNode, me, 'node')
336+
const predicateNode = predicate.nodes[0]
337+
338+
nodes = [predicateNode, current]
339+
340+
edges.push({
341+
id: `${me}-${predicateNode.id}`,
342+
source: predicateNode.id,
343+
sourceHandle: `output-${predicateNode.id}`,
344+
target: me,
345+
targetHandle: `input-${me}`,
346+
type: 'customEdge',
347+
animated: true,
348+
})
333349
}
334350
}
335351

@@ -481,7 +497,7 @@ function WorkflowsDesigner(props) {
481497
// });
482498
}, [])
483499

484-
const { fitView } = useReactFlow();
500+
const { fitView, screenToFlowPosition } = useReactFlow();
485501
const updateNodeInternals = useUpdateNodeInternals()
486502

487503
const getLayoutedElements = (nodes, edges, options = {}) => {
@@ -546,7 +562,9 @@ function WorkflowsDesigner(props) {
546562
.then(({ nodes: layoutedNodes, edges: layoutedEdges }) => {
547563
setNodes(layoutedNodes)
548564
setEdges(layoutedEdges)
549-
fitView();
565+
fitView({
566+
padding: 5
567+
});
550568
});
551569
};
552570

@@ -746,7 +764,8 @@ function WorkflowsDesigner(props) {
746764
setTimeout(() => {
747765
setOnCreationMode({
748766
...connectionState.fromNode,
749-
handle: connectionState.fromHandle
767+
handle: connectionState.fromHandle,
768+
event
750769
})
751770
}, 2)
752771
}
@@ -778,13 +797,22 @@ function WorkflowsDesigner(props) {
778797
);
779798

780799
const handleSelectNode = item => {
781-
const targetId = uuid()
800+
let targetId = uuid()
801+
802+
const { clientX, clientY } = 'changedTouches' in isOnCreation.event ? isOnCreation.event.changedTouches[0] : isOnCreation.event;
803+
804+
if (item.operator)
805+
targetId = `${targetId}-operator`
782806

783807
let newNode = addInformationsToNode({
784808
...createSimpleNode([], item),
785809
id: targetId,
786-
position: isOnCreation.fromOrigin ? isOnCreation.fromOrigin : findNonOverlappingPosition(nodes.map(n => n.position)),
810+
// position: isOnCreation.fromOrigin ? isOnCreation.fromOrigin : findNonOverlappingPosition(nodes.map(n => n.position)),
787811
type: item.type || 'simple',
812+
position: screenToFlowPosition({
813+
x: clientX,
814+
y: clientY,
815+
}),
788816
})
789817

790818
let newEdges = []
@@ -825,8 +853,6 @@ function WorkflowsDesigner(props) {
825853
setEdges(newEdges)
826854

827855
setOnCreationMode(false)
828-
829-
onLayout({ direction: 'RIGHT', nodes: newNodes, edges: newEdges, from: 'handleSelect' });
830856
}
831857

832858
function run() {

otoroshi/javascript/src/extensions/workflows/flow/AddNodeButton.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

otoroshi/javascript/src/extensions/workflows/flow/Node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function Node(props) {
3333
}}
3434
>
3535
<div className='node-one-output d-flex-center'>
36-
{data.label || data.item?.label} {data.name}
36+
{data.operator ? <i className='fas fa-wrench' /> : (data.label || data.item?.label)} {data.name}
3737
</div>
3838

3939
{data.nodeRenderer && data.nodeRenderer(props)}

otoroshi/javascript/src/extensions/workflows/models/Functions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { AddNode } from "../nodes/AddNode"
21
import { AssignNode } from "../nodes/AssignNode"
32
import { CallNode } from "../nodes/CallNode"
43
import { ErrorNode } from "../nodes/ErrorNode"
@@ -54,6 +53,7 @@ import { DecrOperator } from '../operators/DecrOperator'
5453
import { IncrOperator } from '../operators/IncrOperator'
5554
import { ReturnedNode } from "../nodes/ReturnedNode"
5655
import { StartNode } from "../nodes/StartNode"
56+
import { PredicateNode } from "../nodes/PredicateNode"
5757

5858
export const NODES = {
5959
"assign": AssignNode,
@@ -69,9 +69,9 @@ export const NODES = {
6969
"wait": WaitNode,
7070
"error": ErrorNode,
7171
"value": ValueNode,
72-
"addnode": AddNode,
7372
"returned": ReturnedNode,
74-
"start": StartNode
73+
"start": StartNode,
74+
"predicate": PredicateNode
7575
}
7676

7777
export const OPERATORS = {

otoroshi/javascript/src/extensions/workflows/nodes/AddNode.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

otoroshi/javascript/src/extensions/workflows/nodes/IfThenElseNode.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react'
2-
import { AddNode } from './AddNode'
32

43
export const IfThenElseNode = (_workflow) => ({
54
label: <i className='fas fa-question' />,

otoroshi/javascript/src/extensions/workflows/nodes/ParallelFlowsNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export const ParallelFlowsNode = (_workflow) => ({
1010
sourcesIsArray: true,
1111
handlePrefix: 'path',
1212
sources: [],
13-
height: () => `${110 + 20 * _workflow?.paths.length}px`,
13+
height: () => `${110 + 20 * _workflow?.paths?.length}px`,
1414
targets: []
1515
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react'
2+
3+
export const PredicateNode = (_workflow) => {
4+
return {
5+
label: <i className='fas fa-filter' />,
6+
kind: 'PredicateNode',
7+
name: 'Predicate',
8+
type: 'simple',
9+
workflow: _workflow,
10+
sources: ['output']
11+
}
12+
}

0 commit comments

Comments
 (0)