8000 Merge node fix by makaveli2P · Pull Request #56 · urban-toolkit/curio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Merge node fix #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions tests/Merge.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,32 @@
],
"edges": [
{
"id": "reactflow__edge-c16e25b5-9ed4-4b87-8049-dde62c9bfa5aout-fba24a09-19fe-429e-b0b0-037229e7b1dcin",
"id": "reactflow__edge-c16e25b5-9ed4-4b87-8049-dde62c9bfa5aout-fba24a09-19fe-429e-b0b0-037229e7b1dcin_1",
"source": "c16e25b5-9ed4-4b87-8049-dde62c9bfa5a",
"target": "fba24a09-19fe-429e-b0b0-037229e7b1dc"
"sourceHandle": "out",
"target": "fba24a09-19fe-429e-b0b0-037229e7b1dc",
"targetHandle": "in_1"
},
{
"id": "reactflow__edge-fba24a09-19fe-429e-b0b0-037229e7b1dcout-9c3f8293-8cc9-4ed8-8840-ca60655e21d7in",
"source": "fba24a09-19fe-429e-b0b0-037229e7b1dc",
"target": "9c3f8293-8cc9-4ed8-8840-ca60655e21d7"
"sourceHandle": "out",
"target": "9c3f8293-8cc9-4ed8-8840-ca60655e21d7",
"targetHandle": "in"
},
{
"id": "reactflow__edge-e392ed5c-0df1-4815-a76f-542930b855d4out-fba24a09-19fe-429e-b0b0-037229e7b1dcin_2",
"source": "e392ed5c-0df1-4815-a76f-542930b855d4",
"target": "fba24a09-19fe-429e-b0b0-037229e7b1dc"
"sourceHandle": "out",
"target": "fba24a09-19fe-429e-b0b0-037229e7b1dc",
"targetHandle": "in_2"
},
{
"id": "reactflow__edge-9c3f8293-8cc9-4ed8-8840-ca60655e21d7out-3d6376b4-782b-4c98-89f6-8eff022beb87in",
"source": "9c3f8293-8cc9-4ed8-8840-ca60655e21d7",
"target": "3d6376b4-782b-4c98-89f6-8eff022beb87"
"sourceHandle": "out",
"target": "3d6376b4-782b-4c98-89f6-8eff022beb87",
"targetHandle": "in"
}
],
"name": "DefaultWorkflow",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCircleInfo } from "@fortawesome/free-solid-svg-icons";
import { useUserContext } from "../providers/UserProvider";

