import dayjs from 'dayjs' import { Github } from 'lucide-react' import Link from 'next/link' import { useRouter } from 'next/router' import { PropsWithChildren, ReactNode } from 'react' import { Tooltip, TooltipContent, TooltipTrigger } from 'ui' import { TimestampInfo } from 'ui-patterns' import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader' import { WorkflowLogs } from './WorkflowLogs' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import type { Branch } from '@/data/branches/branches-query' interface BranchManagementSectionProps { header: string | ReactNode footer?: ReactNode } export const BranchManagementSection = ({ header, footer, children, }: PropsWithChildren) => { return (
{typeof header === 'string' ? {header} : header}
{children}
{footer !== undefined &&
{footer}
}
) } export const BranchRowLoader = () => { return (
) } export const BranchLoader = () => { return ( <> ) } interface BranchRowProps { repo: string label?: string | ReactNode branch: Branch isGithubConnected: boolean rowLink?: string external?: boolean rowActions?: ReactNode } export const BranchRow = ({ branch, isGithubConnected, label, repo, rowLink, external = false, rowActions, }: BranchRowProps) => { const router = useRouter() const page = router.pathname.split('/').pop() const daysFromNow = dayjs().diff(dayjs(branch.updated_at), 'day') const willBeDeletedIn = branch.deletion_scheduled_at ? dayjs(branch.deletion_scheduled_at).diff(dayjs(), 'minutes') : null const isDeletionPending = willBeDeletedIn !== null && willBeDeletedIn < 0 const formattedTimeFromNow = dayjs(branch.updated_at).fromNow() const navigateUrl = rowLink ?? `/project/${branch.project_ref}` return (
{branch.git_branch && isGithubConnected && ( )} {label || branch.name} {((page === 'branches' && !branch.is_default) || page === 'merge-requests') && ( {page === 'branches' && !branch.is_default && 'Switch to branch'} {page === 'merge-requests' && 'View merge request'} )}
{branch.deletion_scheduled_at ? (

{isDeletionPending ? 'Deletion pending...' : `Will be deleted in ${willBeDeletedIn} minutes`}

) : (

{daysFromNow > 1 ? 'Updated on' : 'Updated'}{' '}

)} {rowActions}
) }