Skip to content

Commit d4f1518

Browse files
committed
fix(autolayout): pass through gridsize
1 parent 500dcd4 commit d4f1518

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-auto-layout.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createLogger } from '@sim/logger'
33
import { useReactFlow } from 'reactflow'
44
import type { AutoLayoutOptions } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils'
55
import { applyAutoLayoutAndUpdateStore as applyAutoLayoutStandalone } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils'
6+
import { useSnapToGridSize } from '@/hooks/queries/general-settings'
67
import { useCanvasViewport } from '@/hooks/use-canvas-viewport'
78

89
export type { AutoLayoutOptions }
@@ -13,21 +14,28 @@ const logger = createLogger('useAutoLayout')
1314
* Hook providing auto-layout functionality for workflows.
1415
* Binds workflowId context and provides memoized callback for React components.
1516
* Includes automatic fitView animation after successful layout.
17+
* Automatically uses the user's snap-to-grid setting for grid-aligned layout.
1618
*
1719
* Note: This hook requires a ReactFlowProvider ancestor.
1820
*/
1921
export function useAutoLayout(workflowId: string | null) {
2022
const reactFlowInstance = useReactFlow()
2123
const { fitViewToBounds } = useCanvasViewport(reactFlowInstance)
24+
const snapToGridSize = useSnapToGridSize()
2225

2326
const applyAutoLayoutAndUpdateStore = useCallback(
2427
async (options: AutoLayoutOptions = {}) => {
2528
if (!workflowId) {
2629
return { success: false, error: 'No workflow ID provided' }
2730
}
28-
return applyAutoLayoutStandalone(workflowId, options)
31+
// Include gridSize from user's snap-to-grid setting
32+
const optionsWithGrid: AutoLayoutOptions = {
33+
...options,
34+
gridSize: options.gridSize ?? (snapToGridSize > 0 ? snapToGridSize : undefined),
35+
}
36+
return applyAutoLayoutStandalone(workflowId, optionsWithGrid)
2937
},
30-
[workflowId]
38+
[workflowId, snapToGridSize]
3139
)
3240

3341
/**

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface AutoLayoutOptions {
2121
x?: number
2222
y?: number
2323
}
24+
gridSize?: number
2425
}
2526

2627
/**
@@ -62,6 +63,7 @@ export async function applyAutoLayoutAndUpdateStore(
6263
x: options.padding?.x ?? DEFAULT_LAYOUT_PADDING.x,
6364
y: options.padding?.y ?? DEFAULT_LAYOUT_PADDING.y,
6465
},
66+
gridSize: options.gridSize,
6567
}
6668

6769
// Call the autolayout API route

0 commit comments

Comments
 (0)