|
1 | 1 | import { useMemo } from 'react' |
2 | 2 | import { hasWorkflowChanged } from '@/lib/workflows/comparison' |
| 3 | +import { mergeSubblockStateWithValues } from '@/lib/workflows/subblocks' |
3 | 4 | import { useVariablesStore } from '@/stores/panel/variables/store' |
4 | 5 | import { useSubBlockStore } from '@/stores/workflows/subblock/store' |
5 | 6 | import { useWorkflowStore } from '@/stores/workflows/workflow/store' |
@@ -42,39 +43,10 @@ export function useChangeDetection({ |
42 | 43 | const currentState = useMemo((): WorkflowState | null => { |
43 | 44 | if (!workflowId) return null |
44 | 45 |
|
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 ?? {}) |
75 | 47 |
|
76 | 48 | return { |
77 | | - blocks: blocksWithSubBlocks, |
| 49 | + blocks: mergedBlocks, |
78 | 50 | edges, |
79 | 51 | loops, |
80 | 52 | parallels, |
|
0 commit comments