function MergeFlowBox({ data, isConnectable }) {
function MergeFlowBox({ data, isConnectable }: { data: any; isConnectable: boolean }) {
const [output, setOutput] = useState<{ code: string; content: string }>({
code: "",
content: JSON.stringify({ data: [], dataType: "outputs" }),
Expand Down Expand Up @@ -64,15 +64,24 @@ function MergeFlowBox({ data, isConnectable }) {

let newOutput: any = { data: [], dataType: "outputs" };

if (Array.isArray(data.input) && data.input.length > 0) {
for (const input of data.input) {
if (input != "" && input != undefined) {
newOutput.data.push(input);
}
if (Array.isArray(data.input)) {
// Process primary input [0] then secondary input [1]
const primaryInput = data.input[0];
const secondaryInput = data.input[1];

if (primaryInput !== undefined && primaryInput !== "") {
newOutput.data.push(primaryInput);
}

if (secondaryInput !== undefined && secondaryInput !== "") {
newOutput.data.push(secondaryInput);
}

// Only trigger output callback if we have at least one valid input
if (newOutput.data.length > 0) {
setOutput({ code: "success", content: newOutput });
data.outputCallback(data.nodeId, newOutput);
}

setOutput({ code: "success", content: newOutput });
data.outputCallback(data.nodeId, newOutput);
}
}, [data.input]);

Expand All< 10000 /tool-tip> @@ -82,7 +91,7 @@ function MergeFlowBox({ data, isConnectable }) {
type="target"
position={Position.Left}
className={"handle_top_left"}
id="in"
id="in_1"
isConnectable={isConnectable}
/>
<Handle
Expand Down
4 changes: 3 additions & 1 deletion utk_curio/frontend/urban-workflows/src/hook/useCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export function useCode(): IUseCode {

let targetHandle = "in";

if(edge.id.includes("in_2")) { // For the second input of the merge node
if(edge.id.includes("in_1")) { // For the first input of the merge node
targetHandle = "in_1";
} else if(edge.id.includes("in_2")) { // For the second input of the merge node
targetHandle = "in_2";
}

Expand Down
136 changes: 62 additions & 74 deletions utk_curio/frontend/urban-workflows/src/providers/FlowProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { BoxType, EdgeType, VisInteractionType } from "../constants";
import { useProvenanceContext } from "./ProvenanceProvider";
import { TrillGenerator } from "../TrillGenerator";


export interface IOutput {
nodeId: string;
output: string;
Expand Down Expand Up @@ -137,6 +138,7 @@ const FlowProvider = ({ children }: { children: ReactNode }) => {
_setWorkflowName(data);
};


useEffect(() => {
addWorkflow(workflowNameRef.current);
let empty_trill = TrillGenerator.generateTrill([], [], workflowNameRef.current);
Expand Down Expand Up @@ -444,19 +446,20 @@ const FlowProvider = ({ children } ED4F : { children: ReactNode }) => {
if (node.id == setInput) {
// Merge Flow box is the only box that allows multiple 'in' connections
if (inBox == BoxType.MERGE_FLOW) {
let inputList = node.data.input;
let sourceList = node.data.source;

if (inputList == undefined || inputList == "") {
inputList = [output];
} else {
inputList = [...inputList, output];
}

if (sourceList == undefined || sourceList == "") {
sourceList = [getOutput];
} else {
sourceList = [...sourceList, getOutput];
// Initialize fixed-size arrays for position-semantic behavior
let inputList = Array.isArray(node.data.input) ? [...node.data.input] : [undefined, undefined];
let sourceList = Array.isArray(node.data.source) ? [...node.data.source] : [undefined, undefined];

// Ensure arrays are exactly size 2
while (inputList.length < 2) inputList.push(undefined);
while (sourceList.length < 2) sourceList.push(undefined);

// Map handle to array index: "in_1" -> 0 (primary), "in_2" -> 1 (secondary)
const handleIndex = targetHandle === "in_1" ? 0 : targetHandle === "in_2" ? 1 : -1;

if (handleIndex >= 0) {
inputList[handleIndex] = output;
sourceList[handleIndex] = getOutput;
}

node.data = {
Expand Down Expand Up @@ -505,27 +508,18 @@ const FlowProvider = ({ children }: { children: ReactNode }) => {
nds.map((node: any) => {
if (node.id == resetInput) {
if (targetNode.type === BoxType.MERGE_FLOW) {
let inputList: string[] = [];
let sourceList: string[] = [];

if (Array.isArray(node.data.source)) {
for (
let i = 0;
i < node.data.source.length;
i++
) {
if (
connection.source !=
node.data.source[i]
) {
inputList.push(
node.data.input[i]
);
sourceList.push(
node.data.source[i]
);
}
}
let inputList = Array.isArray(node.data.input) ? [...node.data.input] : [undefined, undefined];
let sourceList = Array.isArray(node.data.source) ? [...node.data.source] : [undefined, undefined];

while (inputList.length < 2) inputList.push(undefined);
while (sourceList.length < 2) sourceList.push(undefined);

const handleIndex = connection.targetHandle === "in_1" ? 0 : connection.targetHandle === "in_2" ? 1 : -1;

if (handleIndex >= 0) {
// Clear the specific position
inputList[handleIndex] = undefined;
sourceList[handleIndex] = undefined;
}

node.data = {
Expand Down Expand Up @@ -615,9 +609,9 @@ const FlowProvider = ({ children }: { children: ReactNode }) => {
"An in/out connection can only be connected to another in/out connection"
);
} else if (
((connection.sourceHandle == "in" || connection.sourceHandle == "in_2") &&
((connection.sourceHandle == "in" || connection.sourceHandle == "in_1" || connection.sourceHandle == "in_2") &&
connection.targetHandle != "out") ||
((connection.targetHandle == "in" || connection.targetHandle == "in_2") &&
((connection.targetHandle == "in" || connection.targetHandle == "in_1" || connection.targetHandle == "in_2") &&
connection.sourceHandle != "out")
) {
validHandleCombination = false;
Expand All @@ -626,9 +620,9 @@ const FlowProvider = ({ children }: { children: ReactNode }) => {
);
} else if (
(connection.sourceHandle == "out" &&
(connection.targetHandle != "in" && connection.targetHandle != "in_2")) ||
(connection.targetHandle != "in" && connection.targetHandle != "in_1" && connection.targetHandle != "in_2")) ||
(connection.targetHandle == "out" &&
(connection.sourceHandle != "in" && connection.sourceHandle != "in_2"))
(connection.sourceHandle != "in" && connection.sourceHandle != "in_1" && connection.sourceHandle != "in_2"))
) {
validHandleCombination = false;
alert(
Expand Down Expand Up @@ -656,10 +650,21 @@ const FlowProvider = ({ children }: { children: ReactNode }) => {
inBox
);

if (!allowConnection)
alert(
"Input and output types of these boxes are not compatible"
if (!allowConnection) {
alert("Input and output types of these boxes are not compatible");
}

if (inBox === BoxType.MERGE_FLOW && allowConnection) {
const existingConnections = edges.filter((edge: Edge) =>
edge.target === connection.target &&
(edge.targetHandle === "in_1" || edge.targetHandle === "in_2")
);

if (existingConnections.length >= 2) {
alert("Connection Limit Reached!\n\nMerge nodes can only accept 2 input connections:\n• TOP-LEFT input = Primary data\n• BOTTOM-LEFT input = Secondary data\n\nPlease remove an existing connection first.");
allowConnection = false;
}
}

// Checking cycles
if (target.id === connection.source) {
Expand Down Expand Up @@ -757,41 +762,24 @@ const FlowProvider = ({ children }: { children: ReactNode }) => {
nds.map((node: any) => {
if (nodesAffected.includes(node.id)) {
if (node.type == BoxType.MERGE_FLOW) {
if (Array.isArray(node.data.input)) {
let foundSource = false;
let inputList: string[] = [];
let sourceList: string[] = [];

for (let i = 0; i < node.data.input.length; i++) {
if (node.data.source[i] == newOutput.nodeId) {
// updating new value
inputList.push(newOutput.output);
sourceList.push(newOutput.nodeId);
foundSource = true;
} else {
inputList.push(node.data.input[i]);
sourceList.push(node.data.source[i]);
}
let inputList = Array.isArray(node.data.input) ? [...node.data.input] : [undefined, undefined];
let sourceList = Array.isArray(node.data.source) ? [...node.data.source] : [undefined, undefined];

while (inputList.length < 2) inputList.push(undefined);
while (sourceList.length < 2) sourceList.push(undefined);

for (let i = 0; i < sourceList.length; i++) {
if (sourceList[i] === newOutput.nodeId) {
inputList[i] = newOutput.output;
break;
}

if (!foundSource) {
// adding new value
inputList.push(newOutput.output);
sourceList.push(newOutput.nodeId);
}
console.log("===================", inputList);
node.data = {
...node.data,
input: inputList,
source: sourceList,
};
} else {
node.data = {
...node.data,
input: [newOutput.output],
source: [newOutput.nodeId],
};
}

node.data = {
...node.data,
input: inputList,
source: sourceList,
};
} else {
if (newOutput.output == undefined) {
node.data = {
Expand Down
0