Skip to content

Commit

Permalink
feat: improve layout options and make sure nodes and flow have positi…
Browse files Browse the repository at this point in the history
…on 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
  • Loading branch information
ogabrielluiz authored Aug 7, 2024
1 parent 72463d9 commit 0ac7845
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,5 +880,5 @@ export const LANGFLOW_ACCESS_TOKEN_EXPIRE_SECONDS_ENV =
Number(process.env.ACCESS_TOKEN_EXPIRE_SECONDS) -
Number(process.env.ACCESS_TOKEN_EXPIRE_SECONDS) * 0.1;
export const TEXT_FIELD_TYPES: string[] = ["str", "SecretStr"];
export const NODE_WIDTH = 384;
export const NODE_WIDTH = 400;
export const NODE_HEIGHT = NODE_WIDTH * 3;
5 changes: 5 additions & 0 deletions src/frontend/src/hooks/flows/use-upload-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getObjectsFromFilelist } from "@/helpers/get-objects-from-filelist";
import useFlowStore from "@/stores/flowStore";
import useFlowsManagerStore from "@/stores/flowsManagerStore";
import { FlowType } from "@/types/flow";
import { processDataFromFlow } from "@/utils/reactflowUtils";
import useAddFlow from "./use-add-flow";

const useUploadFlow = () => {
Expand Down Expand Up @@ -56,6 +57,10 @@ const useUploadFlow = () => {
}): Promise<void> => {
try {
let flows = await getFlowsToUpload({ files });
for (const flow of flows) {
await processDataFromFlow(flow);
}

if (
isComponent !== undefined &&
flows.every(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ export default function Page({

useEffect(() => {
if (reactFlowInstance && currentFlowId) {
reactFlowInstance!.setViewport(viewport);
if (viewport.x == 0 && viewport.y == 0) {
reactFlowInstance.fitView();
} else {
reactFlowInstance.setViewport(viewport);
}
}
}, [currentFlowId, reactFlowInstance]);

Expand Down
9 changes: 6 additions & 3 deletions src/frontend/src/utils/layoutUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import { Edge } from "reactflow";
const layoutOptions = {
"elk.algorithm": "layered",
"elk.direction": "RIGHT",
"elk.components.direction": "DOWN",
"elk.layered.spacing.edgeNodeBetweenLayers": "40",
"elk.spacing.nodeNode": "40",
"elk.layered.nodePlacement.strategy": "SIMPLE",
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
"elk.separateConnectedComponents": true,
"elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
"elk.spacing.componentComponent": `${NODE_WIDTH}`,
"elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
};
const elk = new ELK();

Expand Down Expand Up @@ -54,7 +59,6 @@ export const getLayoutedNodes = async (nodes: NodeType[], edges: Edge[]) => {
targets: [e.targetHandle || e.target],
})),
};

const layoutedGraph = await elk.layout(graph);

const layoutedNodes = nodes.map((node) => {
Expand All @@ -71,6 +75,5 @@ export const getLayoutedNodes = async (nodes: NodeType[], edges: Edge[]) => {
type: "genericNode",
};
});

return layoutedNodes;
};
2 changes: 1 addition & 1 deletion src/frontend/src/utils/reactflowUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export const processFlows = (DbData: FlowType[], skipUpdate = true) => {
return { data: savedComponents, flows: DbData };
};

const needsLayout = (nodes: NodeType[]) => {
export const needsLayout = (nodes: NodeType[]) => {
return nodes.some((node) => !node.position);
};

Expand Down

0 comments on commit 0ac7845

Please sign in to comment.