Skip to content

Commit b2489e6

Browse files
author
waleed
committed
added debug logging
1 parent e0e651c commit b2489e6

File tree

2 files changed

+104
-8
lines changed

2 files changed

+104
-8
lines changed

apps/sim/hooks/use-trigger-config-aggregation.ts

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,57 @@ export function populateTriggerFieldsFromConfig(
9292
triggerId: string | undefined
9393
) {
9494
if (!triggerConfig || !triggerId || !blockId) {
95+
logger.debug('populateTriggerFieldsFromConfig: Skipping - missing params', {
96+
blockId,
97+
triggerId,
98+
hasTriggerConfig: !!triggerConfig,
99+
})
95100
return
96101
}
97102

98103
if (!isTriggerValid(triggerId)) {
104+
logger.debug('populateTriggerFieldsFromConfig: Skipping - invalid trigger', {
105+
blockId,
106+
triggerId,
107+
})
99108
return
100109
}
101110

111+
logger.debug('populateTriggerFieldsFromConfig: Starting migration', {
112+
blockId,
113+
triggerId,
114+
triggerConfigKeys: Object.keys(triggerConfig),
115+
triggerConfig,
116+
})
117+
102118
const triggerDef = getTrigger(triggerId)
103119

104120
const subBlockStore = useSubBlockStore.getState()
105121

122+
let migratedCount = 0
106123
triggerDef.subBlocks
107124
.filter((sb) => sb.mode === 'trigger' && !SYSTEM_SUBBLOCK_IDS.includes(sb.id))
108125
.forEach((subBlock) => {
109126
let configValue: any
110127

111128
if (subBlock.id in triggerConfig) {
112129
configValue = triggerConfig[subBlock.id]
130+
logger.debug('populateTriggerFieldsFromConfig: Found new field name', {
131+
blockId,
132+
subBlockId: subBlock.id,
133+
value: configValue,
134+
})
113135
} else {
114136
for (const [oldFieldName, value] of Object.entries(triggerConfig)) {
115137
const mappedFieldName = mapOldFieldNameToNewSubBlockId(oldFieldName)
116138
if (mappedFieldName === subBlock.id) {
117139
configValue = value
140+
logger.debug('populateTriggerFieldsFromConfig: Mapped old field name', {
141+
blockId,
142+
oldFieldName,
143+
newSubBlockId: subBlock.id,
144+
value: configValue,
145+
})
118146
break
119147
}
120148
}
@@ -124,21 +152,69 @@ export function populateTriggerFieldsFromConfig(
124152
const currentValue = subBlockStore.getValue(blockId, subBlock.id)
125153

126154
let normalizedValue = configValue
127-
if (
128-
(subBlock.id === 'labelIds' || subBlock.id === 'folderIds') &&
129-
typeof configValue === 'string' &&
130-
configValue.trim() !== ''
131-
) {
132-
try {
133-
normalizedValue = JSON.parse(configValue)
134-
} catch {
155+
// Handle array fields - normalize strings to arrays, preserve arrays as-is
156+
if (subBlock.id === 'labelIds' || subBlock.id === 'folderIds') {
157+
if (typeof configValue === 'string' && configValue.trim() !== '') {
158+
try {
159+
normalizedValue = JSON.parse(configValue)
160+
logger.debug('populateTriggerFieldsFromConfig: Parsed string to array', {
161+
blockId,
162+
subBlockId: subBlock.id,
163+
originalValue: configValue,
164+
normalizedValue,
165+
})
166+
} catch {
167+
normalizedValue = [configValue]
168+
logger.debug(
169+
'populateTriggerFieldsFromConfig: Converted string to single-item array',
170+
{
171+
blockId,
172+
subBlockId: subBlock.id,
173+
originalValue: configValue,
174+
normalizedValue,
175+
}
176+
)
177+
}
178+
} else if (
179+
!Array.isArray(configValue) &&
180+
configValue !== null &&
181+
configValue !== undefined
182+
) {
183+
// If it's not already an array and not null/undefined, wrap it
135184
normalizedValue = [configValue]
185+
logger.debug('populateTriggerFieldsFromConfig: Wrapped non-array value in array', {
186+
blockId,
187+
subBlockId: subBlock.id,
188+
originalValue: configValue,
189+
normalizedValue,
190+
})
136191
}
192+
// If it's already an array or null/undefined, use as-is
137193
}
138194

139195
if (currentValue === null || currentValue === undefined || currentValue === '') {
140196
subBlockStore.setValue(blockId, subBlock.id, normalizedValue)
197+
migratedCount++
198+
logger.debug('populateTriggerFieldsFromConfig: Set value', {
199+
blockId,
200+
subBlockId: subBlock.id,
201+
value: normalizedValue,
202+
currentValue,
203+
})
204+
} else {
205+
logger.debug('populateTriggerFieldsFromConfig: Skipped - value already exists', {
206+
blockId,
207+
subBlockId: subBlock.id,
208+
currentValue,
209+
wouldSet: normalizedValue,
210+
})
141211
}
142212
}
143213
})
214+
215+
logger.debug('populateTriggerFieldsFromConfig: Migration complete', {
216+
blockId,
217+
triggerId,
218+
migratedCount,
219+
})
144220
}

apps/sim/stores/workflows/subblock/store.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,32 @@ export const useSubBlockStore = create<SubBlockStore>()(
133133
}
134134

135135
if (!triggerId || !isTriggerValid(triggerId)) {
136+
console.log('[initializeFromWorkflow] Skipping - invalid triggerId', {
137+
blockId,
138+
blockType: block.type,
139+
triggerId,
140+
isTriggerValid: triggerId ? isTriggerValid(triggerId) : false,
141+
})
136142
return
137143
}
138144

139145
const triggerConfigSubBlock = block.subBlocks?.triggerConfig
140146
if (triggerConfigSubBlock?.value && typeof triggerConfigSubBlock.value === 'object') {
147+
console.log('[initializeFromWorkflow] Found triggerConfig, migrating', {
148+
blockId,
149+
triggerId,
150+
triggerConfigKeys: Object.keys(triggerConfigSubBlock.value),
151+
triggerConfig: triggerConfigSubBlock.value,
152+
})
141153
populateTriggerFieldsFromConfig(blockId, triggerConfigSubBlock.value, triggerId)
154+
} else {
155+
console.log('[initializeFromWorkflow] No triggerConfig subblock found', {
156+
blockId,
157+
triggerId,
158+
hasTriggerConfigSubBlock: !!triggerConfigSubBlock,
159+
triggerConfigValue: triggerConfigSubBlock?.value,
160+
allSubBlockIds: Object.keys(block.subBlocks || {}),
161+
})
142162
}
143163
})
144164

0 commit comments

Comments
 (0)