import type { Branch } from 'data/branches/branches-query' import dayjs from 'dayjs' import { ArrowLeft, ArrowRight } from 'lucide-react' import { useState } from 'react' import { StatusIcon } from 'ui' import AlertError from 'components/ui/AlertError' import { useWorkflowRunLogsQuery } from 'data/workflow-runs/workflow-run-logs-query' import { useWorkflowRunsQuery } from 'data/workflow-runs/workflow-runs-query' import { Button, cn, Dialog, DialogContent, DialogDescription, DialogHeader, DialogSection, DialogSectionSeparator, DialogTitle, DialogTrigger, } from 'ui' import { GenericSkeletonLoader } from 'ui-patterns' import BranchStatusBadge from './BranchStatusBadge' interface WorkflowLogsProps { projectRef: string status?: Branch['status'] | string } type StatusType = Branch['status'] | string const UNHEALTHY_STATUSES: StatusType[] = [ 'ACTIVE_UNHEALTHY', 'INIT_FAILED', 'UNKNOWN', 'MIGRATIONS_FAILED', 'FUNCTIONS_FAILED', ] export const WorkflowLogs = ({ projectRef, status }: WorkflowLogsProps) => { const [isOpen, setIsOpen] = useState(false) const { data: workflowRuns, isSuccess: isWorkflowRunsSuccess, isLoading: isWorkflowRunsLoading, isError: isWorkflowRunsError, error: workflowRunsError, } = useWorkflowRunsQuery({ projectRef }, { enabled: isOpen }) const [selectedWorkflowRunId, setSelectedWorkflowRunId] = useState(undefined) const { data: workflowRunLogs, isSuccess: isWorkflowRunLogsSuccess, isLoading: isWorkflowRunLogsLoading, isError: isWorkflowRunLogsError, error: workflowRunLogsError, } = useWorkflowRunLogsQuery( { workflowRunId: selectedWorkflowRunId }, { enabled: isOpen && selectedWorkflowRunId !== undefined } ) const showStatusIcon = status !== undefined && status !== 'ACTIVE_HEALTHY' && status !== 'FUNCTIONS_DEPLOYED' && status !== 'MIGRATIONS_PASSED' const isUnhealthy = status !== undefined && UNHEALTHY_STATUSES.includes(status) return ( Workflow Logs Select a workflow run to view logs {selectedWorkflowRunId === undefined ? ( <> {isWorkflowRunsLoading && } {isWorkflowRunsError && (
)} {isWorkflowRunsSuccess && (workflowRuns.length > 0 ? (
    {workflowRuns.map((workflowRun) => (
  • ))}
) : (

No workflow runs found.

))} ) : (
{isWorkflowRunLogsLoading && } {isWorkflowRunLogsError && (
)} {isWorkflowRunLogsSuccess && (
                  {workflowRunLogs}
                
)}
)}
) }