mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 11:55:05 +03:00
* allow creating branching without git * update branching modals * add account connections * edit branch * copy * update copy * enable branch modal changes * add gitless branching flag * update account connections * merge page * merge experiment * update merge * update pull requests empty state * use diff query * branch diffing * diff query * Clean up * refinements to gitless branching * branching merge and status * link * branch function diffing * update styling * refactor * remove hook * error handling * move * remove enable branching modal * re-add github linker * abstract away enable and disable * toggle fixes * update logic to lean on connection status * update form logic * sheet layout * gitless flag * style and workflow updates * fix side panel size * fix duplicate onerror * copy changes * refetch * merge mutation copy * remove import * add cost * allow connection details on create * initial queries * push button * merge cleanup * Fix TS issues * Fix TS issues * Couple of clean ups * Revert hardcode in useFlag * Fix TS * layout issues and github check * refactor * refactor to use new field * cleanup * style * failed merge * error positioning * refactoring merge * workflow refactor * hook move * clarification with github integration * replace branch dropdown button * update repo picker * updates * remove modal * fix small nits * change defaults * clean up * disable if not gitless and no connection * clean up * always show workflow run id * optimistic * fix branch query * fix issues * fetch edge diff * confirm merge * update edge functions key --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com> Co-authored-by: Alaister Young <a@alaisteryoung.com>
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { useState, useEffect } from 'react'
|
|
|
|
import { useWorkflowRunsQuery } from 'data/workflow-runs/workflow-runs-query'
|
|
import { useWorkflowRunQuery } from 'data/workflow-runs/workflow-run-query'
|
|
|
|
interface UseWorkflowManagementProps {
|
|
workflowRunId?: string
|
|
projectRef?: string
|
|
onWorkflowComplete?: (status: string) => void
|
|
}
|
|
|
|
export const useWorkflowManagement = ({
|
|
workflowRunId,
|
|
projectRef,
|
|
onWorkflowComplete,
|
|
}: UseWorkflowManagementProps) => {
|
|
const [hasRefetched, setHasRefetched] = useState(false)
|
|
|
|
// Get workflow runs and logs
|
|
const { data: workflowRuns } = useWorkflowRunsQuery(
|
|
{ projectRef },
|
|
{
|
|
enabled: Boolean(workflowRunId),
|
|
refetchInterval: 3000,
|
|
refetchOnMount: 'always',
|
|
staleTime: 0,
|
|
}
|
|
)
|
|
|
|
const { data: workflowRunLogs } = useWorkflowRunQuery(
|
|
{ projectRef, workflowRunId },
|
|
{
|
|
refetchInterval: 2000,
|
|
refetchOnMount: 'always',
|
|
staleTime: 0,
|
|
}
|
|
)
|
|
|
|
// Find current workflow run
|
|
const currentWorkflowRun = workflowRuns?.find((run) => run.id === workflowRunId)
|
|
|
|
// Handle workflow completion
|
|
useEffect(() => {
|
|
if (!currentWorkflowRun?.status || !workflowRunId) return
|
|
|
|
const isComplete = ['FUNCTIONS_DEPLOYED', 'MIGRATIONS_FAILED', 'FUNCTIONS_FAILED'].includes(
|
|
currentWorkflowRun.status
|
|
)
|
|
|
|
// Only refetch once per workflow completion
|
|
if (isComplete && !hasRefetched) {
|
|
setHasRefetched(true)
|
|
onWorkflowComplete?.(currentWorkflowRun.status)
|
|
}
|
|
}, [currentWorkflowRun?.status, workflowRunId, hasRefetched, onWorkflowComplete])
|
|
|
|
// Reset refetch flag when workflow ID changes
|
|
useEffect(() => {
|
|
setHasRefetched(false)
|
|
}, [workflowRunId])
|
|
|
|
return {
|
|
currentWorkflowRun,
|
|
workflowRunLogs: workflowRunLogs?.logs,
|
|
}
|
|
}
|