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, AccordionContent, AccordionItem, AccordionTrigger, 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 ( setVisible(!visible)} className="hooks-sidepanel" >
{hasPublicSchemaFunctions ? (
{functionSchemas.map((schema: string) => ( x.schema == schema)} selectFunction={selectFunction} /> ))}
) : ( )}
) } export default ChooseFunctionForm const NoticeBox = () => { const { ref } = useParams() return (
} title="Only functions that return a trigger will be displayed below" description={`You can make functions by using the Database Functions`} button={ } />
) } const NoFunctionsState = () => { // for the empty 'no tables' state link const router = useRouter() const { ref } = router.query return ( { router.push(`/project/${ref}/database/functions`) }} >

You will need to create a trigger based function before you can add it to your trigger.

) } export interface SchemaFunctionGroupProps { schema: string functions: DatabaseFunction[] selectFunction: (id: number) => void } const SchemaFunctionGroup = ({ schema, functions, selectFunction }: SchemaFunctionGroupProps) => { return (
schema
{schema}
{functions.map((x) => ( ))}
) } export interface FunctionProps { id: number completeStatement: string name: string onClick: (id: number) => void } const Function = ({ id, completeStatement, name, onClick }: FunctionProps) => { return (
onClick(id)}>

{name}

e.stopPropagation()} className="py-0 text-xs font-normal text-foreground-light hover:no-underline" > View definition
e.stopPropagation()}>
) }