MCPcopy
hub / github.com/simstudioai/sim / useUpdateWorkflow

Function useUpdateWorkflow

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

Source from the content-addressed store, hash-verified

464}
465
466export function useUpdateWorkflow() {
467 const queryClient = useQueryClient()
468
469 return useMutation({
470 mutationFn: async (variables: UpdateWorkflowVariables) => {
471 const { workflow: updatedWorkflow } = await requestJson(updateWorkflowContract, {
472 params: { id: variables.workflowId },
473 body: variables.metadata,
474 })
475
476 return mapWorkflow(updatedWorkflow)
477 },
478 onMutate: async (variables) => {
479 await queryClient.cancelQueries({
480 queryKey: workflowKeys.list(variables.workspaceId, 'active'),
481 })
482
483 const snapshot = queryClient.getQueryData<WorkflowMetadata[]>(
484 workflowKeys.list(variables.workspaceId, 'active')
485 )
486
487 queryClient.setQueryData<WorkflowMetadata[]>(
488 workflowKeys.list(variables.workspaceId, 'active'),
489 (old) =>
490 (old ?? []).map((w) =>
491 w.id === variables.workflowId
492 ? { ...w, ...variables.metadata, lastModified: new Date() }
493 : w
494 )
495 )
496
497 return { snapshot }
498 },
499 onError: (_error, variables, context) => {
500 if (context?.snapshot) {
501 queryClient.setQueryData(
502 workflowKeys.list(variables.workspaceId, 'active'),
503 context.snapshot
504 )
505 }
506 },
507 onSettled: (_data, _error, variables) => {
508 return invalidateWorkflowLists(queryClient, variables.workspaceId)
509 },
510 })
511}
512
513interface DeleteWorkflowVariables {
514 workspaceId: string

Callers 4

sidebar.tsxFile · 0.90
WorkflowItemFunction · 0.90
workflow.tsxFile · 0.90
ApiInfoModalFunction · 0.90

Calls 3

requestJsonFunction · 0.90
mapWorkflowFunction · 0.90
invalidateWorkflowListsFunction · 0.90

Tested by

no test coverage detected