Skip to content

Commit dccd9e9

Browse files
authored
fix(triggers): check triggermode and consolidate block type (#2011)
1 parent b5d9964 commit dccd9e9

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

apps/sim/lib/workflows/triggers.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getBlock } from '@/blocks'
2+
import type { BlockState } from '@/stores/workflows/workflow/types'
23

34
/**
45
* Unified trigger type definitions
@@ -62,14 +63,9 @@ const START_CONFLICT_TYPES: TriggerType[] = [
6263
TRIGGER_TYPES.STARTER, // Legacy starter also conflicts with start_trigger
6364
]
6465

65-
type BlockWithType = { type: string; subBlocks?: Record<string, unknown> | undefined }
66+
type MinimalBlock = { type: string; subBlocks?: Record<string, unknown> | undefined }
6667

67-
type BlockWithMetadata = BlockWithType & {
68-
category?: string
69-
triggers?: { enabled?: boolean }
70-
}
71-
72-
export interface StartBlockCandidate<T extends BlockWithType> {
68+
export interface StartBlockCandidate<T extends MinimalBlock> {
7369
blockId: string
7470
block: T
7571
path: StartBlockPath
@@ -108,20 +104,18 @@ export function classifyStartBlockType(
108104
}
109105
}
110106

111-
export function classifyStartBlock<T extends BlockWithType>(block: T): StartBlockPath | null {
112-
const blockWithMetadata = block as BlockWithMetadata
107+
export function classifyStartBlock<T extends MinimalBlock>(block: T): StartBlockPath | null {
108+
const blockState = block as Partial<BlockState>
113109

114110
// Try to get metadata from the block itself first
115-
let category = blockWithMetadata.category
116-
let triggerModeEnabled = Boolean(blockWithMetadata.triggers?.enabled)
111+
let category: string | undefined
112+
const triggerModeEnabled = Boolean(blockState.triggerMode)
117113

118114
// If not available on the block, fetch from registry
119-
if (!category || triggerModeEnabled === undefined) {
120-
const blockConfig = getBlock(block.type)
121-
if (blockConfig) {
122-
category = category || blockConfig.category
123-
triggerModeEnabled = triggerModeEnabled || Boolean(blockConfig.triggers?.enabled)
124-
}
115+
const blockConfig = getBlock(block.type)
116+
117+
if (blockConfig) {
118+
category = blockConfig.category
125119
}
126120

127121
return classifyStartBlockType(block.type, { category, triggerModeEnabled })
@@ -131,7 +125,7 @@ export function isLegacyStartPath(path: StartBlockPath): boolean {
131125
return path !== StartBlockPath.UNIFIED
132126
}
133127

134-
function toEntries<T extends BlockWithType>(blocks: Record<string, T> | T[]): Array<[string, T]> {
128+
function toEntries<T extends MinimalBlock>(blocks: Record<string, T> | T[]): Array<[string, T]> {
135129
if (Array.isArray(blocks)) {
136130
return blocks.map((block, index) => {
137131
const potentialId = (block as { id?: unknown }).id
@@ -169,7 +163,7 @@ function supportsExecution(path: StartBlockPath, execution: StartExecutionKind):
169163
)
170164
}
171165

172-
export function resolveStartCandidates<T extends BlockWithType>(
166+
export function resolveStartCandidates<T extends MinimalBlock>(
173167
blocks: Record<string, T> | T[],
174168
options: ResolveStartOptions
175169
): StartBlockCandidate<T>[] {

0 commit comments

Comments
 (0)