-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(triggers): fix triggers in subflows #1883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryPrevents triggers from being added to loop or parallel subflows through multiple validation layers. Key Changes:
Notes:
Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant Toolbar/Drop
participant Workflow.tsx
participant Store/Hook
participant TriggerUtils
participant Dialog
Note over User,Dialog: Scenario 1: Drop trigger into container
User->>Workflow.tsx: Drop block into container
Workflow.tsx->>Workflow.tsx: Check if containerInfo exists
Workflow.tsx->>Workflow.tsx: Check if block is trigger<br/>(category='triggers' OR triggers.enabled OR enableTriggerMode)
alt Is trigger block
Workflow.tsx->>TriggerUtils: getDefaultTriggerName(type)
TriggerUtils-->>Workflow.tsx: Return trigger name
Workflow.tsx->>Dialog: Show TRIGGER_IN_SUBFLOW warning
Dialog-->>User: Display "Triggers not allowed in subflows"
Note over Workflow.tsx: Early return - block not added
else Not trigger block
Workflow.tsx->>Workflow.tsx: Add block to container
end
Note over User,Dialog: Scenario 2: Drag existing trigger into container
User->>Workflow.tsx: Drag block over container
Workflow.tsx->>Workflow.tsx: onNodeDragStop with potentialParentId
Workflow.tsx->>Workflow.tsx: Get block from blocks[node.id]
Workflow.tsx->>TriggerUtils: isTriggerBlock(block)
TriggerUtils-->>Workflow.tsx: true/false
alt Is trigger block
Workflow.tsx->>TriggerUtils: getDefaultTriggerName(block.type)
TriggerUtils-->>Workflow.tsx: Return trigger name
Workflow.tsx->>Dialog: Show TRIGGER_IN_SUBFLOW warning
Dialog-->>User: Display "Triggers not allowed in subflows"
Workflow.tsx->>Workflow.tsx: Reset drag state (no parent update)
else Not trigger block
Workflow.tsx->>Workflow.tsx: Update parent relationship
end
Note over User,Dialog: Scenario 3: Toggle trigger mode on block in subflow
User->>Store/Hook: Toggle trigger mode
Store/Hook->>Store/Hook: Check if newTriggerMode is true
Store/Hook->>Store/Hook: Check if block.data.parentId exists
Store/Hook->>Store/Hook: Get parent block
alt Parent is loop or parallel
Store/Hook->>Store/Hook: Log warning (store only)
alt In collaborative hook
Store/Hook->>Workflow.tsx: Dispatch 'show-trigger-warning' event
Workflow.tsx->>Dialog: Show TRIGGER_IN_SUBFLOW warning
Dialog-->>User: Display "Triggers not allowed in subflows"
end
Note over Store/Hook: Early return - mode not changed
else Parent not loop/parallel or no parent
Store/Hook->>Store/Hook: Toggle trigger mode
Store/Hook->>Store/Hook: Remove incoming edges if enabling
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 files reviewed, 1 comment
| static isBlockInSubflow<T extends { id: string; data?: { parentId?: string } }>( | ||
| blockId: string, | ||
| blocks: T[] | Record<string, T> | ||
| ): boolean { | ||
| const blockArray = Array.isArray(blocks) ? blocks : Object.values(blocks) | ||
| const block = blockArray.find((b) => b.id === blockId) | ||
|
|
||
| if (!block || !block.data?.parentId) { | ||
| return false | ||
| } | ||
|
|
||
| // Check if the parent is a loop or parallel block | ||
| const parent = blockArray.find((b) => b.id === block.data?.parentId) | ||
| if (!parent) { | ||
| return false | ||
| } | ||
|
|
||
| // Type-safe check: parent must have a 'type' property | ||
| const parentWithType = parent as T & { type?: string } | ||
| return parentWithType.type === 'loop' || parentWithType.type === 'parallel' | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Unused utility - isBlockInSubflow is never called. The same logic is duplicated inline in use-collaborative-workflow.ts:977 and store.ts:1057. Consider either using this utility or removing it to reduce code duplication.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/workflows/triggers.ts
Line: 574:594
Comment:
**style:** Unused utility - `isBlockInSubflow` is never called. The same logic is duplicated inline in `use-collaborative-workflow.ts:977` and `store.ts:1057`. Consider either using this utility or removing it to reduce code duplication.
How can I resolve this? If you propose a fix, please make it concise.
Summary
Prevents adding triggers to subflows
Type of Change
Testing
Manual
Checklist