Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • use react query to fetch child workflow schema, avoid refetch and duplicated utils
  • consolidated utils and testing mocks, import from sim/testing instead
  • moved most utils from local state mocks and larger setups to the testing dir, so we can abstract it away and just import it here and don't have to recreate the test fixture every time

Type of Change

  • Bug fix
  • Other: Code maintainability

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 15, 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 15, 2026 9:15pm

Review with Vercel Agent

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 15, 2026

Greptile Summary

Improved workflow input field fetching by implementing React Query for caching and deduplication, consolidated testing utilities and mocks into a reusable @sim/testing package, and eliminated duplicated code across the codebase.

Key improvements:

  • Added useWorkflowInputFields hook with 1-minute cache to prevent redundant API calls when multiple components need child workflow schema
  • Consolidated input format extraction logic into extractInputFieldsFromBlocks utility function used across 4+ different locations
  • Moved normalizeInputFormatValue from separate -utils file into main input-format.ts module
  • Created centralized @sim/testing package with factories, builders, mocks, and assertions
  • Removed ~1500 lines of duplicated mock code from apps/sim/app/api/__test-utils__/utils.ts and apps/sim/executor/__test-utils__/executor-mocks.ts
  • Updated 40+ test files to import from consolidated testing package instead of local mocks
  • Simplified input-mapping.tsx and tool-input.tsx components by removing manual fetch logic with useEffect

Code quality:

  • All changes follow established patterns and maintain backward compatibility
  • Proper TypeScript typing throughout
  • Consistent error handling and validation
  • Good separation of concerns with utility functions

Confidence Score: 5/5

  • Safe to merge with no risks - excellent refactoring that reduces code duplication and improves maintainability
  • This is a well-executed refactoring PR with clear benefits and no breaking changes. The React Query implementation prevents race conditions and provides better UX through caching. The testing utilities consolidation eliminates ~2600 lines of duplicated code while improving test maintainability. All changes follow established patterns and maintain backward compatibility.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/hooks/queries/workflows.ts Added useWorkflowInputFields hook using React Query for caching and deduplication - clean implementation
apps/sim/lib/workflows/input-format.ts Consolidated input format extraction logic with proper validation and type safety
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/input-mapping/input-mapping.tsx Simplified component by replacing local state fetch with React Query hook - removed ~60 lines of duplicated logic
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx Removed duplicated workflow input field extraction logic in favor of shared React Query hook
packages/testing/src/index.ts Central testing utilities package exports - well-documented with comprehensive examples
packages/testing/src/mocks/blocks.mock.ts Consolidated block configuration mocks from scattered test files into reusable package
apps/sim/executor/utils/lazy-cleanup.ts Simplified input field extraction by reusing extractInputFieldsFromBlocks utility
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx Refactored context menu and rename logic using refs to fix state management issues - complex state coordination

Sequence Diagram

sequenceDiagram
    participant UI as Input Mapping Component
    participant Hook as useWorkflowInputFields Hook
    participant RQ as React Query Cache
    participant API as /api/workflows/:id
    participant Util as extractInputFieldsFromBlocks

    UI->>Hook: useWorkflowInputFields(workflowId)
    Hook->>RQ: Check cache for workflowId
    
    alt Cache Hit (< 1 min old)
        RQ-->>Hook: Return cached fields
        Hook-->>UI: Display fields
    else Cache Miss or Stale
        Hook->>API: GET /api/workflows/:workflowId
        API-->>Hook: workflow data with blocks
        Hook->>Util: extractInputFieldsFromBlocks(blocks)
        Util->>Util: Find trigger block (starter/start_trigger/input_trigger)
        Util->>Util: Extract inputFormat from subBlocks or legacy config
        Util->>Util: Filter & validate fields
        Util-->>Hook: Array of {name, type}
        Hook->>RQ: Store in cache (staleTime: 60s)
        Hook-->>UI: Display fields
    end
    
    Note over UI,Util: Other components reusing same hook<br/>get instant cached response
Loading

@waleedlatif1 waleedlatif1 merged commit a35f6ec into staging Jan 15, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/state branch January 15, 2026 21:25
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