Skip to content

Conversation

@waleedlatif1
Copy link
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
Copy link

vercel bot commented Jan 27, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 28, 2026 0:50am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 27, 2026

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

Filename Overview
apps/sim/app/api/workflows/[id]/autolayout/route.ts Added gridSize parameter to API schema with validation (0-50), properly passed to autolayout options
apps/sim/lib/workflows/autolayout/core.ts Added grid snapping after normalization with dimension recalculation, addressing previous review concerns
apps/sim/lib/workflows/autolayout/utils.ts Implemented snapToGrid, snapPositionToGrid, and snapNodesToGrid functions with proper dimension recalculation
apps/sim/lib/workflows/autolayout/targeted.ts Threaded 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

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

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

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

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

Copy link

@cursor cursor bot left a comment

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.

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

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 staging Jan 28, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/autolayout branch January 28, 2026 01:02
Sign up for free to 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.

2 participants