mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
## Context Related to FE-2461 More refactoring to clean up usage of `useQueryStateWithSelect`, in the following pages - Auth OAuth Apps - Cron Jobs - Vaults Secrets Management - Database Hooks - Wrappers ## To test In each of those pages, verify that - [ ] Clicking the "new" cta updates the URL params, and refreshing should re-open the sheet - [ ] Editing an existing item should update URL params, and refreshing should re-open the sheet with the right item - Verify that if the URL param has the wrong id, page should not open the sheet, show a toast, and reset the URL param - [ ] Deleting an existing item should update URL params, and refreshing should re-open the sheet with the right item - Verify that if the URL param has the wrong id, page should not open the sheet, show a toast, and reset the URL param <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Added "item not found" toasts and clearer feedback after create/update/delete actions; prevent opening create flows when server features are disabled. * **Style** * Standardized button labels, sizes and modal/dialog spacing; refined table column widths and inline code formatting for readability. * **Refactor** * Simplified UI state flows across OAuth Apps, Hooks/Webhooks, Cron Jobs, Vault Secrets, and Wrappers to use consistent URL-driven interactions and centralized modals. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
133 lines
4.1 KiB
TypeScript
133 lines
4.1 KiB
TypeScript
import { useParams } from 'common'
|
|
import { useFDWsQuery } from 'data/fdw/fdws-query'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import { parseAsString, useQueryState } from 'nuqs'
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Card,
|
|
cn,
|
|
Sheet,
|
|
SheetContent,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableFooter,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from 'ui'
|
|
|
|
import { INTEGRATIONS } from '../Landing/Integrations.constants'
|
|
import { DeleteWrapperModal } from './DeleteWrapperModal'
|
|
import { EditWrapperSheet } from './EditWrapperSheet'
|
|
import { WrapperRow } from './WrapperRow'
|
|
import { wrapperMetaComparator } from './Wrappers.utils'
|
|
|
|
interface WrapperTableProps {
|
|
isLatest?: boolean
|
|
}
|
|
|
|
export const WrapperTable = ({ isLatest = false }: WrapperTableProps) => {
|
|
const { id, ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const integration = INTEGRATIONS.find((i) => i.id === id)
|
|
|
|
const [isClosingEditWrapper, setIsClosingEditWrapper] = useState(false)
|
|
|
|
const { data, isSuccess } = useFDWsQuery({
|
|
projectRef: ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const wrappers = useMemo(
|
|
() =>
|
|
integration && integration.type === 'wrapper' && data
|
|
? data.filter((wrapper) => wrapperMetaComparator(integration.meta, wrapper))
|
|
: [],
|
|
[data, integration]
|
|
)
|
|
|
|
const [selectedWrapperIdToEdit, setSelectedWrapperToEdit] = useQueryState('edit', parseAsString)
|
|
const selectedWrapperToEdit = wrappers.find((w) => w.id.toString() === selectedWrapperIdToEdit)
|
|
|
|
useEffect(() => {
|
|
if (isSuccess && !!selectedWrapperIdToEdit && !selectedWrapperToEdit) {
|
|
toast('Wrapper not found')
|
|
setSelectedWrapperToEdit(null)
|
|
}
|
|
}, [isSuccess, selectedWrapperIdToEdit, selectedWrapperToEdit, setSelectedWrapperToEdit])
|
|
|
|
if (!integration || integration.type !== 'wrapper') {
|
|
return (
|
|
<p className="text-foreground-light text-sm">
|
|
The referenced ID doesn't correspond to a wrapper integration
|
|
</p>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Card className="max-w-5xl">
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead className="w-[220px]">Name</TableHead>
|
|
<TableHead>Tables</TableHead>
|
|
<TableHead>Encrypted key</TableHead>
|
|
<TableHead className="w-24">
|
|
<span className="sr-only">Actions</span>
|
|
</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{(isLatest ? wrappers.slice(0, 3) : wrappers).map((x) => {
|
|
return <WrapperRow key={x.id} wrapper={x} />
|
|
})}
|
|
</TableBody>
|
|
<TableFooter
|
|
className={cn(
|
|
'text-xs font-normal text-center text-foreground-muted',
|
|
// Prevent the footer from being highlighted on hover
|
|
'[&>tr>td]:hover:bg-inherit',
|
|
// Conditionally remove the border-top if there are no wrappers
|
|
wrappers.length === 0 ? 'border-t-0' : ''
|
|
)}
|
|
>
|
|
<TableRow>
|
|
<TableCell colSpan={4}>
|
|
{wrappers.length} {integration?.name}
|
|
{wrappers.length === 0 || wrappers.length > 1 ? 's' : ''} created
|
|
</TableCell>
|
|
</TableRow>
|
|
</TableFooter>
|
|
</Table>
|
|
</Card>
|
|
|
|
<Sheet
|
|
open={!!selectedWrapperToEdit}
|
|
onOpenChange={(open) => {
|
|
if (!open) setIsClosingEditWrapper(true)
|
|
}}
|
|
>
|
|
<SheetContent size="lg" tabIndex={undefined}>
|
|
{selectedWrapperToEdit && (
|
|
<EditWrapperSheet
|
|
wrapper={selectedWrapperToEdit}
|
|
wrapperMeta={integration.meta}
|
|
onClose={() => {
|
|
setSelectedWrapperToEdit(null)
|
|
setIsClosingEditWrapper(false)
|
|
}}
|
|
isClosing={isClosingEditWrapper}
|
|
setIsClosing={setIsClosingEditWrapper}
|
|
/>
|
|
)}
|
|
</SheetContent>
|
|
</Sheet>
|
|
|
|
<DeleteWrapperModal />
|
|
</>
|
|
)
|
|
}
|