Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ack comment
  • Loading branch information
waleedlatif1 committed Feb 18, 2026
commit 11198015c56e49fbcfc9e71f5476684d65106f58
18 changes: 18 additions & 0 deletions apps/sim/hooks/queries/folders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,22 @@ describe('folder optimistic top insertion ordering', () => {
expect(optimisticFolder).toBeDefined()
expect(optimisticFolder?.sortOrder).toBe(1)
})

it('uses source parent scope when duplicate parentId is undefined', async () => {
const mutation = useDuplicateFolderMutation()

await mutation.onMutate({
workspaceId: 'ws-1',
id: 'folder-parent-match',
name: 'Duplicated with inherited parent',
// parentId intentionally omitted to mirror duplicate fallback behavior
})

const optimisticFolder = getOptimisticFolderByName('Duplicated with inherited parent') as
| { parentId: string | null; sortOrder: number }
| undefined
expect(optimisticFolder).toBeDefined()
expect(optimisticFolder?.parentId).toBe('parent-1')
expect(optimisticFolder?.sortOrder).toBe(1)
})
})
5 changes: 3 additions & 2 deletions apps/sim/hooks/queries/folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,20 @@ export function useDuplicateFolderMutation() {

// Get source folder info if available
const sourceFolder = previousFolders[variables.id]
const targetParentId = variables.parentId ?? sourceFolder?.parentId ?? null
return {
id: tempId,
name: variables.name,
userId: sourceFolder?.userId || '',
workspaceId: variables.workspaceId,
parentId: variables.parentId ?? sourceFolder?.parentId ?? null,
parentId: targetParentId,
color: variables.color || sourceFolder?.color || '#808080',
isExpanded: false,
sortOrder: getTopInsertionSortOrder(
currentWorkflows,
previousFolders,
variables.workspaceId,
variables.parentId
targetParentId
),
createdAt: new Date(),
updatedAt: new Date(),
Expand Down
Loading