fix(PageComponent): update validateSelection function to include edges in the selection if only nodes are selected
This commit is contained in:
parent
3fc08cee93
commit
15a2c95351
2 changed files with 13 additions and 3 deletions
|
|
@ -446,7 +446,7 @@ export default function Page({
|
||||||
)}
|
)}
|
||||||
<SelectionMenu isVisible={selectionMenuVisible} nodes={lastSelection?.nodes}
|
<SelectionMenu isVisible={selectionMenuVisible} nodes={lastSelection?.nodes}
|
||||||
onClick={()=>{
|
onClick={()=>{
|
||||||
if(validateSelection(lastSelection!).length===0){
|
if(validateSelection(lastSelection!,edges).length===0){
|
||||||
const {newFlow} = generateFlow(lastSelection!,reactFlowInstance!,getRandomName());
|
const {newFlow} = generateFlow(lastSelection!,reactFlowInstance!,getRandomName());
|
||||||
const newGroupNode = generateNodeFromFlow(newFlow)
|
const newGroupNode = generateNodeFromFlow(newFlow)
|
||||||
setNodes((oldNodes)=>[...oldNodes.filter((oldNodes)=>!lastSelection?.nodes.some((selectionNode)=>selectionNode.id===oldNodes.id)),newGroupNode])
|
setNodes((oldNodes)=>[...oldNodes.filter((oldNodes)=>!lastSelection?.nodes.some((selectionNode)=>selectionNode.id===oldNodes.id)),newGroupNode])
|
||||||
|
|
@ -464,7 +464,7 @@ export default function Page({
|
||||||
else{
|
else{
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "Invalid selection",
|
title: "Invalid selection",
|
||||||
list: validateSelection(lastSelection!),
|
list: validateSelection(lastSelection!,edges),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}/>
|
}}/>
|
||||||
|
|
|
||||||
|
|
@ -486,8 +486,18 @@ export function concatFlows(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateSelection(
|
export function validateSelection(
|
||||||
selection: OnSelectionChangeParams
|
selection: OnSelectionChangeParams,
|
||||||
|
edges: Edge[]
|
||||||
): Array<string> {
|
): 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> = [];
|
let errorsArray: Array<string> = [];
|
||||||
// check if there is more than one node
|
// check if there is more than one node
|
||||||
if (selection.nodes.length < 2) {
|
if (selection.nodes.length < 2) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue