Files
supabase/apps/studio/components/ui/EditorPanel/SaveSnippetDialog.tsx
T
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

116 lines
3.8 KiB
TypeScript

import { useEffect, useState } from 'react'
import { toast } from 'sonner'
import {
AiIconAnimation,
Button,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
Input,
Label,
} from 'ui'
import { generateSnippetTitle } from '@/components/interfaces/SQLEditor/SQLEditor.constants'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { useCheckOpenAIKeyQuery } from '@/data/ai/check-api-key-query'
import { useSqlTitleGenerateMutation } from '@/data/ai/sql-title-mutation'
import { useOrgAiOptInLevel } from '@/hooks/misc/useOrgOptedIntoAi'
interface SaveSnippetDialogProps {
open: boolean
sql: string
onOpenChange: (open: boolean) => void
onSave: (name: string) => void
}
export const SaveSnippetDialog = ({ open, sql, onOpenChange, onSave }: SaveSnippetDialogProps) => {
const { data: check } = useCheckOpenAIKeyQuery()
const [name, setName] = useState(generateSnippetTitle())
const isApiKeySet = !!check?.hasKey
// Orgs on HIPAA plans or that have disabled AI should not have access to Supabase AI
const { aiOptInLevel, isHipaaProjectDisallowed } = useOrgAiOptInLevel()
const isAiOptedOut = aiOptInLevel === 'disabled'
const { mutate: generateTitle, isPending: isGenerating } = useSqlTitleGenerateMutation({
onSuccess: ({ title }) => setName(title),
onError: (error) => toast.error(`Failed to generate title: ${error.message}`),
})
// Reset the name each time the dialog opens
useEffect(() => {
if (open) setName(generateSnippetTitle())
}, [open])
const handleSave = () => {
const trimmed = name.trim()
if (!trimmed) return
onSave(trimmed)
onOpenChange(false)
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent size="small">
<DialogHeader>
<DialogTitle>Save snippet</DialogTitle>
</DialogHeader>
<DialogSectionSeparator />
<DialogSection className="flex flex-col gap-y-4 py-5">
<div className="flex flex-col gap-y-2">
<Label htmlFor="snippet-name">Name</Label>
<Input
id="snippet-name"
autoFocus
value={name}
onChange={(e) => setName(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') handleSave()
}}
/>
</div>
<div className="flex justify-end">
<ButtonTooltip
size="tiny"
disabled={isGenerating || !isApiKeySet || isHipaaProjectDisallowed || isAiOptedOut}
onClick={() => generateTitle({ sql })}
tooltip={{
content: {
side: 'bottom',
text: isHipaaProjectDisallowed
? 'This feature is not available for HIPAA projects.'
: isAiOptedOut
? 'Your organization has opted out of AI features.'
: isApiKeySet
? undefined
: 'Add your "OPENAI_API_KEY" to your environment variables to use this feature.',
},
}}
>
<div className="flex items-center gap-1">
<div className="scale-75">
<AiIconAnimation loading={isGenerating} />
</div>
<span>Generate with AI</span>
</div>
</ButtonTooltip>
</div>
</DialogSection>
<DialogSectionSeparator />
<DialogFooter className="px-5 py-4">
<Button onClick={() => onOpenChange(false)}>Cancel</Button>
<Button variant="primary" disabled={!name.trim()} onClick={handleSave}>
Save snippet
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}