Files
supabase/apps/studio/components/ui/EditorPanel/SaveSnippetDialog.tsx
Gildas Garcia 8c6d5036ea chore: remove <Label> _Shadcn_ suffix (#45986)
## Problem

The `_Shadcn_` suffix isn't needed anymore on label component

## Solution

Remove it. No other changes

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

* **Refactor**
* Standardized Label usage across the codebase by removing the legacy
alias and using the direct Label export from the UI package
consistently.
* **Documentation**
* Updated component examples and docs to use the standardized Label
component in usage snippets and demos.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45986)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-15 15:55:33 +02:00

125 lines
4.1 KiB
TypeScript

import { useParams } from 'common'
import { useEffect, useState } from 'react'
import { toast } from 'sonner'
import {
AiIconAnimation,
Button,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
Input,
Label,
} from 'ui'
import { subscriptionHasHipaaAddon } from '@/components/interfaces/Billing/Subscription/Subscription.utils'
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 { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'
import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-query'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
interface SaveSnippetDialogProps {
open: boolean
sql: string
onOpenChange: (open: boolean) => void
onSave: (name: string) => void
}
export const SaveSnippetDialog = ({ open, sql, onOpenChange, onSave }: SaveSnippetDialogProps) => {
const { ref } = useParams()
const { data: organization } = useSelectedOrganizationQuery()
const { data: subscription } = useOrgSubscriptionQuery(
{ orgSlug: organization?.slug },
{ enabled: open }
)
const { data: projectSettings } = useProjectSettingsV2Query({ projectRef: ref })
const { data: check } = useCheckOpenAIKeyQuery()
const [name, setName] = useState(generateSnippetTitle())
const isApiKeySet = !!check?.hasKey
const hasHipaaAddon = subscriptionHasHipaaAddon(subscription) && projectSettings?.is_sensitive
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>
{!hasHipaaAddon && (
<div className="flex justify-end">
<ButtonTooltip
type="default"
size="tiny"
disabled={isGenerating || !isApiKeySet}
onClick={() => generateTitle({ sql })}
tooltip={{
content: {
side: 'bottom',
text: 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 type="default" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button disabled={!name.trim()} onClick={handleSave}>
Save snippet
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}