@@ -62,15 +62,6 @@ function collectWorkflowsInFolder(
6262/**
6363 * Hook for managing folder export to ZIP.
6464 *
65- * Handles:
66- * - Collecting all workflows within a folder (including nested subfolders)
67- * - Fetching workflow data and variables from API
68- * - Sanitizing workflow state for export
69- * - Downloading as ZIP file
70- * - Loading state management
71- * - Error handling and logging
72- * - Clearing selection after export
73- *
7465 * @param props - Hook configuration
7566 * @returns Export folder handlers and state
7667 */
@@ -86,7 +77,7 @@ export function useExportFolder({ workspaceId, getFolderId, onSuccess }: UseExpo
8677 const folderId = getFolderId ( )
8778 if ( ! folderId ) return false
8879 return collectWorkflowsInFolder ( folderId , workflows , folders ) . length > 0
89- } , [ getFolderId , workflows , folders ] )
80+ } , [ workflows , folders ] )
9081
9182 /**
9283 * Download file helper
@@ -117,7 +108,6 @@ export function useExportFolder({ workspaceId, getFolderId, onSuccess }: UseExpo
117108
118109 setIsExporting ( true )
119110 try {
120- // Get fresh folder ID at export time
121111 const folderId = getFolderId ( )
122112 if ( ! folderId ) {
123113 logger . warn ( 'No folder ID provided for export' )
@@ -132,7 +122,6 @@ export function useExportFolder({ workspaceId, getFolderId, onSuccess }: UseExpo
132122 return
133123 }
134124
135- // Collect all workflow IDs recursively
136125 const workflowIdsToExport = collectWorkflowsInFolder ( folderId , workflows , folderStore . folders )
137126
138127 if ( workflowIdsToExport . length === 0 ) {
@@ -148,7 +137,6 @@ export function useExportFolder({ workspaceId, getFolderId, onSuccess }: UseExpo
148137
149138 const exportedWorkflows : Array < { name : string ; content : string } > = [ ]
150139
151- // Export each workflow
152140 for ( const workflowId of workflowIdsToExport ) {
153141 try {
154142 const workflow = workflows [ workflowId ]
@@ -157,7 +145,6 @@ export function useExportFolder({ workspaceId, getFolderId, onSuccess }: UseExpo
157145 continue
158146 }
159147
160- // Fetch workflow state from API
161148 const workflowResponse = await fetch ( `/api/workflows/${ workflowId } ` )
162149 if ( ! workflowResponse . ok ) {
163150 logger . error ( `Failed to fetch workflow ${ workflowId } ` )
@@ -170,15 +157,13 @@ export function useExportFolder({ workspaceId, getFolderId, onSuccess }: UseExpo
170157 continue
171158 }
172159
173- // Fetch workflow variables (API returns Record format directly)
174160 const variablesResponse = await fetch ( `/api/workflows/${ workflowId } /variables` )
175161 let workflowVariables : Record < string , Variable > | undefined
176162 if ( variablesResponse . ok ) {
177163 const variablesData = await variablesResponse . json ( )
178164 workflowVariables = variablesData ?. data
179165 }
180166
181- // Prepare export state
182167 const workflowState = {
183168 ...workflowData . state ,
184169 metadata : {
@@ -212,19 +197,25 @@ export function useExportFolder({ workspaceId, getFolderId, onSuccess }: UseExpo
212197 return
213198 }
214199
215- // Always export as ZIP for folders (even with single workflow)
216200 const zip = new JSZip ( )
201+ const seenFilenames = new Set < string > ( )
217202
218203 for ( const exportedWorkflow of exportedWorkflows ) {
219- const filename = `${ exportedWorkflow . name . replace ( / [ ^ a - z 0 - 9 ] / gi, '-' ) } .json`
204+ const baseName = exportedWorkflow . name . replace ( / [ ^ a - z 0 - 9 ] / gi, '-' )
205+ let filename = `${ baseName } .json`
206+ let counter = 1
207+ while ( seenFilenames . has ( filename ) ) {
208+ filename = `${ baseName } -${ counter } .json`
209+ counter ++
210+ }
211+ seenFilenames . add ( filename )
220212 zip . file ( filename , exportedWorkflow . content )
221213 }
222214
223215 const zipBlob = await zip . generateAsync ( { type : 'blob' } )
224216 const zipFilename = `${ folder . name . replace ( / [ ^ a - z 0 - 9 ] / gi, '-' ) } -export.zip`
225217 downloadFile ( zipBlob , zipFilename , 'application/zip' )
226218
227- // Clear selection after successful export
228219 const { clearSelection } = useFolderStore . getState ( )
229220 clearSelection ( )
230221
0 commit comments