feat(auto-layout): local auto layout#1144
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR introduces a local auto-layout feature that replaces server-side API calls with a client-side implementation for workflow positioning. The main changes involve:
-
New local auto-layout implementation (
local-auto-layout.ts) - A comprehensive graph-based positioning algorithm featuring topological sorting, barycentric crossing minimization, intelligent layout direction detection, and proper container node handling -
Control bar integration - Modified the control bar to use
applyLocalAutoLayoutAndUpdateStoreinstead of the server-sideapplyAutoLayoutAndUpdateStorefunction -
Shared configuration - Exported
DEFAULT_AUTO_LAYOUT_OPTIONSfrom the existing auto-layout utility with reduced spacing values (horizontal: 500→250, vertical: 400→200, layer: 700→350) to enable consistent defaults between remote and local implementations
The local implementation maintains the same interface as the server-side version while providing immediate visual feedback without network round-trips. It includes sophisticated features like cycle detection in topological sorting, optimistic updates with rollback capability on errors, and extensive logging for debugging. The algorithm handles complex scenarios including container nodes with relative positioning for children and intelligent viewport-based positioning.
This change aligns with the project's goal of improving user experience by eliminating network latency for auto-layout operations while maintaining full compatibility with existing workflow structures.
PR Description Notes:
- The PR template is incomplete with placeholder text and no actual description of changes
- Missing issue reference, testing details, and type of change selection
- No screenshots provided despite this being a visual UI feature
Confidence score: 3/5
- This PR introduces complex layout logic that may have edge cases with large workflows or unusual node configurations
- Score reflects concerns about hardcoded viewport assumptions, potential performance issues, and complex position calculations that could fail in edge cases
- Pay close attention to the new
local-auto-layout.tsfile, particularly the position calculation logic and container node handling
3 files reviewed, 2 comments
| layoutOptions as { | ||
| strategy: 'smart' | 'hierarchical' | 'layered' | 'force-directed' | ||
| direction: 'horizontal' | 'vertical' | 'auto' | ||
| spacing: { | ||
| horizontal: number | ||
| vertical: number | ||
| layer: number | ||
| } | ||
| alignment: 'start' | 'center' | 'end' | ||
| padding: { | ||
| x: number | ||
| y: number | ||
| } | ||
| } |
There was a problem hiding this comment.
style: Complex type assertion could be avoided with better interface design
Context Used: Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)
| // Handle container node children positioning | ||
| Object.entries(layoutedBlocks).forEach(([blockId, block]) => { | ||
| if (block.data?.parentId) { | ||
| const parent = layoutedBlocks[block.data.parentId] | ||
| if (parent) { | ||
| // Adjust child position relative to parent with padding | ||
| const padding = 50 | ||
| block.position = { | ||
| x: parent.position.x + padding, | ||
| y: parent.position.y + padding + 50, // Extra top padding for container header | ||
| } | ||
| } | ||
| } | ||
| }) |
There was a problem hiding this comment.
logic: Container positioning logic modifies the block object directly, which could cause unintended side effects since it's a reference to the original object
| // Handle container node children positioning | |
| Object.entries(layoutedBlocks).forEach(([blockId, block]) => { | |
| if (block.data?.parentId) { | |
| const parent = layoutedBlocks[block.data.parentId] | |
| if (parent) { | |
| // Adjust child position relative to parent with padding | |
| const padding = 50 | |
| block.position = { | |
| x: parent.position.x + padding, | |
| y: parent.position.y + padding + 50, // Extra top padding for container header | |
| } | |
| } | |
| } | |
| }) | |
| // Handle container node children positioning | |
| Object.entries(layoutedBlocks).forEach(([blockId, block]) => { | |
| if (block.data?.parentId) { | |
| const parent = layoutedBlocks[block.data.parentId] | |
| if (parent) { | |
| // Adjust child position relative to parent with padding | |
| const padding = 50 | |
| layoutedBlocks[blockId] = { | |
| ...block, | |
| position: { | |
| x: parent.position.x + padding, | |
| y: parent.position.y + padding + 50, // Extra top padding for container header | |
| } | |
| } | |
| } | |
| } | |
| }) |
…is for queueing docs in kb (#1143) * improvement(kb): created knowledge, chunks, tags services and use redis for queueing docs in kb * moved directories around * cleanup * bulk create docuemnt records after upload is completed * fix(copilot): send api key to sim agent (#1142) * Fix api key auth * Lint * ack PR comments * added sort by functionality for headers in kb table * updated * test fallback from redis, fix styling * cleanup copilot, fixed tooltips * feat: local auto layout (#1144) * feat: added llms.txt and robots.txt (#1145) * fix(condition-block): edges not following blocks, duplicate issues (#1146) * fix(condition-block): edges not following blocks, duplicate issues * add subblock update to setActiveWorkflow * Update apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/condition-input.tsx Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * fix dependency array * fix(copilot-cleanup): support azure blob upload in copilot, remove dead code & consolidate other copilot files (#1147) * cleanup * support azure blob image upload * imports cleanup * PR comments * ack PR comments * fix key validation * improvement(forwarding+excel): added forwarding and improve excel read (#1136) * added forwarding for outlook * lint * improved excel sheet read * addressed greptile * fixed bodytext getting truncated * fixed any type * added html func --------- Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net> * revert agent const * update docs --------- Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com> Co-authored-by: Emir Karabeg <78010029+emir-karabeg@users.noreply.github.com> Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai> Co-authored-by: Adam Gough <77861281+aadamgough@users.noreply.github.com> Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>
…is for queueing docs in kb (simstudioai#1143) * improvement(kb): created knowledge, chunks, tags services and use redis for queueing docs in kb * moved directories around * cleanup * bulk create docuemnt records after upload is completed * fix(copilot): send api key to sim agent (simstudioai#1142) * Fix api key auth * Lint * ack PR comments * added sort by functionality for headers in kb table * updated * test fallback from redis, fix styling * cleanup copilot, fixed tooltips * feat: local auto layout (simstudioai#1144) * feat: added llms.txt and robots.txt (simstudioai#1145) * fix(condition-block): edges not following blocks, duplicate issues (simstudioai#1146) * fix(condition-block): edges not following blocks, duplicate issues * add subblock update to setActiveWorkflow * Update apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/condition-input.tsx Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * fix dependency array * fix(copilot-cleanup): support azure blob upload in copilot, remove dead code & consolidate other copilot files (simstudioai#1147) * cleanup * support azure blob image upload * imports cleanup * PR comments * ack PR comments * fix key validation * improvement(forwarding+excel): added forwarding and improve excel read (simstudioai#1136) * added forwarding for outlook * lint * improved excel sheet read * addressed greptile * fixed bodytext getting truncated * fixed any type * added html func --------- Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net> * revert agent const * update docs --------- Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com> Co-authored-by: Emir Karabeg <78010029+emir-karabeg@users.noreply.github.com> Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai> Co-authored-by: Adam Gough <77861281+aadamgough@users.noreply.github.com> Co-authored-by: Adam Gough <adamgough@Mac.attlocal.net>
Summary
Adds local auto layout for control-bar auto-layout that looks at the workflow block store for smart layouts.
Type of Change
Checklist