Skip to content

feat(autolayout): add snap-to-grid support - #3031

Merged
waleedlatif1 merged 3 commits into
stagingfrom
improvement/autolayout
Jan 28, 2026
Merged

feat(autolayout): add snap-to-grid support#3031
waleedlatif1 merged 3 commits into
stagingfrom
improvement/autolayout

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Add gridSize option to autolayout that snaps block positions to grid multiples
  • When snap-to-grid is enabled, autolayout now places blocks at valid grid positions
  • Remove unused YAML autolayout API route

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercelBot commented Jan 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentReviewUpdated (UTC)
docsSkippedSkippedJan 28, 2026 0:50am

Request Review

@greptile-apps

greptile-appsBot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR adds snap-to-grid functionality to the autolayout system and removes the unused YAML autolayout API route.

Key Changes:

  • Added gridSize parameter (0-50) to autolayout API with proper validation
  • Implemented grid snapping after position normalization in layoutBlocksCore, with dimension recalculation to ensure accuracy
  • Threaded gridSize through all layout functions: prepareContainerDimensions, layoutContainers, applyTargetedLayout, and computeLayoutPositions
  • Created utility functions snapToGrid, snapPositionToGrid, and snapNodesToGrid for consistent grid snapping behavior
  • Properly addressed previous review concerns by recalculating dimensions after grid snapping (core.ts:426-429)
  • Deleted 108-line unused YAML autolayout route file

Implementation Quality:
The implementation correctly handles grid snapping as a post-processing step after layout calculation, ensuring that the snapping doesn't interfere with the core layout algorithm. The dimension recalculation after snapping prevents container size mismatches that could occur if blocks snap outward from their calculated positions.

Confidence Score: 5/5

  • This PR is safe to merge with high confidence
  • The implementation is clean, well-structured, and addresses previous review concerns. Grid snapping is correctly implemented as a post-processing step with proper dimension recalculation. The gridSize parameter is properly validated and threaded through all necessary functions. Code removal is safe as the YAML route was unused.
  • No files require special attention

Important Files Changed

FilenameOverview
apps/sim/app/api/workflows/[id]/autolayout/route.tsAdded gridSize parameter to API schema with validation (0-50), properly passed to autolayout options
apps/sim/lib/workflows/autolayout/core.tsAdded grid snapping after normalization with dimension recalculation, addressing previous review concerns
apps/sim/lib/workflows/autolayout/utils.tsImplemented snapToGrid, snapPositionToGrid, and snapNodesToGrid functions with proper dimension recalculation
apps/sim/lib/workflows/autolayout/targeted.tsThreaded gridSize through targeted layout flow, applying snapPositionToGrid to final positions

Sequence Diagram

sequenceDiagram
participant API as API Route
participant AL as applyAutoLayout
participant PCD as prepareContainerDimensions
participant LBC as layoutBlocksCore
participant CP as calculatePositions
participant NP as normalizePositions
participant SNG as snapNodesToGrid
participant LC as layoutContainers
API->>API: Parse request with gridSize
API->>AL: applyAutoLayout(blocks, edges, options)
AL->>PCD: prepareContainerDimensions(blocks, edges, gridSize)
loop For each container (bottom-up)
PCD->>LBC: layoutBlocksCore(childBlocks, {gridSize})
LBC->>CP: calculatePositions(layers, edges)
CP-->>LBC: positioned nodes
LBC->>NP: normalizePositions(nodes)
NP-->>LBC: normalized dimensions
LBC->>SNG: snapNodesToGrid(nodes, gridSize)
SNG-->>LBC: updated dimensions
LBC-->>PCD: {nodes, dimensions}
PCD->>PCD: Update container width/height
end
PCD-->>AL: containers sized
AL->>LBC: layoutBlocksCore(rootBlocks, {gridSize})
LBC->>CP: calculatePositions(layers, edges)
CP-->>LBC: positioned nodes
LBC->>NP: normalizePositions(nodes)
NP-->>LBC: normalized dimensions
LBC->>SNG: snapNodesToGrid(nodes, gridSize)
SNG-->>LBC: snapped dimensions
LBC-->>AL: {nodes, dimensions}
AL->>LC: layoutContainers(blocks, edges, {gridSize})
loop For each container
LC->>LBC: layoutBlocksCore(childBlocks, {gridSize})
LBC->>CP: calculatePositions(layers, edges)
CP-->>LBC: positioned nodes
LBC->>NP: normalizePositions(nodes)
NP-->>LBC: normalized dimensions
LBC->>SNG: snapNodesToGrid(nodes, gridSize)
SNG-->>LBC: snapped dimensions
LBC-->>LC: {nodes, dimensions}
LC->>LC: Apply positions & update container dims
end
LC-->>AL: containers laid out
AL-->>API: {blocks: layoutedBlocks, success: true}
Loading

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/lib/workflows/autolayout/core.ts Outdated
Comment threadapps/sim/lib/workflows/autolayout/core.ts Outdated
Comment threadapps/sim/lib/workflows/autolayout/targeted.ts
Comment threadapps/sim/lib/workflows/autolayout/core.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment threadapps/sim/lib/workflows/autolayout/utils.ts
Comment threadapps/sim/lib/workflows/autolayout/index.ts
@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
waleedlatif1 merged commit 7640fdf into stagingJan 28, 2026
12 checks passed
@waleedlatif1
waleedlatif1 deleted the improvement/autolayout branch January 28, 2026 01:02
royceP2 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Mar 3, 2026
* feat(autolayout): add snap-to-grid support
* fix(autolayout): recalculate dimensions after grid snapping
* fix(autolayout): correct dimension calculation and propagate gridSize
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@waleedlatif1