diff --git a/GUI/src/components/FlowElementsPopup/PreviousVariables.tsx b/GUI/src/components/FlowElementsPopup/PreviousVariables.tsx index 5a39a4917..45261b99e 100644 --- a/GUI/src/components/FlowElementsPopup/PreviousVariables.tsx +++ b/GUI/src/components/FlowElementsPopup/PreviousVariables.tsx @@ -109,6 +109,11 @@ const PreviousVariables: FC = ({ node }) => { key: 'Empty Content Type', value: stringToTemplate(''), }, + { + id: predefinedInputKeys[1], + key: 'Chat Id', + value: stringToTemplate('chatId'), + }, ]; setAssignedVariables([...assignElements, ...predefinedInputElements, ...newAssignElements]); diff --git a/GUI/src/hooks/flow/useEdgeAdd.ts b/GUI/src/hooks/flow/useEdgeAdd.ts index 95e6bcb98..0c6c47aef 100644 --- a/GUI/src/hooks/flow/useEdgeAdd.ts +++ b/GUI/src/hooks/flow/useEdgeAdd.ts @@ -114,7 +114,16 @@ function useEdgeAdd(id: string) { let newEdges: Edge[] = []; setEdges((edges) => { - newEdges = edges.filter((e) => e.id !== id).concat([sourceEdge], targetEdge ?? [], ghostEdges); + const edgeIndex = edges.findIndex((e) => e.id === id); + const remainingEdges = edges.filter((e) => e.id !== id); + const insertIndex = edgeIndex === -1 ? remainingEdges.length : edgeIndex; + newEdges = [ + ...remainingEdges.slice(0, insertIndex), + sourceEdge, + ...(targetEdge ? [targetEdge] : []), + ...ghostEdges, + ...remainingEdges.slice(insertIndex), + ]; return newEdges; }); diff --git a/GUI/src/hooks/flow/useOnNodeDelete.ts b/GUI/src/hooks/flow/useOnNodeDelete.ts index 875177a52..5c1bf6565 100644 --- a/GUI/src/hooks/flow/useOnNodeDelete.ts +++ b/GUI/src/hooks/flow/useOnNodeDelete.ts @@ -77,7 +77,12 @@ const processDeletedNodes = ( updatedNodes = [...updatedNodes.filter((n) => n.id !== node.id), ...newGhostNodes]; updatedEdges = [...getRemainingEdges(updatedEdges, getConnectedEdges([node], updatedEdges)), ...newEdges]; } else { - if (outgoers.length === 0 || outgoers.length > 1) { + const edgesWithoutDeleted = getRemainingEdges(updatedEdges, getConnectedEdges([node], updatedEdges)); + if ( + outgoers.length === 0 || + outgoers.length > 1 || + (outgoers.length === 1 && getIncomers(outgoers[0], updatedNodes, edgesWithoutDeleted).length > 0) + ) { const ghostNode: Node = { id: generateUniqueId(), type: 'ghost',