import Link from 'next/link' import Image from 'next/image' import { FC } from 'react' import { partition } from 'lodash' import * as Tooltip from '@radix-ui/react-tooltip' import { PermissionAction } from '@supabase/shared-types/out/constants' import { Collapsible, IconChevronUp, Button, IconExternalLink, IconTrash, IconEdit } from 'ui' import { useStore, checkPermissions } from 'hooks' import { useParams } from 'common/hooks' import { WrapperMeta } from './Wrappers.types' import { FDW } from 'data/fdw/fdws-query' import { useFDWDeleteMutation } from 'data/fdw/fdw-delete-mutation' import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmModal' interface Props { wrappers: FDW[] wrapperMeta: WrapperMeta isOpen: boolean onOpen: (wrapper: string) => void } const WrapperRow: FC = ({ wrappers = [], wrapperMeta, isOpen, onOpen }) => { const { ui } = useStore() const { ref } = useParams() const { project } = useProjectContext() const { mutateAsync: deleteFDW } = useFDWDeleteMutation() const canManageWrappers = checkPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'wrappers') const onDeleteWrapper = (wrapper: any) => { confirmAlert({ title: `Confirm to disable ${wrapper.name}`, message: `Are you sure you want to disable the ${wrapper.name} wrapper? This will also remove all tables created with this wrapper.`, onAsyncConfirm: async () => { try { await deleteFDW({ projectRef: project?.ref, connectionString: project?.connectionString, wrapper, wrapperMeta, }) ui.setNotification({ category: 'success', message: `Successfully disabled ${wrapper.name} foreign data wrapper`, }) } catch (error: any) { ui.setNotification({ error, category: 'error', message: `Failed to disable ${wrapper.name}: ${error.message}`, }) } }, }) } return ( <> onOpen(wrapperMeta.name)} className={[ 'bg-scale-100 dark:bg-scale-300 ', 'hover:bg-scale-200 dark:hover:bg-scale-500', 'data-open:bg-scale-200 dark:data-open:bg-scale-500', 'border-scale-300', 'dark:border-scale-500 hover:border-scale-500', 'dark:hover:border-scale-700 data-open:border-scale-700', 'col-span-12 mx-auto', '-space-y-px overflow-hidden', 'transition border shadow hover:z-50', 'first:rounded-tl first:rounded-tr first:!border-t', 'last:rounded-bl last:rounded-br last:border-t-0', ].join(' ')} >
{wrappers.map((wrapper) => { const serverOptions = Object.fromEntries( wrapper.server_options.map((option: any) => option.split('=')) ) const [encryptedMetadata, visibleMetadata] = partition( wrapperMeta.server.options, 'hidden' ) return (

{wrapper.name}

{visibleMetadata.map((metadata) => (

{metadata.label}:

{serverOptions[metadata.name]}

))} {encryptedMetadata.map((metadata) => (

{metadata.label}:

Encrypted in Vault
))}

Foreign tables: ({wrapper.tables.length})

{wrapper.tables.map((table: any) => (
{table.name}
))}
{canManageWrappers ? (
) })}
) } export default WrapperRow