Skip to content

Commit 0ac7845

Browse files
authored
feat: improve layout options and make sure nodes and flow have position data (#3231)
* feat: Export needsLayout function for layout handling in reactflowUtils, enhancing node position verification * feat(layoutUtils): Enhance ELK layout options for improved graph rendering and add debug logs for layout verification * feat: Update PageComponent to fit view when viewport is at (0,0) The PageComponent in the FlowPage now fits the view when the viewport is at (0,0). This improves the initial display of the page and enhances the user experience. * feat(uploadFlow): Integrate processDataFromFlow to handle flows during upload, improving data processing efficiency * feat(constants): Update NODE_WIDTH from 384 to 400 for improved component layout and consistency in the user interface * refactor(layoutUtils): Remove debug console logs from getLayoutedNodes
1 parent 72463d9 commit 0ac7845

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

src/frontend/src/constants/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,5 +880,5 @@ export const LANGFLOW_ACCESS_TOKEN_EXPIRE_SECONDS_ENV =
880880
Number(process.env.ACCESS_TOKEN_EXPIRE_SECONDS) -
881881
Number(process.env.ACCESS_TOKEN_EXPIRE_SECONDS) * 0.1;
882882
export const TEXT_FIELD_TYPES: string[] = ["str", "SecretStr"];
883-
export const NODE_WIDTH = 384;
883+
export const NODE_WIDTH = 400;
884884
export const NODE_HEIGHT = NODE_WIDTH * 3;

src/frontend/src/hooks/flows/use-upload-flow.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getObjectsFromFilelist } from "@/helpers/get-objects-from-filelist";
33
import useFlowStore from "@/stores/flowStore";
44
import useFlowsManagerStore from "@/stores/flowsManagerStore";
55
import { FlowType } from "@/types/flow";
6+
import { processDataFromFlow } from "@/utils/reactflowUtils";
67
import useAddFlow from "./use-add-flow";
78

89
const useUploadFlow = () => {
@@ -56,6 +57,10 @@ const useUploadFlow = () => {
5657
}): Promise<void> => {
5758
try {
5859
let flows = await getFlowsToUpload({ files });
60+
for (const flow of flows) {
61+
await processDataFromFlow(flow);
62+
}
63+
5964
if (
6065
isComponent !== undefined &&
6166
flows.every(

src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ export default function Page({
161161

162162
useEffect(() => {
163163
if (reactFlowInstance && currentFlowId) {
164-
reactFlowInstance!.setViewport(viewport);
164+
if (viewport.x == 0 && viewport.y == 0) {
165+
reactFlowInstance.fitView();
166+
} else {
167+
reactFlowInstance.setViewport(viewport);
168+
}
165169
}
166170
}, [currentFlowId, reactFlowInstance]);
167171

src/frontend/src/utils/layoutUtils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import { Edge } from "reactflow";
77
const layoutOptions = {
88
"elk.algorithm": "layered",
99
"elk.direction": "RIGHT",
10+
"elk.components.direction": "DOWN",
1011
"elk.layered.spacing.edgeNodeBetweenLayers": "40",
1112
"elk.spacing.nodeNode": "40",
12-
"elk.layered.nodePlacement.strategy": "SIMPLE",
13+
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
14+
"elk.separateConnectedComponents": true,
15+
"elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
16+
"elk.spacing.componentComponent": `${NODE_WIDTH}`,
17+
"elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
1318
};
1419
const elk = new ELK();
1520

@@ -54,7 +59,6 @@ export const getLayoutedNodes = async (nodes: NodeType[], edges: Edge[]) => {
5459
targets: [e.targetHandle || e.target],
5560
})),
5661
};
57-
5862
const layoutedGraph = await elk.layout(graph);
5963

6064
const layoutedNodes = nodes.map((node) => {
@@ -71,6 +75,5 @@ export const getLayoutedNodes = async (nodes: NodeType[], edges: Edge[]) => {
7175
type: "genericNode",
7276
};
7377
});
74-
7578
return layoutedNodes;
7679
};

src/frontend/src/utils/reactflowUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export const processFlows = (DbData: FlowType[], skipUpdate = true) => {
306306
return { data: savedComponents, flows: DbData };
307307
};
308308

309-
const needsLayout = (nodes: NodeType[]) => {
309+
export const needsLayout = (nodes: NodeType[]) => {
310310
return nodes.some((node) => !node.position);
311311
};
312312

0 commit comments

Comments
 (0)