// @ts-nocheck import { LOCAL_STORAGE_KEYS, useParams } from 'common' import dayjs from 'dayjs' import { GitBranchIcon, GitMerge, MoreVertical, Shield } from 'lucide-react' import Link from 'next/link' import { useRouter } from 'next/router' import { useMemo } from 'react' import { toast } from 'sonner' import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from 'ui' import { TimestampInfo } from 'ui-patterns' import { useIsPgDeltaDiffEnabled } from '../App/FeaturePreview/FeaturePreviewContext' import { ReviewWithAI } from '../BranchManagement/ReviewWithAI' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { FeaturePreviewBadge } from '@/components/ui/FeaturePreviewBadge' import { useBranchUpdateMutation } from '@/data/branches/branch-update-mutation' import { useBranchesQuery } from '@/data/branches/branches-query' import { useProjectGitHubConnectionQuery } from '@/data/integrations/github-connections-query' import { useProjectDetailQuery } from '@/data/projects/project-detail-query' import { useSendEventMutation } from '@/data/telemetry/send-event-mutation' import { useBranchMergeDiff } from '@/hooks/branches/useBranchMergeDiff' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' export const MergeTitle = () => { const { ref } = useParams() const { data: project } = useSelectedProjectQuery() const pgDeltaDiffEnabled = useIsPgDeltaDiffEnabled() const parentProjectRef = project?.parent_project_ref const { data: branches } = useBranchesQuery( { projectRef: parentProjectRef }, { refetchOnMount: 'always', refetchOnWindowFocus: true, staleTime: 0, } ) const currentBranch = branches?.find((branch) => branch.project_ref === ref) const mainBranch = branches?.find((branch) => branch.is_default) return (
{currentBranch?.name}
into
{mainBranch?.name || 'main'}
{subtitle}
} export const MergeActions = ({ isWorkflowRunning, isSubmitting, onSelectMerge, }: { isWorkflowRunning: boolean isSubmitting: boolean onSelectMerge: () => void }) => { const router = useRouter() const { ref } = useParams() const { data: project } = useSelectedProjectQuery() const { data: selectedOrg } = useSelectedOrganizationQuery() const { mutate: sendEvent } = useSendEventMutation() const { mutate: updateBranch, isPending: isUpdating } = useBranchUpdateMutation({ onError: (error) => { toast.error(`Failed to update branch: ${error.message}`) }, }) const parentProjectRef = project?.parent_project_ref const { data: parentProject } = useProjectDetailQuery({ ref: parentProjectRef }) const { data: ghConnection } = useProjectGitHubConnectionQuery({ ref: parentProjectRef }) const { data: branches } = useBranchesQuery( { projectRef: parentProjectRef }, { refetchOnMount: 'always', refetchOnWindowFocus: true, staleTime: 0, } ) const currentBranch = branches?.find((branch) => branch.project_ref === ref) const mainBranch = branches?.find((branch) => branch.is_default) const { diffContent, isBranchOutOfDateOverall, isLoading: isCombinedDiffLoading, hasChanges: combinedHasChanges, } = useBranchMergeDiff({ currentBranchRef: ref, parentProjectRef, currentBranchConnectionString: project?.connectionString || undefined, parentBranchConnectionString: parentProject?.connectionString || undefined, currentBranchCreatedAt: currentBranch?.created_at, }) const isMergeDisabled = !combinedHasChanges || isCombinedDiffLoading || isBranchOutOfDateOverall || isWorkflowRunning || (!!ghConnection && Boolean(mainBranch?.git_branch)) return (