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

Function useDuplicateWorkflowMutation

apps/sim/hooks/queries/workflows.ts:327–458  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

325}
326
327export function useDuplicateWorkflowMutation() {
328 const queryClient = useQueryClient()
329
330 return useMutation({
331 mutationFn: async (
332 variables: DuplicateWorkflowVariables
333 ): Promise<DuplicateWorkflowMutationData> => {
334 const { workspaceId, sourceId, name, description, folderId, newId } = variables
335
336 logger.info(`Duplicating workflow ${sourceId} in workspace: ${workspaceId}`)
337
338 const duplicatedWorkflow = await requestJson(duplicateWorkflowContract, {
339 params: { id: sourceId },
340 body: {
341 name,
342 description,
343 workspaceId,
344 folderId: folderId ?? null,
345 newId,
346 },
347 })
348
349 logger.info(`Successfully duplicated workflow ${sourceId} to ${duplicatedWorkflow.id}`, {
350 blocksCount: duplicatedWorkflow.blocksCount,
351 edgesCount: duplicatedWorkflow.edgesCount,
352 subflowsCount: duplicatedWorkflow.subflowsCount,
353 })
354
355 return {
356 id: duplicatedWorkflow.id,
357 name: duplicatedWorkflow.name || name,
358 description: duplicatedWorkflow.description || description,
359 workspaceId,
360 folderId: duplicatedWorkflow.folderId ?? folderId,
361 sortOrder: duplicatedWorkflow.sortOrder ?? 0,
362 locked: duplicatedWorkflow.locked,
363 blocksCount: duplicatedWorkflow.blocksCount || 0,
364 edgesCount: duplicatedWorkflow.edgesCount || 0,
365 subflowsCount: duplicatedWorkflow.subflowsCount || 0,
366 }
367 },
368 onMutate: async (variables) => {
369 await queryClient.cancelQueries({
370 queryKey: workflowKeys.list(variables.workspaceId, 'active'),
371 })
372
373 const snapshot = queryClient.getQueryData<WorkflowMetadata[]>(
374 workflowKeys.list(variables.workspaceId, 'active')
375 )
376 const tempId = variables.newId ?? generateId()
377
378 const currentWorkflows = Object.fromEntries(
379 getWorkflows(variables.workspaceId).map((w) => [w.id, w])
380 )
381 const targetFolderId = variables.folderId ?? null
382
383 const optimistic: WorkflowMetadata = {
384 id: tempId,

Callers 3

panel.tsxFile · 0.90
useDuplicateSelectionFunction · 0.90
useDuplicateWorkflowFunction · 0.90

Calls 9

requestJsonFunction · 0.90
generateIdFunction · 0.90
getWorkflowsFunction · 0.90
getTopInsertionSortOrderFunction · 0.90
getFolderMapFunction · 0.90
invalidateWorkflowListsFunction · 0.90
infoMethod · 0.80
deleteMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected