feat(core): add option to avoid replacing edge id when updating

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-02-22 20:20:11 +01:00
committed by Braks
parent aafd8622f4
commit 4bf4b6386e
3 changed files with 8 additions and 5 deletions
+5 -3
View File
@@ -22,7 +22,7 @@ export function addEdgeToStore(edgeParams: Edge | Connection, edges: Edge[]) {
return edge
}
export function updateEdgeAction(edge: GraphEdge, newConnection: Connection, edges: GraphEdge[]) {
export function updateEdgeAction(edge: GraphEdge, newConnection: Connection, edges: GraphEdge[], shouldReplaceId: boolean) {
if (!newConnection.source || !newConnection.target) {
warn("Can't create new edge. An edge needs a source and a target.")
return false
@@ -35,9 +35,11 @@ export function updateEdgeAction(edge: GraphEdge, newConnection: Connection, edg
return false
}
const { id, ...rest } = edge
const newEdge = {
...edge,
id: getEdgeId(newConnection),
...rest,
id: shouldReplaceId ? getEdgeId(newConnection) : id,
source: newConnection.source,
target: newConnection.target,
sourceHandle: newConnection.sourceHandle,