File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -156,4 +156,22 @@ describe('folder optimistic top insertion ordering', () => {
156156 expect ( optimisticFolder ) . toBeDefined ( )
157157 expect ( optimisticFolder ?. sortOrder ) . toBe ( 1 )
158158 } )
159+
160+ it ( 'uses source parent scope when duplicate parentId is undefined' , async ( ) => {
161+ const mutation = useDuplicateFolderMutation ( )
162+
163+ await mutation . onMutate ( {
164+ workspaceId : 'ws-1' ,
165+ id : 'folder-parent-match' ,
166+ name : 'Duplicated with inherited parent' ,
167+ // parentId intentionally omitted to mirror duplicate fallback behavior
168+ } )
169+
170+ const optimisticFolder = getOptimisticFolderByName ( 'Duplicated with inherited parent' ) as
171+ | { parentId : string | null ; sortOrder : number }
172+ | undefined
173+ expect ( optimisticFolder ) . toBeDefined ( )
174+ expect ( optimisticFolder ?. parentId ) . toBe ( 'parent-1' )
175+ expect ( optimisticFolder ?. sortOrder ) . toBe ( 1 )
176+ } )
159177} )
Original file line number Diff line number Diff line change @@ -243,19 +243,20 @@ export function useDuplicateFolderMutation() {
243243
244244 // Get source folder info if available
245245 const sourceFolder = previousFolders [ variables . id ]
246+ const targetParentId = variables . parentId ?? sourceFolder ?. parentId ?? null
246247 return {
247248 id : tempId ,
248249 name : variables . name ,
249250 userId : sourceFolder ?. userId || '' ,
250251 workspaceId : variables . workspaceId ,
251- parentId : variables . parentId ?? sourceFolder ?. parentId ?? null ,
252+ parentId : targetParentId ,
252253 color : variables . color || sourceFolder ?. color || '#808080' ,
253254 isExpanded : false ,
254255 sortOrder : getTopInsertionSortOrder (
255256 currentWorkflows ,
256257 previousFolders ,
257258 variables . workspaceId ,
258- variables . parentId
259+ targetParentId
259260 ) ,
260261 createdAt : new Date ( ) ,
261262 updatedAt : new Date ( ) ,
You can’t perform that action at this time.
0 commit comments