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