The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore(studio): improve download snippet dialog (#46242)
Danny White5fdff9707fb7
diff --git a/apps/studio/components/interfaces/SQLEditor/DownloadSnippetModal.tsx b/apps/studio/components/interfaces/SQLEditor/DownloadSnippetModal.tsxindex a112ed61ff2..30efd77a085 100644--- a/apps/studio/components/interfaces/SQLEditor/DownloadSnippetModal.tsx+++ b/apps/studio/components/interfaces/SQLEditor/DownloadSnippetModal.tsx@@ -4,18 +4,22 @@ import Link from 'next/link'import { useState } from 'react'import {Button,+ cn,Dialog,DialogContent,DialogHeader,DialogSection,DialogSectionSeparator,DialogTitle,- Tabs,+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,type DialogProps,} from 'ui'import { CodeBlock } from 'ui-patterns/CodeBlock'-import { Markdown } from '../Markdown'import {generateFileCliCommand,generateMigrationCliCommand,@@ -25,108 +29,139 @@ import { TwoOptionToggle } from '@/components/ui/TwoOptionToggle'import { DOCS_URL } from '@/lib/constants'import { useSqlEditorV2StateSnapshot } from '@/state/sql-editor-v2'+const CLI_DOCS_URL = `${DOCS_URL}/guides/cli/local-development`+export interface DownloadSnippetModalProps extends DialogProps {id: string}+type DownloadFormat = 'migration' | 'seed' | 'sql'+export const DownloadSnippetModal = ({ id, ...props }: DownloadSnippetModalProps) => {const snapV2 = useSqlEditorV2StateSnapshot()const snippet = snapV2.snippets[id]?.snippetconst migrationName = snakeCase(snippet?.name)- const [selectedView, setSelectedView] = useState<'CLI' | 'NPM'>('CLI')+ const [downloadFormat, setDownloadFormat] = useState<DownloadFormat>('migration')+ const [selectedView, setSelectedView] = useState<'CLI' | 'NPX'>('CLI')const SNIPPETS = [{- id: 'migration',+ id: 'migration' as const,label: 'Migration',- title: 'Download as migration',- description: `Download the snippet in a new migration named \`${migrationName}\``,+ caption: (+ <>+ Run this command from your project directory to download the snippet in a new migration+ named <code className="text-code-inline break-normal">{migrationName}</code>.+ </>+ ),+ docLink: {+ label: 'About migrations',+ href: `${DOCS_URL}/guides/deployment/database-migrations`,+ },cli: generateMigrationCliCommand(id, migrationName),- npm: generateMigrationCliCommand(id, migrationName, true),+ npx: generateMigrationCliCommand(id, migrationName, true),},{- id: 'seed',+ id: 'seed' as const,label: 'Seed file',- title: 'Download as seed file',- description:- 'If your query consists of sample data, append the snippet to the end of `supabase/seed.sql`',+ caption: (+ <>+ Run this command from your project directory to download the snippet. If your query+ consists of sample data, append it to the end of{' '}+ <code className="text-code-inline break-normal">supabase/seed.sql</code>.+ </>+ ),+ docLink: {+ label: 'About seeding',+ href: `${DOCS_URL}/guides/local-development/seeding-your-database`,+ },cli: generateSeedCliCommand(id),- npm: generateSeedCliCommand(id, true),+ npx: generateSeedCliCommand(id, true),},{- id: 'sql',+ id: 'sql' as const,label: 'SQL file',- title: 'Download as SQL file',- description: `Download the snippet directly into a new SQL file named \`${migrationName}.sql\``,+ caption: (+ <>+ Run this command from your project directory to download the snippet into a new SQL file+ named <code className="text-code-inline break-normal">{migrationName}.sql</code>.+ </>+ ),cli: generateFileCliCommand(id, migrationName),- npm: generateFileCliCommand(id, migrationName, true),+ npx: generateFileCliCommand(id, migrationName, true),},]+ const selectedSnippet = SNIPPETS.find((s) => s.id === downloadFormat) ?? SNIPPETS[0]+ const commandValue = selectedView === 'CLI' ? selectedSnippet.cli : selectedSnippet.npx+return (<Dialog {...props}>- <DialogContent size="xlarge">+ <DialogContent><DialogHeader>- <DialogTitle>Download snippet as local migration file via the Supabase CLI</DialogTitle>+ <DialogTitle>Export query</DialogTitle></DialogHeader><DialogSectionSeparator />- <Tabs type="underlined" listClassNames="pl-5 pt-2">- {SNIPPETS.map((snippet) => {- return (- <Tabs.Panel key={snippet.id} id={snippet.id} label={snippet.label}>- <DialogSection>- <div className="flex items-center justify-between mb-3">- <div className="flex flex-col gap-y-1">- <p className="text-base">{snippet.title}</p>- <Markdown- className="text-sm text-scale-1000 [&>p>code]:break-normal!"- content={snippet.description}- />- </div>- <TwoOptionToggle- width={50}- options={['CLI', 'NPM']}- activeOption={selectedView}- borderOverride="border-muted"- onClickOption={() =>- selectedView === 'CLI' ? setSelectedView('NPM') : setSelectedView('CLI')- }- />- </div>- <pre>- <CodeBlock- language="bash"- className="language-bash prose dark:prose-dark max-w-none"- >- {selectedView === 'CLI' ? snippet.cli : snippet.npm}- </CodeBlock>- </pre>- </DialogSection>- </Tabs.Panel>- )- })}- </Tabs>- <DialogSection className="flex items-center justify-between">- <p className="text-xs text-lighter">Run this command from your project directory</p>- <div className="flex justify-between items-center gap-x-2">- <Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>- <Link- href={`${DOCS_URL}/guides/deployment/database-migrations`}- target="_blank"- rel="noreferrer"- >- About migrations- </Link>- </Button>+ <DialogSection className="flex flex-col gap-y-4">+ <div className="flex items-center justify-between gap-x-2">+ <p className="text-sm">Export as</p>+ <Select+ value={downloadFormat}+ onValueChange={(value) => setDownloadFormat(value as DownloadFormat)}+ >+ <SelectTrigger className="w-auto">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {SNIPPETS.map((snippet) => (+ <SelectItem key={snippet.id} value={snippet.id}>+ {snippet.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </div>+ <div className="flex flex-col gap-y-2">+ <div className="flex items-center justify-between gap-x-2">+ <p className="text-sm">Run with</p>+ <TwoOptionToggle+ width={50}+ options={['CLI', 'NPX']}+ activeOption={selectedView}+ borderOverride="border-muted"+ onClickOption={() =>+ selectedView === 'CLI' ? setSelectedView('NPX') : setSelectedView('CLI')+ }+ />+ </div>+ <CodeBlock+ language="bash"+ value={commandValue}+ hideLineNumbers+ wrapperClassName="[&_pre]:px-4 [&_pre]:py-3"+ className={cn(+ '!bg-surface-75 border-border [&_code]:text-[12px] [&_code]:text-foreground'+ )}+ />+ <p className="text-xs text-foreground-lighter leading-relaxed">+ {selectedSnippet.caption}+ </p>+ </div>+ </DialogSection>+ <DialogSection>+ <div className="flex items-center justify-start gap-x-2">+ {selectedSnippet.docLink && (+ <Button asChild type="default" icon={<ExternalLink />}>+ <Link href={selectedSnippet.docLink.href} target="_blank" rel="noreferrer">+ {selectedSnippet.docLink.label}+ </Link>+ </Button>+ )}- <Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>- <Link- href={`${DOCS_URL}/guides/cli/local-development`}- target="_blank"- rel="noreferrer"- >+ <Button asChild type="default" icon={<ExternalLink />}>+ <Link href={CLI_DOCS_URL} target="_blank" rel="noreferrer">About CLI</Link></Button>diff --git a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsxindex 5536305da67..7635f8045d4 100644--- a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx+++ b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx@@ -411,7 +411,7 @@ export const SQLEditorTreeViewItem = ({onFocusCapture={(e) => e.stopPropagation()}><Download size={14} />- Download as migration file+ Export query</ContextMenuItem>)}{onSelectDelete !== undefined && isOwner && (diff --git a/e2e/studio/features/sql-editor.spec.ts b/e2e/studio/features/sql-editor.spec.tsindex 21a302d20a5..44f2a6500ca 100644--- a/e2e/studio/features/sql-editor.spec.ts+++ b/e2e/studio/features/sql-editor.spec.ts@@ -786,11 +786,11 @@ hello world`)await expect(page.getByText('result found')).toBeVisible()await searchBar.fill('') // clear search bar- // download as migration file+ // export query as migration fileawait privateSnippetSection.getByTitle(sqlSnippetName, { exact: true }).click({ button: 'right' })- await page.getByRole('menuitem', { name: 'Download as migration file' }).click()+ await page.getByRole('menuitem', { name: 'Export query' }).click()await expect(page.getByText('supabase migration new')).toBeVisible()await page.getByRole('button', { name: 'Close' }).click()