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

150 lines
5.3 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
import { noop } from 'lodash'
import { Lock, Table } from 'lucide-react'
import { AiIconAnimation, Badge, CardTitle } from 'ui'
import type { PolicyTable } from './PolicyTableRow.types'
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { EditorTablePageLink } from '@/data/prefetchers/project.$ref.editor.$id'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
interface PolicyTableRowHeaderProps {
table: PolicyTable
isLocked: boolean
hasApiAccess: boolean
isLoadingApiAccess: boolean
onSelectToggleRLS: (table: PolicyTable) => void
onSelectCreatePolicy: (table: PolicyTable) => void
}
export const PolicyTableRowHeader = ({
table,
isLocked,
hasApiAccess,
isLoadingApiAccess,
onSelectToggleRLS = noop,
onSelectCreatePolicy,
}: PolicyTableRowHeaderProps) => {
const { ref } = useParams()
const aiSnap = useAiAssistantStateSnapshot()
const { openSidebar } = useSidebarManagerSnapshot()
const { can: canCreatePolicies } = useAsyncCheckPermissions(
PermissionAction.TENANT_SQL_ADMIN_WRITE,
'policies'
)
const { can: canToggleRLS } = useAsyncCheckPermissions(
PermissionAction.TENANT_SQL_ADMIN_WRITE,
'tables'
)
const isRealtimeSchema = table.schema === 'realtime'
const isRealtimeMessagesTable = isRealtimeSchema && table.name === 'messages'
const isTableLocked = isRealtimeSchema ? !isRealtimeMessagesTable : isLocked
return (
<div id={table.id.toString()} className="flex w-full items-center justify-between">
<div className="flex gap-x-4 text-left flex-wrap">
<EditorTablePageLink
projectRef={ref}
id={String(table.id)}
className="flex items-center gap-3 flex-wrap"
>
<Table strokeWidth={1.5} size={16} className="text-foreground-muted" />
<CardTitle className="m-0 normal-case">{table.name}</CardTitle>
</EditorTablePageLink>
<div className="flex items-center gap-x-1">
{!table.rls_enabled && (
<Badge variant="warning" className="h-5">
RLS Disabled
</Badge>
)}
{!isLoadingApiAccess && !hasApiAccess && (
<Badge variant="default" className="h-5">
API Disabled
</Badge>
)}
{isTableLocked && (
<Badge className="h-5">
<span className="flex gap-x-1 items-center text-foreground-lighter">
<Lock size={10} /> Locked
</span>
</Badge>
)}
</div>
</div>
{!isTableLocked && (
<div className="flex-1">
<div className="flex flex-row justify-end gap-x-2">
{!isRealtimeMessagesTable && (
<ButtonTooltip
disabled={!canToggleRLS}
onClick={() => onSelectToggleRLS(table)}
data-testid={`${table.name}-toggle-rls`}
tooltip={{
content: {
side: 'bottom',
text: !canToggleRLS
? 'You need additional permissions to toggle RLS'
: undefined,
},
}}
>
{table.rls_enabled ? 'Disable RLS' : 'Enable RLS'}
</ButtonTooltip>
)}
<ButtonTooltip
disabled={!canToggleRLS || !canCreatePolicies}
onClick={() => onSelectCreatePolicy(table)}
data-testid={`${table.name}-create-policy`}
tooltip={{
content: {
side: 'bottom',
text: !canToggleRLS
? !canToggleRLS || !canCreatePolicies
? 'You need additional permissions to create RLS policies'
: undefined
: undefined,
},
}}
>
Create policy
</ButtonTooltip>
<ButtonTooltip
className="px-1"
onClick={() => {
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
aiSnap.newChat({
name: 'Create new policy',
initialInput: `Create and name a new policy for the ${table.schema} schema on the ${table.name} table that ...`,
})
}}
tooltip={{
content: {
side: 'bottom',
text:
!canToggleRLS || !canCreatePolicies
? 'You need additional permissions to create RLS policies'
: 'Create with Supabase Assistant',
},
}}
aria-label={
!canToggleRLS || !canCreatePolicies
? 'You need additional permissions to create RLS policies'
: 'Create with Supabase Assistant'
}
>
<AiIconAnimation size={16} />
</ButtonTooltip>
</div>
</div>
)}
</div>
)
}