mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
## What kind of change does this PR introduce? Mechanical cleanup on top of the Button default-variant change (#50160). ## What is the current behavior? Many callsites still pass `variant="default"` even though that is now the component default. ## What is the new behavior? Removes redundant static `variant="default"` from legacy `Button` and `ButtonTooltip` callsites. Keeps explicit defaults where they document the API: - `button-default.tsx` and `button-sizes.tsx` demos - `DocsButton`, which pins neutral styling at the wrapper boundary ## To test Studio: - [Auth → Rate Limits](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/auth/rate-limits): dirty the form so Cancel appears; Cancel stays neutral, Save stays green - [Project Settings → API Keys](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/settings/api-keys): `DocsButton` in the header actions stays neutral Design system: - [Design system → Button](https://design-system-git-dnywh-dc924ac1-supabase.vercel.app/design-system/docs/components/button): `button-default` / `button-sizes` still show explicit default styling; Primary (green) is restricted to the Primary section (and `asChild`) WWW: - [www → Brand assets](https://zone-www-dot-com-git-dnywh-dc924ac1-supabase.vercel.app/brand-assets): Download logo kit / Download button kit stay neutral
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { useParams } from 'common'
|
|
import { GitMerge } from 'lucide-react'
|
|
import { useRouter } from 'next/router'
|
|
import { toast } from 'sonner'
|
|
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { useBranchUpdateMutation } from '@/data/branches/branch-update-mutation'
|
|
import { useBranchesQuery } from '@/data/branches/branches-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
export const MergeRequestButton = () => {
|
|
const { ref } = useParams()
|
|
const router = useRouter()
|
|
const { data: projectDetails } = useSelectedProjectQuery()
|
|
const track = useTrack()
|
|
|
|
const projectRef = projectDetails?.parent_project_ref || ref
|
|
|
|
const { data: branches } = useBranchesQuery({ projectRef }, { enabled: Boolean(projectDetails) })
|
|
|
|
const { mutate: updateBranch, isPending: isUpdating } = useBranchUpdateMutation({
|
|
onError: () => {
|
|
toast.error(`Failed to open merge request`)
|
|
},
|
|
})
|
|
|
|
const selectedBranch = branches?.find((branch) => branch.project_ref === ref)
|
|
|
|
if (!projectRef || !selectedBranch || selectedBranch.is_default || selectedBranch.git_branch)
|
|
return null
|
|
|
|
const hasReviewRequested = !!selectedBranch.review_requested_at
|
|
const buttonLabel = hasReviewRequested ? 'Review merge request' : 'Open merge request'
|
|
|
|
const handleClick = () => {
|
|
track('header_merge_request_button_clicked', { hasReviewRequested })
|
|
if (hasReviewRequested) {
|
|
router.push(`/project/${selectedBranch.project_ref}/merge`)
|
|
} else {
|
|
updateBranch(
|
|
{
|
|
branchRef: selectedBranch.project_ref,
|
|
projectRef,
|
|
requestReview: true,
|
|
},
|
|
{
|
|
onSuccess: () => {
|
|
toast.success('Merge request created')
|
|
router.push(`/project/${selectedBranch.project_ref}/merge`)
|
|
track('branch_create_merge_request_button_clicked', {
|
|
branchType: selectedBranch.persistent ? 'persistent' : 'preview',
|
|
origin: 'header',
|
|
})
|
|
},
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<ButtonTooltip
|
|
className="rounded-full w-[26px] h-[26px]"
|
|
onClick={handleClick}
|
|
loading={isUpdating}
|
|
tooltip={{
|
|
content: {
|
|
text: buttonLabel,
|
|
side: 'bottom',
|
|
align: 'center',
|
|
},
|
|
}}
|
|
icon={
|
|
<div className="relative">
|
|
{hasReviewRequested && (
|
|
<span className="w-1 h-1 absolute top-0 right-0 rounded-full bg-brand" />
|
|
)}
|
|
<GitMerge size={16} strokeWidth={1.5} />
|
|
</div>
|
|
}
|
|
/>
|
|
)
|
|
}
|