Skip to content

Commit

Permalink
fix(ui): subworkflow port name updating (#889)
Browse files Browse the repository at this point in the history
* fix subworkflow port name updating

* fitView on canvas change
  • Loading branch information
KaWaite authored Feb 20, 2025
1 parent 0740888 commit b81f662
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
7 changes: 6 additions & 1 deletion ui/src/features/Editor/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useReactFlow } from "@xyflow/react";
import { MouseEvent, useCallback, useMemo, useState } from "react";
import { MouseEvent, useCallback, useEffect, useMemo, useState } from "react";
import { useY } from "react-yjs";
import { Array as YArray, UndoManager as YUndoManager } from "yjs";

Expand Down Expand Up @@ -47,6 +47,11 @@ export default ({
const [selectedNodeIds, setSelectedNodeIds] = useState<string[]>([]);
const [selectedEdgeIds, setSelectedEdgeIds] = useState<string[]>([]);

// TODO: If we split canvas more, or use refs, etc, this will become unnecessary @KaWaite
useEffect(() => {
fitView({ padding: 0.5 });
}, [currentWorkflowId, fitView]);

const {
canUndo,
canRedo,
Expand Down
2 changes: 0 additions & 2 deletions ui/src/features/PageWrapper/ProjectId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const ProjectIdWrapper: React.FC<Props> = ({ children }) => {
setCurrentProject(project);
}, [project, currentProject, currentWorkspace, setCurrentProject]);

console.log("isloading", isLoading);

return isLoading ? (
<LoadingSplashscreen />
) : !project ? (
Expand Down
2 changes: 0 additions & 2 deletions ui/src/features/PageWrapper/WorkspaceId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const WorkspaceIdWrapper: React.FC<Props> = ({ children }) => {
setCurrentWorkspace(workspace);
}, [workspace, setCurrentWorkspace]);

console.log("isloading", isLoading);

return isLoading ? (
<LoadingSplashscreen />
) : !workspace ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export function removeParentYWorkflowNodePseudoPort(

const parentNodes = parentYNodes.toJSON() as Node[];

const subworkflowNode = parentNodes.find((n) => n.id === currentWorkflowId);
const subworkflowNode = parentNodes.find(
(n) => n.data.subworkflowId === currentWorkflowId,
);
if (!subworkflowNode) return;

const updatedSubworkflowNode: Node = { ...subworkflowNode };
Expand All @@ -33,7 +35,7 @@ export function removeParentYWorkflowNodePseudoPort(

if (portToRemove) {
removeEdgePort(
currentWorkflowId,
updatedSubworkflowNode.id,
parentYWorkflow,
portToRemove.portName,
"target",
Expand All @@ -50,7 +52,7 @@ export function removeParentYWorkflowNodePseudoPort(

if (portToRemove) {
removeEdgePort(
currentWorkflowId,
updatedSubworkflowNode.id,
parentYWorkflow,
portToRemove.portName,
"source",
Expand Down
16 changes: 6 additions & 10 deletions ui/src/lib/yjs/useParentYWorkflow/updateParentYWorkflowEdges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function updateParentYWorkflowEdges(

// Update the subworkflow node with the updated input/output
const subworkflowParentNode = parentNodes.find(
(n) => n.id === currentWorkflowId,
(n) => n.data.subworkflowId === currentWorkflowId,
);
if (!subworkflowParentNode) return;

Expand Down Expand Up @@ -50,9 +50,9 @@ export function updateParentYWorkflowEdges(
const edgeIndex = Array.from(parentYEdges).findIndex((e) => {
const edgeObj = reassembleEdge(e as YEdge);
return edgeType === "source"
? edgeObj.source === currentWorkflowId &&
? edgeObj.source === subworkflowParentNode.id &&
edgeObj.sourceHandle === prevPseudoPort.portName
: edgeObj.target === currentWorkflowId &&
: edgeObj.target === subworkflowParentNode.id &&
edgeObj.targetHandle === prevPseudoPort.portName;
});

Expand All @@ -77,7 +77,7 @@ export function updateParentYWorkflowEdges(
}

export function removeEdgePort(
currentWorkflowId: string,
nodeId: string,
parentYWorkflow: YWorkflow,
portName: string,
type: "source" | "target",
Expand All @@ -91,14 +91,10 @@ export function removeEdgePort(
const updatedEdges = edgesArray.filter((edgeObj) => {
if (type === "source") {
return !(
edgeObj.source === currentWorkflowId &&
edgeObj.sourceHandle === portName
edgeObj.source === nodeId && edgeObj.sourceHandle === portName
);
}
return !(
edgeObj.target === currentWorkflowId &&
edgeObj.targetHandle === portName
);
return !(edgeObj.target === nodeId && edgeObj.targetHandle === portName);
});

const newYEdges = updatedEdges.map((edgeObj) => yEdgeConstructor(edgeObj));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function updateParentYWorkflowNode(

// Update the subworkflow node with the updated input/output
const parentNodeIndex = parentNodes.findIndex(
(n) => n.id === currentWorkflowId,
(n) => n.data.subworkflowId === currentWorkflowId,
);
const subworkflowParentNode = parentNodes[parentNodeIndex];

Expand Down
4 changes: 3 additions & 1 deletion ui/src/lib/yjs/useYNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ export default ({

const parentWorkflowIndex = rawWorkflows.findIndex((w) => {
const nodes = w.nodes as Node[];
return nodes.some((n) => n.id === currentWorkflowId);
return nodes.some(
(n) => n.data.subworkflowId === currentWorkflowId,
);
});
const parentYWorkflow = yWorkflows.get(parentWorkflowIndex);

Expand Down

0 comments on commit b81f662

Please sign in to comment.