InsertDataDialog.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { useParams } from 'common'
  2. import { SqlEditor } from 'icons'
  3. import Link from 'next/link'
  4. import {
  5. Button,
  6. cn,
  7. Dialog,
  8. DialogContent,
  9. DialogFooter,
  10. DialogHeader,
  11. DialogSection,
  12. DialogSectionSeparator,
  13. DialogTitle,
  14. DialogTrigger,
  15. } from 'ui'
  16. import { CodeBlock } from 'ui-patterns/CodeBlock'
  17. import { DocsButton } from '@/components/ui/DocsButton'
  18. import { FDWTable } from '@/data/fdw/fdws-query'
  19. import { DOCS_URL } from '@/lib/constants'
  20. interface InsertDataDialogProps {
  21. table: string
  22. fdwTable: FDWTable
  23. }
  24. export const InsertDataDialog = ({ table, fdwTable }: InsertDataDialogProps) => {
  25. const { ref } = useParams()
  26. const sql = /* SQL */ `
  27. insert into ${fdwTable.schema}.${fdwTable.name} (
  28. -- specify columns
  29. )
  30. values (
  31. -- specify values for each column
  32. );
  33. `.trim()
  34. return (
  35. <Dialog>
  36. <DialogTrigger asChild>
  37. <Button type="default">Insert data</Button>
  38. </DialogTrigger>
  39. <DialogContent aria-describedby={undefined}>
  40. <DialogHeader>
  41. <DialogTitle>
  42. Insert data into <code className="text-code-inline">{table}</code>
  43. </DialogTitle>
  44. </DialogHeader>
  45. <DialogSectionSeparator />
  46. <DialogSection className="flex flex-col gap-y-2">
  47. <p className="text-sm">
  48. The Iceberg Foreign Data Wrapper (FDW) supports inserting data into Iceberg tables using
  49. standard SQL <code className="text-code-inline">INSERT</code> statements.
  50. </p>
  51. <p className="text-sm">
  52. Use the following SQL snippet to insert data into your iceberg table:
  53. </p>
  54. </DialogSection>
  55. <DialogSectionSeparator />
  56. <DialogSection className="p-0!">
  57. <CodeBlock
  58. hideLineNumbers
  59. wrapperClassName={cn('[&_pre]:px-4 [&_pre]:py-3 [&>pre]:rounded-none [&>pre]:border-0')}
  60. className="[&_code]:text-foreground"
  61. language="sql"
  62. value={sql}
  63. />
  64. </DialogSection>
  65. <DialogFooter>
  66. <DocsButton
  67. href={`${DOCS_URL}/guides/database/extensions/wrappers/iceberg#data-insertion`}
  68. />
  69. <Button asChild type="default" icon={<SqlEditor />}>
  70. <Link href={`/project/${ref}/sql/new?content=${encodeURIComponent(sql)}`}>
  71. Open in SQL Editor
  72. </Link>
  73. </Button>
  74. </DialogFooter>
  75. </DialogContent>
  76. </Dialog>
  77. )
  78. }