| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import { useState } from 'react'
- import {
- Button,
- Dialog,
- DialogContent,
- DialogFooter,
- DialogHeader,
- DialogSection,
- DialogSectionSeparator,
- DialogTitle,
- DialogTrigger,
- } from 'ui'
- import { Admonition } from 'ui-patterns'
- import { INTERNAL_SCHEMAS, useIsProtectedSchema } from '@/hooks/useProtectedSchemas'
- export const ProtectedSchemaDialog = ({ onClose }: { onClose: () => void }) => {
- return (
- <>
- <DialogHeader>
- <DialogTitle>Schemas managed by Briven</DialogTitle>
- </DialogHeader>
- <DialogSectionSeparator />
- <DialogSection className="space-y-2 prose">
- <p className="text-sm">
- The following schemas are managed by Briven and are currently protected from write
- access through the dashboard.
- </p>
- <div className="flex flex-wrap gap-1">
- {INTERNAL_SCHEMAS.map((schema) => (
- <code key={schema} className="text-xs">
- {schema}
- </code>
- ))}
- </div>
- <p className="text-sm mt-4!">
- These schemas are critical to the functionality of your Briven project and hence we
- highly recommend not altering them.
- </p>
- <p className="text-sm">
- You can, however, still interact with those schemas through the SQL Editor although we
- advise you only do so if you know what you are doing.
- </p>
- </DialogSection>
- <DialogFooter>
- <div className="flex items-center justify-end space-x-2">
- <Button type="default" onClick={onClose}>
- Understood
- </Button>
- </div>
- </DialogFooter>
- </>
- )
- }
- export const ProtectedSchemaWarning = ({
- size = 'md',
- schema,
- entity,
- }: {
- size?: 'sm' | 'md'
- schema: string
- entity: string
- }) => {
- const [showModal, setShowModal] = useState(false)
- const { isSchemaLocked, reason, fdwType } = useIsProtectedSchema({ schema })
- if (!isSchemaLocked) return null
- const showLearnMoreDialog =
- reason !== 'fdw' || (fdwType !== 'iceberg' && fdwType !== 's3_vectors')
- return (
- <Admonition
- showIcon={size === 'sm' ? false : true}
- layout={size === 'sm' ? 'vertical' : 'horizontal'}
- type="note"
- title={
- size === 'sm' ? `Viewing protected schema` : `Viewing ${entity} from a protected schema`
- }
- description={
- reason === 'fdw' && fdwType === 'iceberg' ? (
- <p>
- The <code className="text-code-inline">{schema}</code> schema is used by Briven to
- connect to analytics buckets and is read-only through the dashboard.
- </p>
- ) : reason === 'fdw' && fdwType === 's3_vectors' ? (
- <p>
- The <code className="text-code-inline">{schema}</code> schema is used by Briven to
- connect to vector buckets and is read-only through the dashboard.
- </p>
- ) : (
- <p>
- The <code className="text-code-inline">{schema}</code> schema is managed by Briven and
- is read-only through the dashboard.
- </p>
- )
- }
- actions={
- showLearnMoreDialog && (
- <Dialog open={showModal} onOpenChange={setShowModal}>
- <DialogTrigger asChild>
- <Button type="default" size="tiny" onClick={() => setShowModal(true)}>
- Learn more
- </Button>
- </DialogTrigger>
- <DialogContent>
- <ProtectedSchemaDialog onClose={() => setShowModal(false)} />
- </DialogContent>
- </Dialog>
- )
- }
- />
- )
- }
|