import { Transition } from '@headlessui/react' import { Dictionary } from 'components/grid' import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState' import InformationBox from 'components/ui/InformationBox' import SqlEditor from 'components/ui/SqlEditor' import { map as lodashMap, uniqBy } from 'lodash' import { observer, useLocalObservable } from 'mobx-react-lite' import { useRouter } from 'next/router' import { createContext, useContext, useState } from 'react' import { Button, IconChevronDown, IconHelpCircle, IconTerminal, SidePanel } from 'ui' interface IChooseFunctionFormStore { functionSchemas: string[] triggerFunctions: Dictionary[] } class ChooseFunctionFormStore implements IChooseFunctionFormStore { triggerFunctions = [] get functionSchemas() { return lodashMap(uniqBy(this.triggerFunctions, 'schema'), 'schema') } } const ChooseFunctionFormContext = createContext(null) export interface ChooseFunctionFormProps { triggerFunctions: Dictionary[] visible: boolean onChange: (id: number) => void setVisible: (value: boolean) => void } const ChooseFunctionForm = ({ triggerFunctions, visible, onChange, setVisible, }: ChooseFunctionFormProps) => { const _localState = useLocalObservable(() => new ChooseFunctionFormStore()) _localState.triggerFunctions = triggerFunctions as any function selectFunction(id: number) { onChange(id) setVisible(!visible) } const hasPublicSchemaFunctions = _localState.triggerFunctions.length >= 1 return ( setVisible(!visible)} className="hooks-sidepanel" >
{hasPublicSchemaFunctions ? (
{_localState.functionSchemas.map((schema: string) => ( ))}
) : ( )}
) } export default observer(ChooseFunctionForm) const NoticeBox = ({}) => { const router = useRouter() const { ref } = router.query 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 selectFunction: (id: number) => void } const SchemaFunctionGroup = observer(({ schema, selectFunction }: SchemaFunctionGroupProps) => { const _pageState = useContext(ChooseFunctionFormContext) const _functions = _pageState!.triggerFunctions.filter((x) => x.schema == schema) 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) => { const [visible, setVisible] = useState(false) return (
onClick(id)} >

{name}

) }