Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Merge complete loop (#37018)

Saxon Fletcher53cd3e44a7ef
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({