Skip to content

Commit

Permalink
fix: not delete edges when deleting non-deletable nodes (#2887)
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk authored and c121914yu committed Oct 12, 2024
1 parent ebeeb1c commit ee73739
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import {
Input_Template_Node_Width
} from '@fastgpt/global/core/workflow/template/input';
import { FlowNodeItemType } from '@fastgpt/global/core/workflow/type/node';
import { getHandleId } from '@fastgpt/global/core/workflow/utils';
import { IfElseResultEnum } from '@fastgpt/global/core/workflow/template/system/ifElse/constant';

/*
Compute helper lines for snapping nodes to each other
Expand Down Expand Up @@ -439,6 +437,15 @@ export const useWorkflow = () => {

onNodesChange([change]);

// Remove the edges connected to the node
const nodeEdges = edges.filter((edge) => edge.source === nodeId || edge.target === nodeId);
onEdgesChange(
nodeEdges.map<EdgeRemoveChange>((edge) => ({
type: 'remove',
id: edge.id
}))
);

return;
});
const handleSelectNode = useMemoizedFn((change: NodeSelectionChange) => {
Expand Down Expand Up @@ -538,9 +545,14 @@ export const useWorkflow = () => {

const handleEdgeChange = useCallback(
(changes: EdgeChange[]) => {
onEdgesChange(changes);
// If any node is selected, don't remove edges
const changesFiltered = changes.filter(
(change) => !(change.type === 'remove' && nodes.some((node) => node.selected))
);

onEdgesChange(changesFiltered);
},
[onEdgesChange]
[nodes, onEdgesChange]
);

const onNodeDragStop = useCallback(
Expand Down

0 comments on commit ee73739

Please sign in to comment.