ProtectedSchemaWarning.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { useState } from 'react'
  2. import {
  3. Button,
  4. Dialog,
  5. DialogContent,
  6. DialogFooter,
  7. DialogHeader,
  8. DialogSection,
  9. DialogSectionSeparator,
  10. DialogTitle,
  11. DialogTrigger,
  12. } from 'ui'
  13. import { Admonition } from 'ui-patterns'
  14. import { INTERNAL_SCHEMAS, useIsProtectedSchema } from '@/hooks/useProtectedSchemas'
  15. export const ProtectedSchemaDialog = ({ onClose }: { onClose: () => void }) => {
  16. return (
  17. <>
  18. <DialogHeader>
  19. <DialogTitle>Schemas managed by Briven</DialogTitle>
  20. </DialogHeader>
  21. <DialogSectionSeparator />
  22. <DialogSection className="space-y-2 prose">
  23. <p className="text-sm">
  24. The following schemas are managed by Briven and are currently protected from write
  25. access through the dashboard.
  26. </p>
  27. <div className="flex flex-wrap gap-1">
  28. {INTERNAL_SCHEMAS.map((schema) => (
  29. <code key={schema} className="text-xs">
  30. {schema}
  31. </code>
  32. ))}
  33. </div>
  34. <p className="text-sm mt-4!">
  35. These schemas are critical to the functionality of your Briven project and hence we
  36. highly recommend not altering them.
  37. </p>
  38. <p className="text-sm">
  39. You can, however, still interact with those schemas through the SQL Editor although we
  40. advise you only do so if you know what you are doing.
  41. </p>
  42. </DialogSection>
  43. <DialogFooter>
  44. <div className="flex items-center justify-end space-x-2">
  45. <Button type="default" onClick={onClose}>
  46. Understood
  47. </Button>
  48. </div>
  49. </DialogFooter>
  50. </>
  51. )
  52. }
  53. export const ProtectedSchemaWarning = ({
  54. size = 'md',
  55. schema,
  56. entity,
  57. }: {
  58. size?: 'sm' | 'md'
  59. schema: string
  60. entity: string
  61. }) => {
  62. const [showModal, setShowModal] = useState(false)
  63. const { isSchemaLocked, reason, fdwType } = useIsProtectedSchema({ schema })
  64. if (!isSchemaLocked) return null
  65. const showLearnMoreDialog =
  66. reason !== 'fdw' || (fdwType !== 'iceberg' && fdwType !== 's3_vectors')
  67. return (
  68. <Admonition
  69. showIcon={size === 'sm' ? false : true}
  70. layout={size === 'sm' ? 'vertical' : 'horizontal'}
  71. type="note"
  72. title={
  73. size === 'sm' ? `Viewing protected schema` : `Viewing ${entity} from a protected schema`
  74. }
  75. description={
  76. reason === 'fdw' && fdwType === 'iceberg' ? (
  77. <p>
  78. The <code className="text-code-inline">{schema}</code> schema is used by Briven to
  79. connect to analytics buckets and is read-only through the dashboard.
  80. </p>
  81. ) : reason === 'fdw' && fdwType === 's3_vectors' ? (
  82. <p>
  83. The <code className="text-code-inline">{schema}</code> schema is used by Briven to
  84. connect to vector buckets and is read-only through the dashboard.
  85. </p>
  86. ) : (
  87. <p>
  88. The <code className="text-code-inline">{schema}</code> schema is managed by Briven and
  89. is read-only through the dashboard.
  90. </p>
  91. )
  92. }
  93. actions={
  94. showLearnMoreDialog && (
  95. <Dialog open={showModal} onOpenChange={setShowModal}>
  96. <DialogTrigger asChild>
  97. <Button type="default" size="tiny" onClick={() => setShowModal(true)}>
  98. Learn more
  99. </Button>
  100. </DialogTrigger>
  101. <DialogContent>
  102. <ProtectedSchemaDialog onClose={() => setShowModal(false)} />
  103. </DialogContent>
  104. </Dialog>
  105. )
  106. }
  107. />
  108. )
  109. }