Skip to content

Commit 2a6d4fc

Browse files
fix(deploy): reuse subblock merge helper in use change detection hook (#3287)
* fix(workflow-changes): change detection logic divergence * use shared helper
1 parent 42020c3 commit 2a6d4fc

File tree

1 file changed

+3
-36
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/hooks

1 file changed

+3
-36
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/hooks/use-change-detection.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useMemo } from 'react'
22
import { hasWorkflowChanged } from '@/lib/workflows/comparison'
3+
import { mergeSubblockStateWithValues } from '@/lib/workflows/subblocks'
34
import { useVariablesStore } from '@/stores/panel/variables/store'
45
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
56
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
@@ -42,44 +43,10 @@ export function useChangeDetection({
4243
const currentState = useMemo((): WorkflowState | null => {
4344
if (!workflowId) return null
4445

45-
const blocksWithSubBlocks: WorkflowState['blocks'] = {}
46-
for (const [blockId, block] of Object.entries(blocks)) {
47-
const blockSubValues = subBlockValues?.[blockId] || {}
48-
const subBlocks: Record<string, any> = {}
49-
50-
if (block.subBlocks) {
51-
for (const [subId, subBlock] of Object.entries(block.subBlocks)) {
52-
const storedValue = blockSubValues[subId]
53-
subBlocks[subId] = {
54-
...subBlock,
55-
value: storedValue !== undefined ? storedValue : subBlock.value,
56-
}
57-
}
58-
}
59-
60-
if (block.triggerMode) {
61-
const triggerConfigValue = blockSubValues?.triggerConfig
62-
if (
63-
triggerConfigValue &&
64-
typeof triggerConfigValue === 'object' &&
65-
!subBlocks.triggerConfig
66-
) {
67-
subBlocks.triggerConfig = {
68-
id: 'triggerConfig',
69-
type: 'short-input',
70-
value: triggerConfigValue,
71-
}
72-
}
73-
}
74-
75-
blocksWithSubBlocks[blockId] = {
76-
...block,
77-
subBlocks,
78-
}
79-
}
46+
const mergedBlocks = mergeSubblockStateWithValues(blocks, subBlockValues ?? {})
8047

8148
return {
82-
blocks: blocksWithSubBlocks,
49+
blocks: mergedBlocks,
8350
edges,
8451
loops,
8552
parallels,

0 commit comments

Comments
 (0)