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 (
You will need to create a trigger based function before you can add it to your trigger.
{name}