MCPcopy Index your code
hub / github.com/simstudioai/sim / useDuplicateFolderMutation

Function useDuplicateFolderMutation

apps/sim/hooks/queries/folders.ts:258–321  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

256}
257
258export function useDuplicateFolderMutation() {
259 const queryClient = useQueryClient()
260
261 const handlers = createFolderMutationHandlers<DuplicateFolderVariables>(
262 queryClient,
263 'DuplicateFolder',
264 (variables, tempId, previousFolders) => {
265 const currentWorkflows = Object.fromEntries(
266 getWorkflows(variables.workspaceId).map((w) => [w.id, w])
267 )
268
269 const sourceFolder = previousFolders[variables.id]
270 const targetParentId = variables.parentId ?? sourceFolder?.parentId ?? null
271 return {
272 id: tempId,
273 name: variables.name,
274 userId: sourceFolder?.userId || '',
275 workspaceId: variables.workspaceId,
276 parentId: targetParentId,
277 color: variables.color || sourceFolder?.color || '#808080',
278 isExpanded: false,
279 locked: false,
280 sortOrder: getTopInsertionSortOrder(
281 currentWorkflows,
282 previousFolders,
283 variables.workspaceId,
284 targetParentId
285 ),
286 createdAt: new Date(),
287 updatedAt: new Date(),
288 archivedAt: null,
289 }
290 },
291 (variables) => variables.newId ?? generateId()
292 )
293
294 return useMutation({
295 mutationFn: async ({
296 id,
297 workspaceId,
298 name,
299 parentId,
300 color,
301 newId,
302 }: DuplicateFolderVariables): Promise<WorkflowFolder> => {
303 const { folder } = await requestJson(duplicateFolderContract, {
304 params: { id },
305 body: {
306 workspaceId,
307 name,
308 parentId: parentId ?? null,
309 color,
310 newId,
311 },
312 })
313 return mapFolder(folder)
314 },
315 ...handlers,

Callers 3

useDuplicateFolderFunction · 0.90
useDuplicateSelectionFunction · 0.90
folders.test.tsFile · 0.90

Calls 7

getWorkflowsFunction · 0.90
getTopInsertionSortOrderFunction · 0.90
generateIdFunction · 0.90
requestJsonFunction · 0.90
invalidateWorkflowListsFunction · 0.90
mapFolderFunction · 0.70

Tested by

no test coverage detected