Files
Gildas Garcia 914677ed4b chore: migrate foreign wrapper forms to react-hook-form (#44512)
## Problem

Foreign wrapper forms still use `formik` but we now use
`react-hook-form` everywhere and we'd like to reduce our dependencies.

## Solution

- [x] Write e2e tests for wrappers
- [x] Migrate to `react-hook-form`

## Notes

I tried to cover the 3 cases I identified for foreign wrappers with e2e
tests:
- Add all available tables to a new schema (stripe)
- Add selected tables to a new table (stripe)
- Create dynamic columns (s3 wrapper)

However, they are not exhaustive as I can't test the integration
actually works, only that it was created successfully. Besides, I can't
test the Iceberg wrapper case as it needs actual S3 buckets.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Enhanced column-type selector with searchable combobox, enum support,
icons, and optional recommendation prompts.

* **Refactor**
* Migrated many wrapper/table/editor forms to a schema-driven form
system with stronger validation, dynamic field arrays, and consistent
form controls.
* Updated input field integration to work with the new form control
model.

* **Bug Fixes**
* Improved handling of missing wrapper/error states during wrapper
loading.

* **Tests**
* Added unit tests for form schemas and end-to-end tests for wrapper
creation flows.

* **Chores**
  * Removed legacy dynamic-columns component.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-09 09:20:27 +02:00

133 lines
4.1 KiB
TypeScript

import { useParams } from 'common'
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'
import { useFDWsQuery } from '@/data/fdw/fdws-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
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, isError } = 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 (isError && !!selectedWrapperIdToEdit && !selectedWrapperToEdit) {
toast('Wrapper not found')
setSelectedWrapperToEdit(null)
}
}, [isError, 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 className="border-b-0">
<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 />
</>
)
}