Skip to content

Commit d042fbb

Browse files
committed
use shared helper
1 parent 7c5a6bd commit d042fbb

File tree

1 file changed

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

1 file changed

+3
-31
lines changed

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

Lines changed: 3 additions & 31 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,39 +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-
for (const [subId, value] of Object.entries(blockSubValues)) {
61-
if (!subBlocks[subId] && value !== null && value !== undefined) {
62-
subBlocks[subId] = {
63-
id: subId,
64-
type: 'short-input',
65-
value,
66-
}
67-
}
68-
}
69-
70-
blocksWithSubBlocks[blockId] = {
71-
...block,
72-
subBlocks,
73-
}
74-
}
46+
const mergedBlocks = mergeSubblockStateWithValues(blocks, subBlockValues ?? {})
7547

7648
return {
77-
blocks: blocksWithSubBlocks,
49+
blocks: mergedBlocks,
7850
edges,
7951
loops,
8052
parallels,

0 commit comments

Comments
 (0)