Home / Function/ DownloadSnippetModal() — supabase Function Reference

DownloadSnippetModal() — supabase Function Reference

Architecture documentation for the DownloadSnippetModal() function in DownloadSnippetModal.tsx from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  ef98649f_da64_9ce7_0f37_f2fb87ca08c7["DownloadSnippetModal()"]
  703c7a12_29bc_06f3_a8a2_1b523f93db3b["generateMigrationCliCommand()"]
  ef98649f_da64_9ce7_0f37_f2fb87ca08c7 -->|calls| 703c7a12_29bc_06f3_a8a2_1b523f93db3b
  afa1175f_3449_1253_e5b1_d6612acc8707["generateSeedCliCommand()"]
  ef98649f_da64_9ce7_0f37_f2fb87ca08c7 -->|calls| afa1175f_3449_1253_e5b1_d6612acc8707
  abf9ef4f_f8c3_a05e_b562_14c91e927bc1["generateFileCliCommand()"]
  ef98649f_da64_9ce7_0f37_f2fb87ca08c7 -->|calls| abf9ef4f_f8c3_a05e_b562_14c91e927bc1
  style ef98649f_da64_9ce7_0f37_f2fb87ca08c7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/SQLEditor/DownloadSnippetModal.tsx lines 22–130

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 `supabase/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 (
    <Modal
      hideFooter
      showCloseButton
      size="xlarge"
      header={<p>Download snippet as local migration file via the Supabase CLI.</p>}
      {...props}
    >
      <div className="flex flex-col items-start justify-between gap-4 relative pt-2">
        <Tabs type="underlined" listClassNames="pl-5">
          {SNIPPETS.map((snippet) => {
            return (
              <Tabs.Panel key={snippet.id} id={snippet.id} label={snippet.label}>
                <Modal.Content className="!py-0">
                  <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>
                </Modal.Content>
              </Tabs.Panel>
            )
          })}
        </Tabs>
        <Modal.Content className="w-full flex items-center justify-between pt-0">
          <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>

            <Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>
              <Link
                href={`${DOCS_URL}/guides/cli/local-development`}
                target="_blank"
                rel="noreferrer"
              >
                About CLI
              </Link>
            </Button>
          </div>
        </Modal.Content>
      </div>
    </Modal>
  )
}

Subdomains

Frequently Asked Questions

What does DownloadSnippetModal() do?
DownloadSnippetModal() is a function in the supabase codebase.
What does DownloadSnippetModal() call?
DownloadSnippetModal() calls 3 function(s): generateFileCliCommand, generateMigrationCliCommand, generateSeedCliCommand.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free