From 53cd3e44a7ef0edec91cf1026ba587f130ebedc2 Mon Sep 17 00:00:00 2001 From: Saxon Fletcher Date: Thu, 10 Jul 2025 22:33:49 +1000 Subject: [PATCH] Merge complete loop (#37018) * prevent merge complete loop * dependency --- apps/studio/pages/project/[ref]/merge.tsx | 71 ++++++++++++++--------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/apps/studio/pages/project/[ref]/merge.tsx b/apps/studio/pages/project/[ref]/merge.tsx index bd8ca61d489..ccd69fe17df 100644 --- a/apps/studio/pages/project/[ref]/merge.tsx +++ b/apps/studio/pages/project/[ref]/merge.tsx @@ -103,39 +103,67 @@ const MergePage: NextPageWithLayout = () => { currentBranchCreatedAt: currentBranch?.created_at, }) + const { mutate: updateBranch } = useBranchUpdateMutation({ + onSuccess: () => { + toast.success('Branch updated successfully') + }, + onError: (error) => { + toast.error(`Failed to update branch: ${error.message}`) + }, + }) + + const clearDiffsOptimistically = edgeFunctionsDiff.clearDiffsOptimistically + const currentWorkflowRunId = router.query.workflow_run_id as string | undefined useEffect(() => { setWorkflowFinalStatus(null) }, [currentWorkflowRunId]) + const handleCurrentBranchWorkflowComplete = useCallback( + (status: string) => { + setWorkflowFinalStatus(status) + refetchDiff() + clearDiffsOptimistically() + }, + [refetchDiff, clearDiffsOptimistically] + ) + + const handleParentBranchWorkflowComplete = useCallback( + (status: string) => { + setWorkflowFinalStatus(status) + refetchDiff() + clearDiffsOptimistically() + if (parentProjectRef && currentBranch?.id && currentBranch.review_requested_at) { + updateBranch({ + id: currentBranch.id, + projectRef: parentProjectRef, + requestReview: false, + }) + } + }, + [ + refetchDiff, + clearDiffsOptimistically, + parentProjectRef, + currentBranch?.id, + updateBranch, + currentBranch?.review_requested_at, + ] + ) + const { currentWorkflowRun: currentBranchWorkflow, workflowRunLogs: currentBranchLogs } = useWorkflowManagement({ workflowRunId: currentWorkflowRunId, projectRef: ref, - onWorkflowComplete: (status) => { - setWorkflowFinalStatus(status) - refetchDiff() - edgeFunctionsDiff.clearDiffsOptimistically() - }, + onWorkflowComplete: handleCurrentBranchWorkflowComplete, }) const { currentWorkflowRun: parentBranchWorkflow, workflowRunLogs: parentBranchLogs } = useWorkflowManagement({ workflowRunId: currentWorkflowRunId, projectRef: parentProjectRef, - onWorkflowComplete: (status) => { - setWorkflowFinalStatus(status) - refetchDiff() - edgeFunctionsDiff.clearDiffsOptimistically() - if (parentProjectRef && currentBranch?.id) { - updateBranch({ - id: currentBranch.id, - projectRef: parentProjectRef, - requestReview: false, - }) - } - }, + onWorkflowComplete: handleParentBranchWorkflowComplete, }) const currentWorkflowRun = currentBranchWorkflow || parentBranchWorkflow @@ -210,15 +238,6 @@ const MergePage: NextPageWithLayout = () => { }, }) - const { mutate: updateBranch } = useBranchUpdateMutation({ - onSuccess: () => { - toast.success('Branch updated successfully') - }, - onError: (error) => { - toast.error(`Failed to update branch: ${error.message}`) - }, - }) - const handlePush = () => { if (!currentBranch?.id || !parentProjectRef) return pushBranch({