SqlWarningAdmonition.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Button } from 'ui'
  2. import { Admonition } from 'ui-patterns'
  3. export interface SqlWarningAdmonitionProps {
  4. warningType: 'hasWriteOperation' | 'hasUnknownFunctions'
  5. onCancel: () => void
  6. onConfirm: () => void
  7. disabled?: boolean
  8. className?: string
  9. /** Optional override primary message */
  10. message?: string
  11. /** Optional override secondary message */
  12. subMessage?: string
  13. /** Optional override labels */
  14. cancelLabel?: string
  15. confirmLabel?: string
  16. }
  17. export const SqlWarningAdmonition = ({
  18. warningType,
  19. onCancel,
  20. onConfirm,
  21. disabled = false,
  22. className,
  23. message,
  24. subMessage,
  25. cancelLabel,
  26. confirmLabel,
  27. }: SqlWarningAdmonitionProps) => {
  28. return (
  29. <Admonition
  30. type="warning"
  31. className={`mb-0 rounded-none border-0 shrink-0 bg-background-100 ${className}`}
  32. >
  33. {!!message && (
  34. <p className="text-xs mb-1!">
  35. {`${
  36. warningType === 'hasWriteOperation'
  37. ? 'This query contains write operations.'
  38. : 'This query involves running a function.'
  39. } Are you sure you want to execute it?`}
  40. </p>
  41. )}
  42. <p className="text-foreground-light text-xs">
  43. {subMessage ?? 'Make sure you are not accidentally removing something important.'}
  44. </p>
  45. <div className="flex justify-stretch mt-2 gap-2">
  46. <Button type="outline" size="tiny" className="w-full flex-1" onClick={onCancel}>
  47. {cancelLabel ?? 'Cancel'}
  48. </Button>
  49. <Button
  50. type="danger"
  51. size="tiny"
  52. disabled={disabled}
  53. className="w-full flex-1"
  54. onClick={onConfirm}
  55. >
  56. {confirmLabel ?? 'Run'}
  57. </Button>
  58. </div>
  59. </Admonition>
  60. )
  61. }