(state: RegenerateStateInput)
| 808 | } |
| 809 | |
| 810 | export function regenerateWorkflowStateIds(state: RegenerateStateInput): RegenerateStateOutput { |
| 811 | const blockIdMapping = new Map<string, string>() |
| 812 | const edgeIdMapping = new Map<string, string>() |
| 813 | const loopIdMapping = new Map<string, string>() |
| 814 | const parallelIdMapping = new Map<string, string>() |
| 815 | |
| 816 | Object.keys(state.blocks || {}).forEach((oldId) => { |
| 817 | blockIdMapping.set(oldId, generateId()) |
| 818 | }) |
| 819 | |
| 820 | ;(state.edges || []).forEach((edge: Edge) => { |
| 821 | edgeIdMapping.set(edge.id, generateId()) |
| 822 | }) |
| 823 | |
| 824 | Object.keys(state.loops || {}).forEach((oldId) => { |
| 825 | loopIdMapping.set(oldId, generateId()) |
| 826 | }) |
| 827 | |
| 828 | Object.keys(state.parallels || {}).forEach((oldId) => { |
| 829 | parallelIdMapping.set(oldId, generateId()) |
| 830 | }) |
| 831 | |
| 832 | const newBlocks: Record<string, BlockState> = {} |
| 833 | const newEdges: Edge[] = [] |
| 834 | const newLoops: Record<string, Loop> = {} |
| 835 | const newParallels: Record<string, Parallel> = {} |
| 836 | |
| 837 | Object.entries(state.blocks || {}).forEach(([oldId, block]) => { |
| 838 | const newId = blockIdMapping.get(oldId)! |
| 839 | const newBlock: BlockState = { |
| 840 | ...block, |
| 841 | id: newId, |
| 842 | subBlocks: structuredClone(block.subBlocks), |
| 843 | locked: false, |
| 844 | } |
| 845 | |
| 846 | if (newBlock.data?.parentId) { |
| 847 | const newParentId = blockIdMapping.get(newBlock.data.parentId) |
| 848 | if (newParentId) { |
| 849 | newBlock.data = { ...newBlock.data, parentId: newParentId } |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | if (newBlock.subBlocks) { |
| 854 | const updatedSubBlocks: Record<string, BlockState['subBlocks'][string]> = {} |
| 855 | Object.entries(newBlock.subBlocks).forEach(([subId, subBlock]) => { |
| 856 | const updatedSubBlock = { ...subBlock } |
| 857 | |
| 858 | if ( |
| 859 | typeof updatedSubBlock.value === 'string' && |
| 860 | blockIdMapping.has(updatedSubBlock.value) |
| 861 | ) { |
| 862 | updatedSubBlock.value = blockIdMapping.get(updatedSubBlock.value) ?? updatedSubBlock.value |
| 863 | } |
| 864 | |
| 865 | if ( |
| 866 | (updatedSubBlock.type === 'condition-input' || updatedSubBlock.type === 'router-input') && |
| 867 | typeof updatedSubBlock.value === 'string' |
nothing calls this directly
no test coverage detected