The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Use new action runs endpoints (#41808)
Joshen Limbddd04bbc670
diff --git a/apps/studio/components/interfaces/BranchManagement/DatabaseDiffPanel.tsx b/apps/studio/components/interfaces/BranchManagement/DatabaseDiffPanel.tsxindex 4748365eeaa..d4162cbe5a6 100644--- a/apps/studio/components/interfaces/BranchManagement/DatabaseDiffPanel.tsx+++ b/apps/studio/components/interfaces/BranchManagement/DatabaseDiffPanel.tsx@@ -1,9 +1,9 @@-import Link from 'next/link'import { CircleAlert, Database, Download, Wind } from 'lucide-react'-import { Card, CardContent, CardHeader, CardTitle, Skeleton, Button } from 'ui'+import Link from 'next/link'import { toast } from 'sonner'-import DiffViewer from 'components/ui/DiffViewer'+import { DiffEditor } from '@/components/ui/DiffEditor'+import { Button, Card, CardContent, CardHeader, CardTitle, Skeleton } from 'ui'interface DatabaseDiffPanelProps {diffContent?: string@@ -13,7 +13,7 @@ interface DatabaseDiffPanelProps {currentBranchRef?: string}-const DatabaseDiffPanel = ({+export const DatabaseDiffPanel = ({diffContent,isLoading,error,@@ -89,10 +89,13 @@ const DatabaseDiffPanel = ({</Button></CardHeader><CardContent className="p-0 h-96">- <DiffViewer language="sql" original="" modified={diffContent} />+ <DiffEditor+ language="sql"+ original=""+ modified={diffContent}+ options={{ readOnly: true }}+ /></CardContent></Card>)}--export default DatabaseDiffPaneldiff --git a/apps/studio/components/interfaces/BranchManagement/EdgeFunctionsDiffPanel.tsx b/apps/studio/components/interfaces/BranchManagement/EdgeFunctionsDiffPanel.tsxindex 2865b092f7b..ff91c7bd837 100644--- a/apps/studio/components/interfaces/BranchManagement/EdgeFunctionsDiffPanel.tsx+++ b/apps/studio/components/interfaces/BranchManagement/EdgeFunctionsDiffPanel.tsx@@ -1,8 +1,9 @@import { Circle, Code, Minus, Plus, Wind } from 'lucide-react'import Link from 'next/link'+import { basename } from 'path'import { useEffect, useMemo, useState } from 'react'-import DiffViewer from 'components/ui/DiffViewer'+import { DiffEditor } from '@/components/ui/DiffEditor'import type { EdgeFunctionBodyData } from 'data/edge-functions/edge-function-body-query'import type {EdgeFunctionsDiffResult,@@ -10,7 +11,6 @@ import type {FileStatus,} from 'hooks/branches/useEdgeFunctionsDiff'import { EMPTY_ARR } from 'lib/void'-import { basename } from 'path'import { Card, CardContent, CardHeader, CardTitle, cn, Skeleton } from 'ui'const EMPTY_FUNCTION_BODY: EdgeFunctionBodyData = {@@ -20,7 +20,6 @@ const EMPTY_FUNCTION_BODY: EdgeFunctionBodyData = {interface EdgeFunctionsDiffPanelProps {diffResults: EdgeFunctionsDiffResultcurrentBranchRef?: string- mainBranchRef?: string}interface FunctionDiffProps {@@ -152,10 +151,11 @@ const FunctionDiff = ({</ul></div><div className="flex-1 min-h-0">- <DiffViewer+ <DiffEditorlanguage={language}original={mainFile?.content || ''}modified={currentFile?.content || ''}+ options={{ readOnly: true }}/></div></div>@@ -164,10 +164,9 @@ const FunctionDiff = ({)}-const EdgeFunctionsDiffPanel = ({+export const EdgeFunctionsDiffPanel = ({diffResults,currentBranchRef,- mainBranchRef,}: EdgeFunctionsDiffPanelProps) => {if (diffResults.isLoading) {return <Skeleton className="h-64" />@@ -240,5 +239,3 @@ const EdgeFunctionsDiffPanel = ({</div>)}--export default EdgeFunctionsDiffPaneldiff --git a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsxindex 2a89db3ffda..93019356fa7 100644--- a/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx+++ b/apps/studio/components/interfaces/BranchManagement/WorkflowLogs.tsx@@ -50,9 +50,7 @@ export const WorkflowLogs = ({ projectRef, status }: WorkflowLogsProps) => {error: workflowRunsError,} = useActionsQuery({ ref: projectRef }, { enabled: isOpen })- const [selectedWorkflowRun, setSelectedWorkflowRun] = useState<ActionRunData | undefined>(- undefined- )+ const [selectedWorkflowRun, setSelectedWorkflowRun] = useState<ActionRunData>()const {data: workflowRunLogs,@@ -61,7 +59,7 @@ export const WorkflowLogs = ({ projectRef, status }: WorkflowLogsProps) => {isError: isWorkflowRunLogsError,error: workflowRunLogsError,} = useActionRunLogsQuery(- { ref: projectRef, run_id: selectedWorkflowRun?.id ?? '' },+ { projectRef, runId: selectedWorkflowRun?.id },{ enabled: isOpen && Boolean(selectedWorkflowRun) })diff --git a/apps/studio/components/interfaces/BranchManagement/WorkflowLogsCard.tsx b/apps/studio/components/interfaces/BranchManagement/WorkflowLogsCard.tsxindex a3b02ffdfea..f587009de00 100644--- a/apps/studio/components/interfaces/BranchManagement/WorkflowLogsCard.tsx+++ b/apps/studio/components/interfaces/BranchManagement/WorkflowLogsCard.tsx@@ -2,21 +2,11 @@ import { motion } from 'framer-motion'import { CircleDotDashed, GitMerge, X } from 'lucide-react'import { useEffect, useRef } from 'react'+import { ActionRun } from '@/data/actions/action-detail-query'import { Button, Card, CardContent, CardHeader, CardTitle } from 'ui'-interface WorkflowRun {- id: string- status: string- branch_id?: string- check_run_id?: number | null- created_at?: string- updated_at?: string- workdir?: string | null- git_config?: unknown-}-interface WorkflowLogsCardProps {- workflowRun: WorkflowRun | null | undefined+ workflowRun: ActionRun | null | undefinedlogs: string | undefinedisLoading?: booleanonClose?: () => void@@ -27,7 +17,7 @@ interface WorkflowLogsCardProps {overrideAction?: React.ReactNode}-const WorkflowLogsCard = ({+export const WorkflowLogsCard = ({workflowRun,logs,isLoading = false,@@ -46,19 +36,16 @@ const WorkflowLogsCard = ({}}, [logs])- const showSuccessIcon = workflowRun?.status === 'FUNCTIONS_DEPLOYED'- const isFailed =- workflowRun?.status && ['MIGRATIONS_FAILED', 'FUNCTIONS_FAILED'].includes(workflowRun.status)- const isPolling =- workflowRun?.status !== 'FUNCTIONS_DEPLOYED' &&- (!workflowRun?.status ||- !['MIGRATIONS_FAILED', 'FUNCTIONS_FAILED'].includes(workflowRun.status))+ const workflowRunStatus = workflowRun?.status+ const isSuccess = workflowRunStatus === 'SUCCESS'+ const isFailed = workflowRunStatus === 'FAILED'+ const isPolling = workflowRunStatus === 'RUNNING'const displayTitle =overrideTitle ||(isPolling? 'Processing...'- : showSuccessIcon+ : isSuccess? 'Workflow completed successfully': isFailed? 'Workflow failed'@@ -73,13 +60,13 @@ const WorkflowLogsCard = ({><CircleDotDashed size={16} strokeWidth={1.5} className="text-warning" /></motion.div>- ) : showSuccessIcon ? (+ ) : isSuccess ? (<GitMerge size={16} strokeWidth={1.5} className="text-brand" />) : null)return (<Card className="bg-background overflow-hidden h-64 flex flex-col">- <CardHeader className={showSuccessIcon ? 'text-brand' : isFailed ? 'text-destructive' : ''}>+ <CardHeader className={isSuccess ? 'text-brand' : isFailed ? 'text-destructive' : ''}><div className="flex items-center justify-between"><div className="flex items-center gap-4">{displayIcon}@@ -123,5 +110,3 @@ const WorkflowLogsCard = ({</Card>)}--export default WorkflowLogsCarddiff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsxindex 08a86c5c4ef..94268e7b3d3 100644--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx@@ -78,7 +78,7 @@ import UtilityPanel from './UtilityPanel/UtilityPanel'// Load the monaco editor client-side only (does not behave well server-side)const MonacoEditor = dynamic(() => import('./MonacoEditor'), { ssr: false })const DiffEditor = dynamic(- () => import('@monaco-editor/react').then(({ DiffEditor }) => DiffEditor),+ () => import('../../ui/DiffEditor').then(({ DiffEditor }) => DiffEditor),{ ssr: false })@@ -788,7 +788,6 @@ export const SQLEditor = () => {{isDiffOpen && (<div className="w-full h-full"><DiffEditor- theme="supabase"language="pgsql"original={defaultSqlDiff.original}modified={defaultSqlDiff.modified}@@ -796,21 +795,6 @@ export const SQLEditor = () => {diffEditorRef.current = editorsetIsDiffEditorMounted(true)}}- options={{- fontSize: 13,- renderSideBySide: false,- minimap: { enabled: false },- wordWrap: 'on',- lineNumbers: 'on',- folding: false,- padding: { top: 4 },- lineNumbersMinChars: 3,- }}- // [Joshen] These ones are meant to solve a UI issue that seems to only be happening locally- // Happens when you use the inline assistant in the SQL Editor and accept the suggestion- // Error: TextModel got disposed before DiffEditorWidget model got reset- keepCurrentModifiedModel={true}- keepCurrentOriginalModel={true}/>{showWidget && (<ResizableAIWidgetdiff --git a/apps/studio/components/ui/AIEditor/index.tsx b/apps/studio/components/ui/AIEditor/index.tsxindex 38e858ab1ab..6335e6d11ad 100644--- a/apps/studio/components/ui/AIEditor/index.tsx+++ b/apps/studio/components/ui/AIEditor/index.tsx@@ -1,4 +1,4 @@-import Editor, { DiffEditor, Monaco, OnMount } from '@monaco-editor/react'+import Editor, { Monaco, OnMount } from '@monaco-editor/react'import { AnimatePresence, motion } from 'framer-motion'import { Command } from 'lucide-react'import type { editor as monacoEditor } from 'monaco-editor'@@ -9,6 +9,7 @@ import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/Layimport { constructHeaders } from 'data/fetchers'import { detectOS } from 'lib/helpers'import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'+import { DiffEditor } from '../DiffEditor'import ResizableAIWidget from './ResizableAIWidget'interface AIEditorProps {@@ -375,7 +376,6 @@ export const AIEditor = ({{isDiffMode ? (<div className="w-full h-full"><DiffEditor- theme="supabase"language={language}original={diffValue.original}modified={diffValue.modified}@@ -383,10 +383,6 @@ export const AIEditor = ({diffEditorRef.current = editorsetIsDiffEditorMounted(true)}}- options={{- ...defaultOptions,- renderSideBySide: false,- }}/>{isDiffEditorMounted && (<ResizableAIWidgetdiff --git a/apps/studio/components/ui/DiffViewer.tsx b/apps/studio/components/ui/DiffEditor.tsxsimilarity index 54%rename from apps/studio/components/ui/DiffViewer.tsxrename to apps/studio/components/ui/DiffEditor.tsxindex cdb7096ae16..d348ae2d0f8 100644--- a/apps/studio/components/ui/DiffViewer.tsx+++ b/apps/studio/components/ui/DiffEditor.tsx@@ -1,4 +1,4 @@-import { DiffEditor } from '@monaco-editor/react'+import { DiffEditor as BaseDiffEditor } from '@monaco-editor/react'import type { editor as monacoEditor } from 'monaco-editor'interface DiffViewerProps {@@ -7,42 +7,47 @@ interface DiffViewerProps {/** Modified/right hand side content */modified: string | undefined/** Language identifier understood by Monaco */- language: string+ language?: string/** Height for the editor container */height?: string | number- /** Whether to render diffs side-by-side */- sideBySide?: boolean+ /** Diff Editor Options */+ options?: monacoEditor.IStandaloneDiffEditorConstructionOptions+ onMount?: (editor: monacoEditor.IStandaloneDiffEditor) => void}// Centralised set of options so all diff editors look the sameconst DEFAULT_OPTIONS: monacoEditor.IStandaloneDiffEditorConstructionOptions = {- readOnly: true,- renderSideBySide: false,+ fontSize: 13,minimap: { enabled: false },wordWrap: 'on',lineNumbers: 'on',folding: false,- padding: { top: 16, bottom: 16 },lineNumbersMinChars: 3,- fontSize: 13,scrollBeyondLastLine: false,+ renderSideBySide: false,+ padding: { top: 4 },}-export const DiffViewer = ({+export const DiffEditor = ({original = '',modified = '',- language,+ language = 'pgsql',height = '100%',- sideBySide = false,+ options,+ onMount,}: DiffViewerProps) => (- <DiffEditor+ <BaseDiffEditor+ // [Joshen] These ones are meant to solve a UI issue that seems to only be happening locally+ // Happens when you use the inline assistant in the SQL Editor and accept the suggestion+ // Error: TextModel got disposed before DiffEditorWidget model got reset+ keepCurrentOriginalModel+ keepCurrentModifiedModeltheme="supabase"language={language}height={height}original={original}modified={modified}- options={{ ...DEFAULT_OPTIONS, renderSideBySide: sideBySide }}+ options={{ ...DEFAULT_OPTIONS, ...options }}+ onMount={onMount}/>)--export default DiffViewerdiff --git a/apps/studio/data/actions/action-detail-query.ts b/apps/studio/data/actions/action-detail-query.tsindex 1b09c0c40dd..995b1c44621 100644--- a/apps/studio/data/actions/action-detail-query.ts+++ b/apps/studio/data/actions/action-detail-query.ts@@ -1,32 +1,54 @@import { useQuery } from '@tanstack/react-query'-import type { operations } from 'data/api'+import { components } from 'api-types'import { get, handleError } from 'data/fetchers'import type { ResponseError, UseCustomQueryOptions } from 'types'import { actionKeys } from './keys'-export type ActionRunVariables = operations['v1-get-action-run']['parameters']['path']+type ActionRunVariables = {+ projectRef?: string+ runId?: string+}++export type ActionRun = components['schemas']['ActionRunResponse'] & {+ status?: 'SUCCESS' | 'FAILED' | 'RUNNING'+}++export async function getActionRun(+ { projectRef, runId }: ActionRunVariables,+ signal?: AbortSignal+) {+ if (!projectRef) throw new Error('projectRef is required')+ if (!runId) throw new Error('runId is required')-export async function getActionRun(params: ActionRunVariables, signal?: AbortSignal) {const { data, error } = await get('/v1/projects/{ref}/actions/{run_id}', {- params: { path: params },+ params: { path: { ref: projectRef, run_id: runId } },signal,})+if (error) handleError(error)- return data++ const isRunning = data.run_steps.length === 0+ const isSuccess = data?.run_steps.every((x) => ['EXITED', 'PAUSED'].includes(x.status))+ const isFailed = data?.run_steps.some((x) => x.status === 'DEAD')++ return {+ ...data,+ status: isRunning ? 'RUNNING' : isSuccess ? 'SUCCESS' : isFailed ? 'FAILED' : 'RUNNING',+ } as ActionRun}export type ActionRunData = Awaited<ReturnType<typeof getActionRun>>export type ActionRunError = ResponseErrorexport const useActionRunQuery = <TData = ActionRunData>(- { ref, run_id }: ActionRunVariables,+ { projectRef, runId }: ActionRunVariables,{ enabled = true, ...options }: UseCustomQueryOptions<ActionRunData, ActionRunError, TData> = {}) =>useQuery<ActionRunData, ActionRunError, TData>({- queryKey: actionKeys.detail(ref, run_id),- queryFn: ({ signal }) => getActionRun({ ref, run_id }, signal),- enabled: enabled && Boolean(ref) && Boolean(run_id),+ queryKey: actionKeys.detail(projectRef, runId),+ queryFn: ({ signal }) => getActionRun({ projectRef, runId }, signal),+ enabled: enabled && typeof projectRef !== 'undefined' && typeof runId !== 'undefined',staleTime: 0,...options,})diff --git a/apps/studio/data/actions/action-logs-query.ts b/apps/studio/data/actions/action-logs-query.tsindex 20aaecadfa4..817f8e687cf 100644--- a/apps/studio/data/actions/action-logs-query.ts+++ b/apps/studio/data/actions/action-logs-query.ts@@ -1,20 +1,29 @@import { useQuery } from '@tanstack/react-query'-import { operations } from 'data/api'import { get, handleError } from 'data/fetchers'import type { ResponseError, UseCustomQueryOptions } from 'types'import { actionKeys } from './keys'-export type ActionLogsVariables = operations['v1-get-action-run-logs']['parameters']['path']+type ActionLogsVariables = {+ projectRef?: string+ runId?: string+}++export async function getActionRunLogs(+ { projectRef, runId }: ActionLogsVariables,+ signal?: AbortSignal+) {+ if (!projectRef) throw new Error('projectRef is required')+ if (!runId) throw new Error('runId is required')-export async function getActionRunLogs(params: ActionLogsVariables, signal?: AbortSignal) {const { data, error } = await get(`/v1/projects/{ref}/actions/{run_id}/logs`, {- params: { path: params },+ params: { path: { ref: projectRef, run_id: runId } },parseAs: 'text',headers: { Accept: 'text/plain' },signal,})if (error) handleError(error)+return data.split('\n').flatMap((line) => line.split('\r'))@@ -26,16 +35,16 @@ export type ActionLogsData = Awaited<ReturnType<typeof getActionRunLogs>>export type WorkflowRunLogsError = ResponseErrorexport const useActionRunLogsQuery = <TData = ActionLogsData>(- { ref, run_id }: ActionLogsVariables,+ { projectRef, runId }: ActionLogsVariables,{enabled = true,...options}: UseCustomQueryOptions<ActionLogsData, WorkflowRunLogsError, TData> = {}) =>useQuery<ActionLogsData, WorkflowRunLogsError, TData>({- queryKey: actionKeys.detail(ref, run_id),- queryFn: ({ signal }) => getActionRunLogs({ ref, run_id }, signal),- enabled: enabled && Boolean(ref) && Boolean(run_id),+ queryKey: actionKeys.logs(projectRef, runId),+ queryFn: ({ signal }) => getActionRunLogs({ projectRef, runId }, signal),+ enabled: enabled && typeof projectRef !== 'undefined' && typeof runId !== 'undefined',staleTime: 0,...options,})diff --git a/apps/studio/data/actions/keys.ts b/apps/studio/data/actions/keys.tsindex e2e3df04f90..1729a5067f0 100644--- a/apps/studio/data/actions/keys.ts+++ b/apps/studio/data/actions/keys.ts@@ -2,4 +2,6 @@ export const actionKeys = {list: (projectRef: string | undefined) => ['projects', projectRef, 'actions'] as const,detail: (projectRef: string | undefined, runId: string | undefined) =>['projects', projectRef, 'actions', runId] as const,+ logs: (projectRef: string | undefined, runId: string | undefined) =>+ ['projects', projectRef, 'actions', runId, 'logs'] as const,}diff --git a/apps/studio/data/workflow-runs/keys.ts b/apps/studio/data/workflow-runs/keys.tsdeleted file mode 100644index f2877fff875..00000000000--- a/apps/studio/data/workflow-runs/keys.ts+++ /dev/null@@ -1,5 +0,0 @@-export const workflowRunKeys = {- list: (projectRef: string | undefined) => ['projects', projectRef, 'workflow-runs'] as const,- detail: (projectRef: string | undefined, workflowRunId: string | undefined) =>- ['projects', projectRef, 'workflow-run', workflowRunId] as const,-}diff --git a/apps/studio/data/workflow-runs/workflow-run-logs-query.ts b/apps/studio/data/workflow-runs/workflow-run-logs-query.tsdeleted file mode 100644index 0cc924202b2..00000000000--- a/apps/studio/data/workflow-runs/workflow-run-logs-query.ts+++ /dev/null@@ -1,53 +0,0 @@-import { useQuery } from '@tanstack/react-query'--import { get, handleError } from 'data/fetchers'-import type { ResponseError, UseCustomQueryOptions } from 'types'-import { workflowRunKeys } from './keys'--export type WorkflowRunLogsVariables = {- workflowRunId?: string-}--export async function getWorkflowRunLogs(- { workflowRunId }: WorkflowRunLogsVariables,- signal?: AbortSignal-) {- if (!workflowRunId) throw new Error('workflowRunId is required')-- const { data, error } = await get(`/platform/workflow-runs/{workflow_run_id}/logs`, {- params: {- path: {- workflow_run_id: workflowRunId,- },- },- parseAs: 'text',- headers: {- Accept: 'text/plain',- },- signal,- })- if (error) handleError(error)- return data- .split('\n')- .flatMap((line) => line.split('\r'))- .join('\n')- .trim()-}--export type WorkflowRunLogsData = Awaited<ReturnType<typeof getWorkflowRunLogs>>-export type WorkflowRunLogsError = ResponseError--export const useWorkflowRunLogsQuery = <TData = WorkflowRunLogsData>(- { workflowRunId }: WorkflowRunLogsVariables,- {- enabled = true,- ...options- }: UseCustomQueryOptions<WorkflowRunLogsData, WorkflowRunLogsError, TData> = {}-) =>- useQuery<WorkflowRunLogsData, WorkflowRunLogsError, TData>({- queryKey: workflowRunKeys.list(workflowRunId),- queryFn: ({ signal }) => getWorkflowRunLogs({ workflowRunId }, signal),- enabled: enabled && typeof workflowRunId !== 'undefined',- staleTime: 0,- ...options,- })diff --git a/apps/studio/data/workflow-runs/workflow-run-query.ts b/apps/studio/data/workflow-runs/workflow-run-query.tsdeleted file mode 100644index ccd30669785..00000000000--- a/apps/studio/data/workflow-runs/workflow-run-query.ts+++ /dev/null@@ -1,53 +0,0 @@-import { useQuery } from '@tanstack/react-query'--import { get, handleError } from 'data/fetchers'-import type { ResponseError, UseCustomQueryOptions } from 'types'-import { workflowRunKeys } from './keys'--export type WorkflowRunVariables = {- projectRef?: string- workflowRunId?: string-}--export async function getWorkflowRun(- { workflowRunId }: WorkflowRunVariables,- signal?: AbortSignal-): Promise<{ logs: string; workflowRunId: string }> {- if (!workflowRunId) throw new Error('workflowRunId is required')-- // Use the logs endpoint which fetches workflow run status- const { data, error } = await get('/platform/workflow-runs/{workflow_run_id}/logs', {- params: {- path: {- workflow_run_id: workflowRunId,- },- },- parseAs: 'text',- signal,- })-- if (error) {- handleError(error)- }-- // Return an object with the logs and we'll extract status from headers if needed- return { logs: data as string, workflowRunId }-}--export type WorkflowRunData = { logs: string; workflowRunId: string }-export type WorkflowRunError = ResponseError--export const useWorkflowRunQuery = <TData = WorkflowRunData>(- { projectRef, workflowRunId }: WorkflowRunVariables,- {- enabled = true,- ...options- }: UseCustomQueryOptions<WorkflowRunData, WorkflowRunError, TData> = {}-) =>- useQuery<WorkflowRunData, WorkflowRunError, TData>({- queryKey: workflowRunKeys.detail(projectRef, workflowRunId),- queryFn: ({ signal }) => getWorkflowRun({ workflowRunId }, signal),- enabled: enabled && typeof workflowRunId !== 'undefined',- staleTime: 0,- ...options,- })diff --git a/apps/studio/data/workflow-runs/workflow-runs-query.ts b/apps/studio/data/workflow-runs/workflow-runs-query.tsdeleted file mode 100644index 5b36f3679d6..00000000000--- a/apps/studio/data/workflow-runs/workflow-runs-query.ts+++ /dev/null@@ -1,42 +0,0 @@-import { useQuery } from '@tanstack/react-query'--import { get, handleError } from 'data/fetchers'-import type { ResponseError, UseCustomQueryOptions } from 'types'-import { workflowRunKeys } from './keys'--export type WorkflowRunsVariables = {- projectRef?: string-}--export async function getWorkflowRuns({ projectRef }: WorkflowRunsVariables, signal?: AbortSignal) {- if (!projectRef) throw new Error('projectRef is required')-- const { data, error } = await get(`/platform/workflow-runs`, {- params: {- query: {- project_ref: projectRef,- },- },- signal,- })- if (error) handleError(error)- return data-}--export type WorkflowRunsData = Awaited<ReturnType<typeof getWorkflowRuns>>-export type WorkflowRunsError = ResponseError--export const useWorkflowRunsQuery = <TData = WorkflowRunsData>(- { projectRef }: WorkflowRunsVariables,- {- enabled = true,- ...options- }: UseCustomQueryOptions<WorkflowRunsData, WorkflowRunsError, TData> = {}-) =>- useQuery<WorkflowRunsData, WorkflowRunsError, TData>({- queryKey: workflowRunKeys.list(projectRef),- queryFn: ({ signal }) => getWorkflowRuns({ projectRef }, signal),- enabled: enabled && typeof projectRef !== 'undefined',- staleTime: 0,- ...options,- })diff --git a/apps/studio/hooks/branches/useWorkflowManagement.ts b/apps/studio/hooks/branches/useWorkflowManagement.tsindex 2bd1c4e4589..25927e22a0b 100644--- a/apps/studio/hooks/branches/useWorkflowManagement.ts+++ b/apps/studio/hooks/branches/useWorkflowManagement.ts@@ -1,12 +1,12 @@-import { useState, useEffect } from 'react'+import { useEffect, useState } from 'react'-import { useWorkflowRunsQuery } from 'data/workflow-runs/workflow-runs-query'-import { useWorkflowRunQuery } from 'data/workflow-runs/workflow-run-query'+import { useActionRunQuery } from '@/data/actions/action-detail-query'+import { useActionRunLogsQuery } from '@/data/actions/action-logs-query'interface UseWorkflowManagementProps {workflowRunId?: stringprojectRef?: string- onWorkflowComplete?: (status: string) => void+ onWorkflowComplete?: (status: 'SUCCESS' | 'FAILED') => void}export const useWorkflowManagement = ({@@ -16,43 +16,38 @@ export const useWorkflowManagement = ({}: UseWorkflowManagementProps) => {const [hasRefetched, setHasRefetched] = useState(false)- // Get workflow runs and logs- const { data: workflowRuns } = useWorkflowRunsQuery(- { projectRef },+ const { data: workflowRun } = useActionRunQuery(+ { projectRef, runId: workflowRunId },{- enabled: Boolean(workflowRunId),- refetchInterval: 3000,+ refetchInterval: (query) => {+ return query.state.error?.code === 404 ? false : 2000+ },refetchOnMount: 'always',staleTime: 0,})- const { data: workflowRunLogs } = useWorkflowRunQuery(- { projectRef, workflowRunId },+ const { data: workflowRunLogs } = useActionRunLogsQuery(+ { projectRef, runId: workflowRunId },{- refetchInterval: 2000,+ refetchInterval: (query) => {+ return query.state.error?.code === 404 ? false : 2000+ },refetchOnMount: 'always',staleTime: 0,})- // Find current workflow run- const currentWorkflowRun = workflowRuns?.find((run) => run.id === workflowRunId)-// Handle workflow completionuseEffect(() => {- if (!currentWorkflowRun?.status || !workflowRunId) return-- const isComplete = ['FUNCTIONS_DEPLOYED', 'MIGRATIONS_FAILED', 'FUNCTIONS_FAILED'].includes(- currentWorkflowRun.status- )+ if (!workflowRun || !workflowRunId) return// Only refetch once per workflow completion- if (isComplete && !hasRefetched) {+ if (!!workflowRun.status && workflowRun.status !== 'RUNNING' && !hasRefetched) {setHasRefetched(true)- onWorkflowComplete?.(currentWorkflowRun.status)+ onWorkflowComplete?.(workflowRun.status)}- }, [currentWorkflowRun?.status, workflowRunId, hasRefetched, onWorkflowComplete])+ }, [workflowRunId, hasRefetched, onWorkflowComplete, workflowRun])// Reset refetch flag when workflow ID changesuseEffect(() => {@@ -60,7 +55,7 @@ export const useWorkflowManagement = ({}, [workflowRunId])return {- currentWorkflowRun,- workflowRunLogs: workflowRunLogs?.logs,+ run: workflowRun,+ logs: workflowRunLogs,}}diff --git a/apps/studio/pages/project/[ref]/merge.tsx b/apps/studio/pages/project/[ref]/merge.tsxindex 67d42a647b8..556a2681321 100644--- a/apps/studio/pages/project/[ref]/merge.tsx+++ b/apps/studio/pages/project/[ref]/merge.tsx@@ -6,12 +6,12 @@ import { useCallback, useEffect, useMemo, useState } from 'react'import { toast } from 'sonner'import { useParams } from 'common'-import DatabaseDiffPanel from 'components/interfaces/BranchManagement/DatabaseDiffPanel'-import EdgeFunctionsDiffPanel from 'components/interfaces/BranchManagement/EdgeFunctionsDiffPanel'+import { DatabaseDiffPanel } from 'components/interfaces/BranchManagement/DatabaseDiffPanel'+import { EdgeFunctionsDiffPanel } from 'components/interfaces/BranchManagement/EdgeFunctionsDiffPanel'import { OutOfDateNotice } from 'components/interfaces/BranchManagement/OutOfDateNotice'import { ReviewWithAI } from 'components/interfaces/BranchManagement/ReviewWithAI'-import WorkflowLogsCard from 'components/interfaces/BranchManagement/WorkflowLogsCard'-import DefaultLayout from 'components/layouts/DefaultLayout'+import { WorkflowLogsCard } from 'components/interfaces/BranchManagement/WorkflowLogsCard'+import { DefaultLayout } from 'components/layouts/DefaultLayout'import { PageLayout } from 'components/layouts/PageLayout/PageLayout'import { ProjectLayoutWithAuth } from 'components/layouts/ProjectLayout'import { ScaffoldContainer } from 'components/layouts/Scaffold'@@ -40,16 +40,16 @@ import {NavMenu,NavMenuItem,} from 'ui'-import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'+import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'const MergePage: NextPageWithLayout = () => {const router = useRouter()- const { ref } = useParams()+ const { ref, workflow_run_id: currentWorkflowRunId } = useParams()const { data: project } = useSelectedProjectQuery()const { data: selectedOrg } = useSelectedOrganizationQuery()const [isSubmitting, setIsSubmitting] = useState(false)- const [workflowFinalStatus, setWorkflowFinalStatus] = useState<string | null>(null)+ const [workflowFinalStatus, setWorkflowFinalStatus] = useState<'SUCCESS' | 'FAILED' | null>(null)const [showConfirmDialog, setShowConfirmDialog] = useState(false)const isBranch = project?.parent_project_ref !== undefined@@ -90,7 +90,7 @@ const MergePage: NextPageWithLayout = () => {currentBranchRef: ref,parentProjectRef,currentBranchConnectionString: project?.connectionString || undefined,- parentBranchConnectionString: (parentProject as any)?.connectionString || undefined,+ parentBranchConnectionString: parentProject?.connectionString || undefined,currentBranchCreatedAt: currentBranch?.created_at,})@@ -102,10 +102,8 @@ const MergePage: NextPageWithLayout = () => {const clearDiffsOptimistically = edgeFunctionsDiff.clearDiffsOptimistically- const currentWorkflowRunId = router.query.workflow_run_id as string | undefined-const handleCurrentBranchWorkflowComplete = useCallback(- (status: string) => {+ (status: 'SUCCESS' | 'FAILED') => {setWorkflowFinalStatus(status)refetchDiff()clearDiffsOptimistically()@@ -114,7 +112,7 @@ const MergePage: NextPageWithLayout = () => {)const handleParentBranchWorkflowComplete = useCallback(- (status: string) => {+ (status: 'SUCCESS' | 'FAILED') => {setWorkflowFinalStatus(status)refetchDiff()clearDiffsOptimistically()@@ -141,35 +139,24 @@ const MergePage: NextPageWithLayout = () => {])- const { currentWorkflowRun: currentBranchWorkflow, workflowRunLogs: currentBranchLogs } =- useWorkflowManagement({- workflowRunId: currentWorkflowRunId,- projectRef: ref,- onWorkflowComplete: handleCurrentBranchWorkflowComplete,- })+ const { run: currentBranchWorkflow, logs: currentBranchLogs } = useWorkflowManagement({+ workflowRunId: currentWorkflowRunId,+ projectRef: ref,+ onWorkflowComplete: handleCurrentBranchWorkflowComplete,+ })- const { currentWorkflowRun: parentBranchWorkflow, workflowRunLogs: parentBranchLogs } =- useWorkflowManagement({- workflowRunId: currentWorkflowRunId,- projectRef: parentProjectRef,- onWorkflowComplete: handleParentBranchWorkflowComplete,- })+ const { run: parentBranchWorkflow, logs: parentBranchLogs } = useWorkflowManagement({+ workflowRunId: currentWorkflowRunId,+ projectRef: parentProjectRef,+ onWorkflowComplete: handleParentBranchWorkflowComplete,+ })const currentWorkflowRun = currentBranchWorkflow || parentBranchWorkflowconst workflowRunLogs = currentBranchLogs || parentBranchLogs- const hasCurrentWorkflowFailed = workflowFinalStatus- ? ['MIGRATIONS_FAILED', 'FUNCTIONS_FAILED'].includes(workflowFinalStatus)- : currentWorkflowRun?.status &&- ['MIGRATIONS_FAILED', 'FUNCTIONS_FAILED'].includes(currentWorkflowRun.status)-- const hasCurrentWorkflowCompleted = workflowFinalStatus- ? workflowFinalStatus === 'FUNCTIONS_DEPLOYED'- : currentWorkflowRun?.status === 'FUNCTIONS_DEPLOYED'-- const isWorkflowRunning =- currentWorkflowRun?.status === 'RUNNING_MIGRATIONS' ||- currentWorkflowRun?.status === 'CREATING_PROJECT'+ const hasCurrentWorkflowFailed = workflowFinalStatus === 'FAILED'+ const hasCurrentWorkflowCompleted = workflowFinalStatus === 'SUCCESS'+ const isWorkflowRunning = currentWorkflowRun?.status === 'RUNNING'const addWorkflowRun = useCallback((workflowRunId: string) => {@@ -454,25 +441,28 @@ const MergePage: NextPageWithLayout = () => {)const pageTitle = () => (- <span>- Merge{' '}+ <div className="flex items-center gap-x-2">+ <span>Merge</span>+<Link href={`/project/${ref}/editor`}>- <Badge className="font-mono text-lg gap-1">+ <Badge className="font-mono text-sm gap-1 px-2"><GitBranchIcon strokeWidth={1.5} size={16} className="text-foreground-muted" />{currentBranch.name}</Badge>- </Link>{' '}- into{' '}+ </Link>++ <span>into</span>+<Linkhref={`/project/${mainBranch?.project_ref}/editor`}className="font-mono inline-flex gap-4">- <Badge className="font-mono text-lg gap-1">+ <Badge className="font-mono text-sm gap-1 px-2"><Shield strokeWidth={1.5} size={16} className="text-warning" />{mainBranch?.name || 'main'}</Badge></Link>- </span>+ </div>)const pageSubtitle = () => {@@ -542,8 +532,7 @@ const MergePage: NextPageWithLayout = () => {><Link href={`/project/${parentProjectRef}/branches`}>Create new branch</Link></Button>- ) : hasCurrentWorkflowCompleted &&- currentWorkflowRun?.id === parentBranchWorkflow?.id ? (+ ) : hasCurrentWorkflowCompleted ? (<Buttontype="default"onClick={handleCloseBranch}@@ -591,11 +580,7 @@ const MergePage: NextPageWithLayout = () => {currentBranchRef={ref}/>) : (- <EdgeFunctionsDiffPanel- diffResults={edgeFunctionsDiff}- currentBranchRef={ref}- mainBranchRef={parentProjectRef}- />+ <EdgeFunctionsDiffPanel diffResults={edgeFunctionsDiff} currentBranchRef={ref} />)}</ScaffoldContainer>