Files
supabase/apps/studio/components/interfaces/Database/Triggers/ChooseFunctionForm.tsx
T
Alaister YoungandAlaister Young c31230a90e chore(studio): remove @headlessui/react dependency (#44845)
Remove `@headlessui/react` as a direct dependency from both
`apps/studio` and `packages/ui`. It's incompatible with React 19 (at the
pinned v1 version) and overlaps with our existing Radix/shadcn
primitives.

The only usage was the `<Transition>` component in 3 files + a dead
`Overlay` component in `packages/ui`.

**Removed:**
- `@headlessui/react` from `apps/studio/package.json` and
`packages/ui/package.json`
- Dead `packages/ui/src/lib/Overlay/` directory (not exported or
imported anywhere)

**Changed:**
- `ChooseFunctionForm.tsx` — replaced `Transition` with a shadcn
`Accordion` for the "View definition" toggle
- `FileExplorerColumn.tsx` — replaced `Transition` with `framer-motion`
`AnimatePresence` for drag-over overlay
- `PreviewPane.tsx` — removed `Transition` wrapper entirely (wasn't
visually animating on prod), replaced with simple conditional render

Note: `@headlessui/react` will remain in `pnpm-lock.yaml` as a
transitive dependency of `@graphiql/react` and
`@graphiql/plugin-doc-explorer` — that's expected and not something we
control.

## To test

- **Triggers page** (`/dashboard/project/_/database/triggers`): Create
or edit a trigger, click "Choose a function" to open the side panel.
Click "View definition" on a function row — the SQL definition should
expand/collapse with a smooth height animation. Clicking the row itself
should still select the function.
- **Storage explorer**
(`/dashboard/project/_/storage/buckets/<bucket>`): Navigate into a
folder, drag a file over the column — the drag overlay should fade
in/out smoothly.
- **Storage file preview**
(`/dashboard/project/_/storage/buckets/<bucket>`): Click on a file — the
preview pane should appear on the right (no animation, same as current
prod behaviour).

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

* **Refactor**
* Replaced several transition wrappers with new animation/mounting
behavior for overlays, preview panes, and drag-over UI to improve
consistency and responsiveness.
* Swapped the function-definition toggle for an Accordion and updated
click handling to prevent accidental row selection.
* Removed the legacy overlay component, its context, and associated
overlay styling.

* **Chores**
  * Removed HeadlessUI dependency from project packages.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-04-14 17:51:29 +09:00

181 lines
5.6 KiB
TypeScript

import { useParams } from 'common'
import { map as lodashMap, uniqBy } from 'lodash'
import { HelpCircle, Terminal } from 'lucide-react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import {
Accordion_Shadcn_,
AccordionContent_Shadcn_,
AccordionItem_Shadcn_,
AccordionTrigger_Shadcn_,
Button,
SidePanel,
} from 'ui'
import ProductEmptyState from '@/components/to-be-cleaned/ProductEmptyState'
import InformationBox from '@/components/ui/InformationBox'
import SqlEditor from '@/components/ui/SqlEditor'
import {
useDatabaseFunctionsQuery,
type DatabaseFunction,
} from '@/data/database-functions/database-functions-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
export interface ChooseFunctionFormProps {
visible: boolean
setVisible: (value: boolean) => void
onChange: (fn: DatabaseFunction) => void
}
const ChooseFunctionForm = ({ visible, onChange, setVisible }: ChooseFunctionFormProps) => {
const { data: project } = useSelectedProjectQuery()
const { data = [] } = useDatabaseFunctionsQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
const triggerFunctions = data.filter((fn) => fn.return_type === 'trigger')
const hasPublicSchemaFunctions = triggerFunctions.length >= 1
const functionSchemas = lodashMap(uniqBy(triggerFunctions, 'schema'), 'schema')
const selectFunction = (id: number) => {
const fn = triggerFunctions.find((x) => x.id === id)
if (!!fn) onChange(fn)
setVisible(!visible)
}
return (
<SidePanel
size="large"
header="Pick a function"
visible={visible}
onCancel={() => setVisible(!visible)}
className="hooks-sidepanel"
>
<div className="py-6">
{hasPublicSchemaFunctions ? (
<div className="space-y-6">
<NoticeBox />
{functionSchemas.map((schema: string) => (
<SchemaFunctionGroup
key={schema}
schema={schema}
functions={triggerFunctions.filter((x) => x.schema == schema)}
selectFunction={selectFunction}
/>
))}
</div>
) : (
<NoFunctionsState />
)}
</div>
</SidePanel>
)
}
export default ChooseFunctionForm
const NoticeBox = () => {
const { ref } = useParams()
return (
<div className="px-6">
<InformationBox
icon={<HelpCircle size="20" strokeWidth={1.5} />}
title="Only functions that return a trigger will be displayed below"
description={`You can make functions by using the Database Functions`}
button={
<Button asChild type="default">
<Link href={`/project/${ref}/database/functions`}>Go to Functions</Link>
</Button>
}
/>
</div>
)
}
const NoFunctionsState = () => {
// for the empty 'no tables' state link
const router = useRouter()
const { ref } = router.query
return (
<ProductEmptyState
title="No Trigger Functions found in database"
ctaButtonLabel="Create a trigger function"
onClickCta={() => {
router.push(`/project/${ref}/database/functions`)
}}
>
<p className="text-sm text-foreground-light">
You will need to create a trigger based function before you can add it to your trigger.
</p>
</ProductEmptyState>
)
}
export interface SchemaFunctionGroupProps {
schema: string
functions: DatabaseFunction[]
selectFunction: (id: number) => void
}
const SchemaFunctionGroup = ({ schema, functions, selectFunction }: SchemaFunctionGroupProps) => {
return (
<div className="space-y-4">
<div className="sticky top-0 flex items-center space-x-1 px-6 backdrop-blur backdrop-filter">
<h5 className="text-foreground-light">schema</h5>
<h5>{schema}</h5>
</div>
<div className="space-y-0 divide-y border-t border-b border-default">
{functions.map((x) => (
<Function
id={x.id}
key={x.id}
completeStatement={x.complete_statement}
name={x.name}
onClick={selectFunction}
/>
))}
</div>
</div>
)
}
export interface FunctionProps {
id: number
completeStatement: string
name: string
onClick: (id: number) => void
}
const Function = ({ id, completeStatement, name, onClick }: FunctionProps) => {
return (
<div className="cursor-pointer rounded p-3 px-6 hover:bg-studio" onClick={() => onClick(id)}>
<Accordion_Shadcn_ type="single" collapsible>
<AccordionItem_Shadcn_ value="definition" className="border-none">
<div className="flex items-center justify-between space-x-3">
<div className="flex items-center space-x-3">
<div className="flex items-center justify-center rounded bg-foreground p-1 text-background">
<Terminal strokeWidth={2} size={14} />
</div>
<p className="mb-0 text-sm">{name}</p>
</div>
<AccordionTrigger_Shadcn_
onClick={(e) => e.stopPropagation()}
className="py-0 text-xs font-normal text-foreground-light hover:no-underline"
>
View definition
</AccordionTrigger_Shadcn_>
</div>
<AccordionContent_Shadcn_ className="[&>div]:pb-0" onClick={(e) => e.stopPropagation()}>
<div className="mt-4 h-64 border border-default">
<SqlEditor defaultValue={completeStatement} readOnly={true} contextmenu={false} />
</div>
</AccordionContent_Shadcn_>
</AccordionItem_Shadcn_>
</Accordion_Shadcn_>
</div>
)
}