InferredSQLViewer.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { UntrustedSqlFragment } from '@supabase/pg-meta'
  2. import { Loader2 } from 'lucide-react'
  3. import { Badge, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
  4. import CodeEditor from '@/components/ui/CodeEditor/CodeEditor'
  5. export const InferredSQLViewer = ({
  6. sql,
  7. isLoading = false,
  8. }: {
  9. sql: UntrustedSqlFragment | undefined
  10. isLoading?: boolean
  11. }) => {
  12. return (
  13. <>
  14. <div className="flex items-center justify-between px-4 py-2">
  15. <div className="flex items-center gap-x-2">
  16. <p className="text-sm">Inferred SQL:</p>
  17. {isLoading && <Loader2 size={14} className="animate-spin text-foreground-lighter" />}
  18. </div>
  19. <div className="flex items-center gap-x-2">
  20. <Tooltip>
  21. <TooltipTrigger>
  22. <Badge variant="warning">Generated</Badge>
  23. </TooltipTrigger>
  24. <TooltipContent side="bottom" align="end" className="w-64 text-center">
  25. This query is inferred from client library code with the help of the Assistant and may
  26. not guarantee correctness.
  27. </TooltipContent>
  28. </Tooltip>
  29. </div>
  30. </div>
  31. <div className="h-44 relative">
  32. {isLoading && !sql ? (
  33. <div className="flex h-full items-center justify-center bg-surface-100 text-foreground-lighter">
  34. <Loader2 size={20} className="animate-spin" />
  35. </div>
  36. ) : (
  37. <CodeEditor isReadOnly id="inferred-sql" language="pgsql" value={sql ?? ''} />
  38. )}
  39. </div>
  40. </>
  41. )
  42. }