Files
Danny White 476d4a5851 refactor(ui): drop redundant Button variant="default" props (#50161)
## 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
2026-09-11 17:05:26 +10:00

134 lines
4.7 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { CirclePause } from 'lucide-react'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { toast } from 'sonner'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from 'ui'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { useSetProjectStatus } from '@/data/projects/project-detail-query'
import { useProjectPauseMutation } from '@/data/projects/project-pause-mutation'
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import {
useIsHighAvailability,
useIsProjectActive,
useSelectedProjectQuery,
} from '@/hooks/misc/useSelectedProject'
import { PROJECT_STATUS } from '@/lib/constants'
export const PauseProjectButton = () => {
const router = useRouter()
const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
const { setProjectStatus } = useSetProjectStatus()
const isProjectActive = useIsProjectActive()
const isHighAvailability = useIsHighAvailability()
const isProjectUnhealthy = project?.status === PROJECT_STATUS.ACTIVE_UNHEALTHY
const [isModalOpen, setIsModalOpen] = useState(false)
const projectRef = project?.ref ?? ''
const isPaused = project?.status === PROJECT_STATUS.INACTIVE
const { can: canPauseProject } = useAsyncCheckPermissions(
PermissionAction.INFRA_EXECUTE,
'queue_jobs.projects.pause'
)
const isFreePlan = organization?.plan.id === 'free'
const isBranch = Boolean(project?.parent_project_ref)
const entityLabel = isBranch ? 'branch' : 'project'
const { hasAccess: projectPausingAllowedInOrg } = useCheckEntitlements(
'project_pausing',
organization?.slug
)
const { mutate: pauseProject, isPending: isPausing } = useProjectPauseMutation({
onSuccess: (_, variables) => {
setProjectStatus({ ref: variables.ref, status: PROJECT_STATUS.PAUSING })
toast.success('Pausing project...')
router.push(`/project/${projectRef}`)
},
})
const requestPauseProject = () => {
if (!canPauseProject) {
return toast.error(`You do not have the required permissions to pause this ${entityLabel}`)
}
pauseProject({ ref: projectRef })
}
const buttonDisabled =
(!isBranch && !projectPausingAllowedInOrg) ||
project === undefined ||
isPaused ||
!canPauseProject ||
!isProjectActive ||
isHighAvailability
function getTooltipText() {
if (isPaused) {
return `Your ${entityLabel} is already paused`
} else if (isHighAvailability) {
return 'Pausing is unavailable on High Availability projects'
} else if (!canPauseProject) {
return `You need additional permissions to pause this ${entityLabel}`
} else if (isProjectUnhealthy) {
return `Your ${entityLabel} is unhealthy — restart it instead to restore normal operation`
} else if (!isProjectActive) {
return `Unable to pause ${entityLabel} as ${entityLabel} is not active`
} else if (!isBranch && !projectPausingAllowedInOrg && !isFreePlan) {
return 'Projects on a paid plan will always be running'
} else {
return undefined
}
}
return (
<>
<ButtonTooltip
icon={<CirclePause />}
onClick={() => setIsModalOpen(true)}
loading={isPausing}
disabled={buttonDisabled}
tooltip={{
content: {
side: 'bottom',
text: getTooltipText(),
},
}}
>
Pause {entityLabel}
</ButtonTooltip>
<AlertDialog open={isModalOpen} onOpenChange={setIsModalOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Pause {entityLabel}?</AlertDialogTitle>
<AlertDialogDescription>
This {entityLabel} will be unavailable while paused. Paused {entityLabel} can be
resumed for up to 1 year. After that, backups remain available to download.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isPausing}>Cancel</AlertDialogCancel>
<AlertDialogAction disabled={isPausing} onClick={requestPauseProject} variant="danger">
{isPausing ? `Pausing ${entityLabel}...` : `Pause ${entityLabel}`}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
)
}