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

Function useActivateDeploymentVersion

apps/sim/hooks/queries/deployments.ts:523–574  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

521 * Invalidates deployment info and versions queries on success.
522 */
523export function useActivateDeploymentVersion() {
524 const queryClient = useQueryClient()
525
526 return useMutation({
527 mutationFn: async ({
528 workflowId,
529 version,
530 }: ActivateVersionVariables): Promise<ActivateVersionResult> => {
531 return requestJson(activateDeploymentVersionContract, {
532 params: { id: workflowId, version },
533 body: { isActive: true },
534 })
535 },
536 onMutate: async ({ workflowId, version }) => {
537 await queryClient.cancelQueries({ queryKey: deploymentKeys.versions(workflowId) })
538
539 const previousVersions = queryClient.getQueryData<DeploymentVersionsResponse>(
540 deploymentKeys.versions(workflowId)
541 )
542
543 if (previousVersions) {
544 queryClient.setQueryData<DeploymentVersionsResponse>(deploymentKeys.versions(workflowId), {
545 versions: previousVersions.versions.map((v) => ({
546 ...v,
547 isActive: v.version === version,
548 })),
549 })
550 }
551
552 return { previousVersions }
553 },
554 onError: (_, variables, context) => {
555 logger.error('Failed to activate deployment version')
556
557 if (context?.previousVersions) {
558 queryClient.setQueryData(
559 deploymentKeys.versions(variables.workflowId),
560 context.previousVersions
561 )
562 }
563 },
564 onSettled: (_data, error, variables) => {
565 if (!error) {
566 logger.info('Deployment version activated', {
567 workflowId: variables.workflowId,
568 version: variables.version,
569 })
570 }
571 return invalidateDeploymentQueries(queryClient, variables.workflowId)
572 },
573 })
574}
575
576/**
577 * Variables for updating public API access

Callers 1

DeployModalFunction · 0.90

Calls 4

requestJsonFunction · 0.90
errorMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected