Files
Danny White 14fe0c0cc8 fix(studio): slightly round split-button corners on focus (#49129)
## What kind of change does this PR introduce?

UI polish for split buttons (primary action + dropdown chevron).
Follow-up to #49055.

## What is the current behavior?

The focus ring sits above the neighbouring half, but the inner edge
stays square, so the ring has two sharp corners at the join.

## What is the new behavior?

On keyboard focus, the squared-off edge uses a slight radius so the ring
matches the outer corners more closely. Resting state is unchanged.
Split-button callsites now share the same join classes as the
design-system example.

| Before | After |
| --- | --- |
| <img width="1030" height="296" alt="43471"
src="https://github.com/user-attachments/assets/9df3bd72-c7ac-4419-ae18-a7e649dc2d66"
/> | <img width="1056" height="276" alt="CleanShot 2026-08-17 at 10 45
09@2x"
src="https://github.com/user-attachments/assets/52e8a4dc-9c52-45ce-b4d0-f0e7b1b75935"
/> |

## To test

Tab to each half (labelled button, then chevron). Inner corners of the
focus ring should be slightly rounded, not square.

1. [Split with
dropdown](https://design-system-git-fix-split-button-focus-radius-supabase.vercel.app/design-system/docs/components/button#split-with-dropdown)
(no login)
2. [Access
Tokens](https://studio-staging-git-fix-split-button-focus-radius-supabase.vercel.app/dashboard/account/tokens)
→ Generate new token
3. Any project on [studio
staging](https://studio-staging-git-fix-split-button-focus-radius-supabase.vercel.app/dashboard/_/settings/general)
→ Settings → General → Restart project

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Accessibility**
  - Added accessible labels to dropdown and export controls.
- Improved keyboard-focus visibility, layering, and rounded edge
treatment across joined buttons and menus.
  - Removed misleading or redundant screen-reader text and titles.

- **Bug Fixes**
- Prevented split-button controls from shrinking or displaying awkward
borders and corners.
- Refined hover and focus behavior for action buttons throughout
settings, database, storage, account, and documentation interfaces.

- **Documentation**
- Clarified guidance for using overflow menus and responsive
split-button actions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-17 17:28:22 +10:00

210 lines
7.3 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useFlag } from 'common'
import { ChevronDown, RefreshCw } from 'lucide-react'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { toast } from 'sonner'
import {
Button,
cn,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from 'ui'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { useSetProjectStatus } from '@/data/projects/project-detail-query'
import { useProjectRestartMutation } from '@/data/projects/project-restart-mutation'
import { useProjectRestartServicesMutation } from '@/data/projects/project-restart-services-mutation'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import {
useIsAwsK8sCloudProvider,
useIsProjectActive,
useSelectedProjectQuery,
} from '@/hooks/misc/useSelectedProject'
import { PROJECT_STATUS } from '@/lib/constants'
import { type ResponseError } from '@/types'
export const RestartServerButton = () => {
const router = useRouter()
const { data: project } = useSelectedProjectQuery()
const isProjectActive = useIsProjectActive()
const isBranch = Boolean(project?.parent_project_ref)
const entityLabel = isBranch ? 'branch' : 'project'
const entityLabelCapitalized = entityLabel.charAt(0).toUpperCase() + entityLabel.slice(1)
const canRestart = isProjectActive || project?.status === PROJECT_STATUS.ACTIVE_UNHEALTHY
const isAwsK8s = useIsAwsK8sCloudProvider()
const { setProjectStatus } = useSetProjectStatus()
const [serviceToRestart, setServiceToRestart] = useState<'project' | 'branch' | 'database'>()
const { projectSettingsRestartProject } = useIsFeatureEnabled([
'project_settings:restart_project',
])
const projectRef = project?.ref ?? ''
const projectRegion = project?.region ?? ''
const projectRestartDisabled = useFlag('disableProjectRestarts')
const { can: canRestartProject } = useAsyncCheckPermissions(
PermissionAction.INFRA_EXECUTE,
'reboot'
)
const { mutate: restartProject, isPending: isRestartingProject } = useProjectRestartMutation({
onSuccess: () => {
onRestartSuccess()
},
onError: (error) => {
onRestartFailed(error, 'project')
},
})
const { mutate: restartProjectServices, isPending: isRestartingServices } =
useProjectRestartServicesMutation({
onSuccess: () => {
onRestartSuccess()
},
onError: (error) => {
onRestartFailed(error, 'database')
},
})
const isLoading = isRestartingProject || isRestartingServices
const hasRestartDropdown = canRestartProject && canRestart && !projectRestartDisabled
const requestProjectRestart = () => {
if (!canRestartProject) {
return toast.error('You do not have the required permissions to restart this project')
}
restartProject({ ref: projectRef })
}
const requestDatabaseRestart = () => {
if (!canRestartProject) {
return toast.error('You do not have the required permissions to restart this project')
}
restartProjectServices({ ref: projectRef, region: projectRegion, services: ['postgresql'] })
}
const onRestartFailed = (error: ResponseError, type: string) => {
toast.error(`Unable to restart ${type}: ${error.message}`)
setServiceToRestart(undefined)
}
const onRestartSuccess = () => {
setProjectStatus({ ref: projectRef, status: PROJECT_STATUS.RESTARTING })
toast.success('Restarting server...')
router.push(`/project/${projectRef}`)
setServiceToRestart(undefined)
}
return (
<>
{projectSettingsRestartProject ? (
<div className="flex w-full @lg:w-auto">
<ButtonTooltip
variant="default"
className={cn(
'flex-1 px-3 hover:z-10 focus-visible:z-10 @lg:flex-none',
canRestartProject && canRestart ? 'rounded-r-none focus-visible:rounded-r-sm' : ''
)}
disabled={
project === undefined ||
!canRestartProject ||
!canRestart ||
projectRestartDisabled ||
isAwsK8s
}
onClick={() => setServiceToRestart(entityLabel)}
tooltip={{
content: {
side: 'bottom',
text: projectRestartDisabled
? `${entityLabelCapitalized} restart is currently disabled`
: !canRestartProject
? `You need additional permissions to restart this ${entityLabel}`
: !canRestart
? `Unable to restart ${entityLabel} as ${entityLabel} is not active`
: isAwsK8s
? `${entityLabelCapitalized} restart is not supported for AWS (Revamped) projects`
: undefined,
},
}}
>
Restart {entityLabel}
</ButtonTooltip>
{hasRestartDropdown && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="default"
aria-label={`Restart ${entityLabel}`}
className="shrink-0 rounded-l-none px-[4px] py-[5px] -ml-px focus-visible:z-10 focus-visible:rounded-l-sm"
icon={<ChevronDown />}
disabled={!canRestartProject}
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" side="bottom">
<DropdownMenuItem
key="database"
disabled={isLoading}
onClick={() => {
setServiceToRestart('database')
}}
>
<div className="space-y-0.5">
<p className="block text-foreground">Fast database reboot</p>
<p className="block text-foreground-light">
Restarts only the database. Faster, but may not be able to recover from all
failure modes.
</p>
</div>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)}
</div>
) : (
<Button
variant="default"
icon={<RefreshCw />}
className="w-full @lg:w-auto"
disabled={isLoading}
onClick={() => {
setServiceToRestart('database')
}}
>
Restart database
</Button>
)}
<ConfirmationModal
visible={serviceToRestart !== undefined}
variant="destructive"
title={`Restart ${serviceToRestart}`}
description={
<>
Are you sure you want to restart your {serviceToRestart}? There will be a few minutes of
downtime.
</>
}
confirmLabel="Restart"
confirmLabelLoading="Restarting"
loading={isLoading}
onCancel={() => setServiceToRestart(undefined)}
onConfirm={() => {
if (serviceToRestart === 'project' || serviceToRestart === 'branch') {
requestProjectRestart()
} else if (serviceToRestart === 'database') {
requestDatabaseRestart()
}
}}
/>
</>
)
}