Skip to content

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

feat: add a dashboard button to retrigger a branch workflow (#46626)

Gildas Garcia375cbcf4a20d
diff --git a/apps/studio/components/interfaces/BranchManagement/Overview.tsx b/apps/studio/components/interfaces/BranchManagement/Overview.tsx
index af133208449..bec2163e23b 100644
--- a/apps/studio/components/interfaces/BranchManagement/Overview.tsx
+++ b/apps/studio/components/interfaces/BranchManagement/Overview.tsx
@@ -8,6 +8,7 @@ import {
Infinity,
MoreVertical,
Pencil,
+ Redo,
RefreshCw,
Shield,
Trash2,
@@ -30,6 +31,7 @@ import { EditBranchModal } from './EditBranchModal'
import { PreviewBranchesEmptyState } from './EmptyStates'
import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper'
+import { useBranchPushMutation } from '@/data/branches/branch-push-mutation'
import { useBranchQuery } from '@/data/branches/branch-query'
import { useBranchResetMutation } from '@/data/branches/branch-reset-mutation'
import { useBranchRestoreMutation } from '@/data/branches/branch-restore-mutation'
@@ -262,6 +264,7 @@ const PreviewBranchActions = ({
setShowPersistentBranchDeleteConfirmationModal,
] = useState(false)
const [showEditBranchModal, setShowEditBranchModal] = useState(false)
+ const [showConfirmRetriggersModal, setShowConfirmRetriggersModal] = useState(false)
const { mutate: resetBranch, isPending: isResetting } = useBranchResetMutation({
onSuccess() {
@@ -286,6 +289,20 @@ const PreviewBranchActions = ({
},
})
+ const { mutate: branchPushMutate, isPending: isRetriggering } = useBranchPushMutation({
+ onSuccess() {
+ toast.success('Success! Please allow a few minutes for the branch to update.')
+ setShowConfirmRetriggersModal(false)
+ },
+ onError: (data) => {
+ toast.error(`Failed to trigger workflow: ${data.message}`)
+ },
+ })
+
+ const onRetriggerBranch = () => {
+ branchPushMutate({ branchRef, projectRef })
+ }
+
const onRestoreBranch = () => {
restoreBranch({ branchRef, projectRef })
}
@@ -345,28 +362,54 @@ const PreviewBranchActions = ({
</DropdownMenuItemTooltip>
{!branch.deletion_scheduled_at && (
- <DropdownMenuItemTooltip
- className="gap-x-2"
- disabled={isResetting || !isBranchActiveHealthy}
- onSelect={(e) => {
- e.stopPropagation()
- setShowConfirmResetModal(true)
- }}
- onClick={(e) => {
- e.stopPropagation()
- setShowConfirmResetModal(true)
- }}
- tooltip={{
- content: {
- side: 'left',
- text: !isBranchActiveHealthy
- ? 'Branch is still initializing. Please wait for it to become healthy before resetting.'
- : undefined,
- },
- }}
- >
- <RefreshCw size={14} /> Reset branch
- </DropdownMenuItemTooltip>
+ <>
+ <DropdownMenuItemTooltip
+ className="gap-x-2"
+ disabled={!canUpdateBranches || !isBranchActiveHealthy || isUpdatingBranch}
+ onSelect={(e) => {
+ e.stopPropagation()
+ setShowConfirmRetriggersModal(true)
+ }}
+ onClick={(e) => {
+ e.stopPropagation()
+ setShowConfirmRetriggersModal(true)
+ }}
+ tooltip={{
+ content: {
+ side: 'left',
+ text: !canUpdateBranches
+ ? `You need additional permissions to ${branch.git_branch ? 'resync' : 'rebase'} branches`
+ : !isBranchActiveHealthy
+ ? `Branch is still initializing. Please wait for it to become healthy before ${branch.git_branch ? 'resyncing' : 'rebasing'}.`
+ : undefined,
+ },
+ }}
+ >
+ <Redo size={14} /> {branch.git_branch ? 'Resync branch' : 'Rebase branch'}
+ </DropdownMenuItemTooltip>
+ <DropdownMenuItemTooltip
+ className="gap-x-2"
+ disabled={isResetting || !isBranchActiveHealthy}
+ onSelect={(e) => {
+ e.stopPropagation()
+ setShowConfirmResetModal(true)
+ }}
+ onClick={(e) => {
+ e.stopPropagation()
+ setShowConfirmResetModal(true)
+ }}
+ tooltip={{
+ content: {
+ side: 'left',
+ text: !isBranchActiveHealthy
+ ? 'Branch is still initializing. Please wait for it to become healthy before resetting.'
+ : undefined,
+ },
+ }}
+ >
+ <RefreshCw size={14} /> Reset branch
+ </DropdownMenuItemTooltip>
+ </>
)}
{!branch.deletion_scheduled_at && (
@@ -497,10 +540,26 @@ const PreviewBranchActions = ({
</p>
</ConfirmationModal>
+ <ConfirmationModal
+ variant="default"
+ visible={showConfirmRetriggersModal}
+ confirmLabel={branch.git_branch ? 'Resync' : 'Rebase'}
+ title={branch.git_branch ? 'Confirm branch resync' : 'Confirm branch rebase'}
+ loading={isRetriggering}
+ onCancel={() => setShowConfirmRetriggersModal(false)}
+ onConfirm={onRetriggerBranch}
+ >
+ <p className="text-sm text-foreground-light">
+ {branch.git_branch
+ ? 'This will re-run all steps of the workflow based on the latest git branch state.'
+ : 'This will re-run all steps of the workflow based on the latest dashboard state.'}
+ </p>
+ </ConfirmationModal>
+
<ConfirmationModal
variant="warning"
visible={showPersistentBranchDeleteConfirmationModal}
- confirmLabel={'Switch to preview'}
+ confirmLabel="Switch to preview"
title="Branch must be switched to preview before deletion"
loading={isUpdatingBranch}
onCancel={() => setShowPersistentBranchDeleteConfirmationModal(false)}
diff --git a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx
index f5967e6d7be..307289013f2 100644
--- a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx
+++ b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx
@@ -111,7 +111,7 @@ export const WorkflowLogs = ({ branch }: WorkflowLogsProps) => {
(workflowRuns.length > 0 ? (
<ul className="divide-y">
{workflowRuns.map((workflowRun) => (
- <li key={workflowRun.id} className="px-4 py-3">
+ <li key={workflowRun.id} className="flex justify-between px-4 py-3 gap-2">
<button
type="button"
disabled={workflowRun.id === projectRef}
diff --git a/apps/studio/data/branches/branch-push-mutation.ts b/apps/studio/data/branches/branch-push-mutation.ts
index 2a2055a73a9..4d70401f7db 100644
--- a/apps/studio/data/branches/branch-push-mutation.ts
+++ b/apps/studio/data/branches/branch-push-mutation.ts
@@ -1,6 +1,7 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
+import { actionKeys } from '../actions/keys'
import { branchKeys } from './keys'
import { handleError, post } from '@/data/fetchers'
import type { ResponseError, UseCustomMutationOptions } from '@/types'
@@ -36,6 +37,7 @@ export const useBranchPushMutation = ({
async onSuccess(data, variables, context) {
const { projectRef } = variables
await queryClient.invalidateQueries({ queryKey: branchKeys.list(projectRef) })
+ await queryClient.invalidateQueries({ queryKey: actionKeys.list(projectRef) })
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {