Skip to content

Commit

Permalink
fix(): update existed edges instead add new one
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Sep 10, 2024
1 parent 63dc3e2 commit 981d2c4
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions bricks/diagram/src/draw-canvas/reducers/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,30 @@ export const cells: Reducer<Cell[], DrawCanvasAction> = (state, action) => {
...state.slice(index),
];
}
case "add-edge":
// Add the edge to just next to the previous last edge or area decorator.
// If not found, append to the start.
return insertCellAfter(
state,
action.payload,
case "add-edge": {
const existedEdgeIndex = state.findIndex(
(cell) =>
cell.type === "edge" ||
(cell.type === "decorator" && cell.decorator === "area")
cell.type === "edge" &&
cell.source === action.payload.source &&
cell.target === action.payload.target
);
if (existedEdgeIndex === -1) {
// Add the edge to just next to the previous last edge or area decorator.
// If not found, append to the start.
return insertCellAfter(
state,
action.payload,
(cell) =>
cell.type === "edge" ||
(cell.type === "decorator" && cell.decorator === "area")
);
}
return [
...state.slice(0, existedEdgeIndex),
action.payload,
...state.slice(existedEdgeIndex + 1),
];
}
case "move-cells": {
let matched = false;
const newState = state.map((cell) => {
Expand Down

0 comments on commit 981d2c4

Please sign in to comment.