From 0d4849b81270b4e480050f6452d8749ef7114935 Mon Sep 17 00:00:00 2001 From: Adam Gough Date: Sat, 31 May 2025 21:10:18 -0700 Subject: [PATCH] removed comments --- .../deployment-controls.test.ts | 14 ------------- .../workflow-preview/workflow-preview.tsx | 21 ++----------------- .../marketplace/components/workflow-card.tsx | 1 + 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/apps/sim/app/w/[id]/components/control-bar/components/deployment-controls/deployment-controls.test.ts b/apps/sim/app/w/[id]/components/control-bar/components/deployment-controls/deployment-controls.test.ts index b8c58096b9..596b838b09 100644 --- a/apps/sim/app/w/[id]/components/control-bar/components/deployment-controls/deployment-controls.test.ts +++ b/apps/sim/app/w/[id]/components/control-bar/components/deployment-controls/deployment-controls.test.ts @@ -7,7 +7,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -// Mock the workflow registry store const mockDeploymentStatus = { isDeployed: false, needsRedeployment: false, @@ -41,11 +40,9 @@ describe('DeploymentControls Change Detection Logic', () => { describe('needsRedeployment Priority Logic', () => { it('should prioritize parent needsRedeployment over workflow registry', () => { - // Simulate the logic from DeploymentControls component const parentNeedsRedeployment = true const workflowRegistryNeedsRedeployment = false - // The component logic: Trust the parent's change detection const workflowNeedsRedeployment = parentNeedsRedeployment expect(workflowNeedsRedeployment).toBe(true) @@ -60,19 +57,16 @@ describe('DeploymentControls Change Detection Logic', () => { }) it('should maintain consistency with parent state changes', () => { - // Simulate state changes let parentNeedsRedeployment = false let workflowNeedsRedeployment = parentNeedsRedeployment expect(workflowNeedsRedeployment).toBe(false) - // Parent detects changes parentNeedsRedeployment = true workflowNeedsRedeployment = parentNeedsRedeployment expect(workflowNeedsRedeployment).toBe(true) - // Parent clears changes (after redeployment) parentNeedsRedeployment = false workflowNeedsRedeployment = parentNeedsRedeployment @@ -82,7 +76,6 @@ describe('DeploymentControls Change Detection Logic', () => { describe('Deployment Status Integration', () => { it('should handle deployment status correctly', () => { - // Mock deployment status mockDeploymentStatus.isDeployed = true mockDeploymentStatus.needsRedeployment = false @@ -95,7 +88,6 @@ describe('DeploymentControls Change Detection Logic', () => { }) it('should handle missing deployment status', () => { - // Create a separate mock for this test case const tempMockRegistry = { getState: vi.fn(() => ({ getWorkflowDeploymentStatus: vi.fn(() => null), @@ -112,7 +104,6 @@ describe('DeploymentControls Change Detection Logic', () => { expect(deploymentStatus).toBe(null) - // Restore original mock mockWorkflowRegistry.getState = originalMock }) @@ -125,7 +116,6 @@ describe('DeploymentControls Change Detection Logic', () => { .getState() .getWorkflowDeploymentStatus('test-id') - // Should handle undefined properties gracefully const isDeployed = deploymentStatus?.isDeployed || false expect(isDeployed).toBe(false) }) @@ -188,7 +178,6 @@ describe('DeploymentControls Change Detection Logic', () => { it('should handle null activeWorkflowId gracefully', () => { const deploymentStatus = mockWorkflowRegistry.getState().getWorkflowDeploymentStatus(null) - // Should return the mocked result without throwing expect(deploymentStatus).toBeDefined() }) }) @@ -207,16 +196,13 @@ describe('DeploymentControls Change Detection Logic', () => { it('should maintain prop consistency across re-renders', () => { let needsRedeployment = false - // Initial render let componentProps = { needsRedeployment } expect(componentProps.needsRedeployment).toBe(false) - // State change needsRedeployment = true componentProps = { needsRedeployment } expect(componentProps.needsRedeployment).toBe(true) - // State change back needsRedeployment = false componentProps = { needsRedeployment } expect(componentProps.needsRedeployment).toBe(false) diff --git a/apps/sim/app/w/components/workflow-preview/workflow-preview.tsx b/apps/sim/app/w/components/workflow-preview/workflow-preview.tsx index db26014e2d..c81e847c37 100644 --- a/apps/sim/app/w/components/workflow-preview/workflow-preview.tsx +++ b/apps/sim/app/w/components/workflow-preview/workflow-preview.tsx @@ -56,7 +56,6 @@ export function WorkflowPreview({ defaultPosition, defaultZoom, }: WorkflowPreviewProps) { - // Track structure changes efficiently const blocksStructure = useMemo( () => ({ count: Object.keys(workflowState.blocks || {}).length, @@ -89,48 +88,39 @@ export function WorkflowPreview({ [workflowState.edges] ) - // Helper function to calculate absolute position for child blocks const calculateAbsolutePosition = ( block: any, blocks: Record ): { x: number; y: number } => { - // If no parent, use the block's position as-is if (!block.data?.parentId) { return block.position } - // Find the parent block const parentBlock = blocks[block.data.parentId] if (!parentBlock) { logger.warn(`Parent block not found for child block: ${block.id}`) return block.position } - // Recursively calculate parent's absolute position (for nested containers) const parentAbsolutePosition = calculateAbsolutePosition(parentBlock, blocks) - // Add parent's absolute position to child's relative position return { x: parentAbsolutePosition.x + block.position.x, y: parentAbsolutePosition.y + block.position.y, } } - // Transform blocks and loops into ReactFlow nodes const nodes: Node[] = useMemo(() => { const nodeArray: Node[] = [] - // Add block nodes using the same approach as workflow.tsx Object.entries(workflowState.blocks).forEach(([blockId, block]) => { if (!block || !block.type) { logger.warn(`Skipping invalid block: ${blockId}`) return } - // Calculate absolute position for proper preview positioning const absolutePosition = calculateAbsolutePosition(block, workflowState.blocks) - // Handle container nodes (loop and parallel) differently if (block.type === 'loop') { nodeArray.push({ id: block.id, @@ -169,14 +159,12 @@ export function WorkflowPreview({ return } - // Handle regular blocks const blockConfig = getBlock(block.type) if (!blockConfig) { logger.error(`No configuration found for block type: ${block.type}`, { blockId }) return } - // Create a deep clone of subBlocks to avoid any references to the original state const subBlocksClone = block.subBlocks ? cloneDeep(block.subBlocks) : {} nodeArray.push({ @@ -195,14 +183,11 @@ export function WorkflowPreview({ }, }) - // Add children of this block if it's a loop (for nested blocks) if (block.type === 'loop') { - // Find all children of this loop const childBlocks = Object.entries(workflowState.blocks).filter( ([_, childBlock]) => childBlock.data?.parentId === blockId ) - // Add all child blocks to the node array childBlocks.forEach(([childId, childBlock]) => { const childConfig = getBlock(childBlock.type) @@ -210,10 +195,9 @@ export function WorkflowPreview({ nodeArray.push({ id: childId, type: 'workflowBlock', - // Position child blocks relative to the parent position: { - x: block.position.x + 50, // Offset children to the right - y: block.position.y + (childBlock.position?.y || 100), // Preserve vertical positioning + x: block.position.x + 50, + y: block.position.y + (childBlock.position?.y || 100), }, data: { type: childBlock.type, @@ -236,7 +220,6 @@ export function WorkflowPreview({ return nodeArray }, [blocksStructure, loopsStructure, parallelsStructure, showSubBlocks, workflowState.blocks]) - // Transform edges const edges: Edge[] = useMemo(() => { return workflowState.edges.map((edge) => ({ id: edge.id, diff --git a/apps/sim/app/w/marketplace/components/workflow-card.tsx b/apps/sim/app/w/marketplace/components/workflow-card.tsx index d5a12d524f..db7ecd5146 100644 --- a/apps/sim/app/w/marketplace/components/workflow-card.tsx +++ b/apps/sim/app/w/marketplace/components/workflow-card.tsx @@ -100,6 +100,7 @@ export function WorkflowCard({ workflow, onHover }: WorkflowCardProps) { workflowState={{ ...workflow.workflowState, parallels: workflow.workflowState.parallels || {}, + loops: workflow.workflowState.loops || {}, }} />