import type { ModalProps } from '@ui/components/Modal/Modal'
import { snakeCase } from 'lodash'
import { ExternalLink } from 'lucide-react'
import Link from 'next/link'
import { useState } from 'react'
import { Button, Modal, Tabs } from 'ui'
import { CodeBlock } from 'ui-patterns/CodeBlock'
import { Markdown } from '../Markdown'
import {
generateFileCliCommand,
generateMigrationCliCommand,
generateSeedCliCommand,
} from './SQLEditor.utils'
import { TwoOptionToggle } from '@/components/ui/TwoOptionToggle'
import { DOCS_URL } from '@/lib/constants'
import { useSqlEditorV2StateSnapshot } from '@/state/sql-editor-v2'
export interface DownloadSnippetModalProps extends ModalProps {
id: string
}
const DownloadSnippetModal = ({ id, ...props }: DownloadSnippetModalProps) => {
const snapV2 = useSqlEditorV2StateSnapshot()
const snippet = snapV2.snippets[id]?.snippet
const migrationName = snakeCase(snippet?.name)
const [selectedView, setSelectedView] = useState<'CLI' | 'NPM'>('CLI')
const SNIPPETS = [
{
id: 'migration',
label: 'Migration',
title: 'Download as migration',
description: `Download the snippet in a new migration named \`${migrationName}\``,
cli: generateMigrationCliCommand(id, migrationName),
npm: generateMigrationCliCommand(id, migrationName, true),
},
{
id: 'seed',
label: 'Seed file',
title: 'Download as seed file',
description:
'If your query consists of sample data, append the snippet to the end of `briven/seed.sql`',
cli: generateSeedCliCommand(id),
npm: generateSeedCliCommand(id, true),
},
{
id: 'sql',
label: 'SQL file',
title: 'Download as SQL file',
description: `Download the snippet directly into a new SQL file named \`${migrationName}.sql\``,
cli: generateFileCliCommand(id, migrationName),
npm: generateFileCliCommand(id, migrationName, true),
},
]
return (
{snippet.title}
{selectedView === 'CLI' ? snippet.cli : snippet.npm}
Run this command from your project directory