fix(PageComponent): update validateSelection function to include edges in the selection if only nodes are selected

This commit is contained in:
anovazzi1 2023-09-18 19:32:24 -03:00
commit 15a2c95351
2 changed files with 13 additions and 3 deletions

View file

@ -446,7 +446,7 @@ export default function Page({
)}
<SelectionMenu isVisible={selectionMenuVisible} nodes={lastSelection?.nodes}
onClick={()=>{
if(validateSelection(lastSelection!).length===0){
if(validateSelection(lastSelection!,edges).length===0){
const {newFlow} = generateFlow(lastSelection!,reactFlowInstance!,getRandomName());
const newGroupNode = generateNodeFromFlow(newFlow)
setNodes((oldNodes)=>[...oldNodes.filter((oldNodes)=>!lastSelection?.nodes.some((selectionNode)=>selectionNode.id===oldNodes.id)),newGroupNode])
@ -464,7 +464,7 @@ export default function Page({
else{
setErrorData({
title: "Invalid selection",
list: validateSelection(lastSelection!),
list: validateSelection(lastSelection!,edges),
});
}
}}/>

View file

@ -486,8 +486,18 @@ export function concatFlows(
}
export function validateSelection(
selection: OnSelectionChangeParams
selection: OnSelectionChangeParams,
edges: Edge[]
): Array<string> {
//add edges to selection if selection mode selected only nodes
if(selection.edges.length === 0){
selection.edges = edges.filter(
(edge) =>
selection.nodes.some((node) => node.id === edge.target) &&
selection.nodes.some((node) => node.id === edge.source)
);
}
let errorsArray: Array<string> = [];
// check if there is more than one node
if (selection.nodes.length < 2) {