Skip to content

Commit dbb9c67

Browse files
committed
support delete handle
1 parent 26a54df commit dbb9c67

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ function WorkflowsDesigner(props) {
623623
handleDeleteNode: handleDeleteNode,
624624
updateData: updateData,
625625
addHandleSource: addHandleSource,
626-
handleWorkflowChange: handleWorkflowChange
626+
handleWorkflowChange: handleWorkflowChange,
627+
deleteHandle: deleteHandle
627628
}
628629
},
629630
}
@@ -667,6 +668,25 @@ function WorkflowsDesigner(props) {
667668
updateNodeInternals(nodeId)
668669
}
669670

671+
function deleteHandle(nodeId, handleId) {
672+
setNodes(eds => eds.map(node => {
673+
if (node.id === nodeId) {
674+
return {
675+
...node,
676+
data: {
677+
...node.data,
678+
sourceHandles: node.data.sourceHandles.filter(ha => ha.id !== handleId)
679+
}
680+
}
681+
}
682+
return node
683+
}))
684+
685+
setEdges(eds => eds.filter(edge => edge.sourceHandle !== handleId))
686+
687+
updateNodeInternals(nodeId)
688+
}
689+
670690
function handleDeleteNode(nodeId) {
671691
setNodes((nds) => nds.filter((node) => node.id !== nodeId));
672692
setEdges((eds) => eds.filter((edge) => edge.source !== nodeId && edge.target !== nodeId));

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
BaseEdge,
55
EdgeLabelRenderer,
66
getBezierPath,
7+
getSimpleBezierPath,
8+
getSmoothStepPath,
79
useReactFlow,
810
} from '@xyflow/react';
911

@@ -63,7 +65,7 @@ const listeners = id => {
6365

6466
export function CustomEdge({ id, sourceX, sourceY, targetX, targetY }) {
6567
const { setEdges } = useReactFlow();
66-
const [edgePath, labelX, labelY] = getBezierPath({
68+
const [edgePath, labelX, labelY] = getSimpleBezierPath({
6769
sourceX,
6870
sourceY,
6971
targetX,

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from 'react'
22
import { Handle, Position, useNodeConnections } from '@xyflow/react'
33

4-
function RightHandle({ handle, className, selected }) {
4+
function RightHandle({ handle, className, selected, deleteHandle }) {
55
return <Handle
66
id={handle.id}
77
type="source"
88
position={Position.Right}
99
className={`${className} ${(selected ? 'connected' : '')}`}
1010
>
11+
<i className='fas fa-trash me-1' onClick={deleteHandle} />
1112
{handle.id.split('-')[0]}
1213
<div className={`handle-dot ms-1 ${selected ? 'handle-dot--selected' : ''}`} />
1314
</Handle>
@@ -52,7 +53,11 @@ export default function Handles(props) {
5253
.map(handle => {
5354
const selected = connections.find(connection => connection.sourceHandle === handle.id)
5455

55-
return <RightHandle handle={handle} key={handle.id} selected={selected} />
56+
return <RightHandle
57+
handle={handle}
58+
key={handle.id}
59+
selected={selected}
60+
deleteHandle={() => props.data.functions.deleteHandle(props.id, handle.id)} />
5661
})}
5762
{props.data.sourcesIsArray && <button
5863
type="button"
@@ -66,7 +71,8 @@ export default function Handles(props) {
6671
{sources.output && <RightHandle
6772
handle={{ id: sources.output.id }}
6873
className="my-2"
69-
selected={connections.find(connection => connection.sourceHandle === `output-${props.id}`)} />}
74+
selected={connections.find(connection => connection.sourceHandle === `output-${props.id}`)}
75+
deleteHandle={() => props.data.functions.deleteHandle(props.id, handle.id)} />}
7076
</div>
7177
</>
7278
}

0 commit comments

Comments
 (0)