import { Transition } from '@headlessui/react'
import { useParams } from 'common'
import { map as lodashMap, uniqBy } from 'lodash'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { Button, IconChevronDown, IconHelpCircle, IconTerminal, SidePanel } from 'ui'
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
import InformationBox from 'components/ui/InformationBox'
import SqlEditor from 'components/ui/SqlEditor'
import type { DatabaseFunction } from 'data/database-functions/database-functions-query'
export interface ChooseFunctionFormProps {
triggerFunctions: DatabaseFunction[]
visible: boolean
onChange: (id: number) => void
setVisible: (value: boolean) => void
}
const ChooseFunctionForm = ({
triggerFunctions,
visible,
onChange,
setVisible,
}: ChooseFunctionFormProps) => {
const hasPublicSchemaFunctions = triggerFunctions.length >= 1
const functionSchemas = lodashMap(uniqBy(triggerFunctions, 'schema'), 'schema')
function selectFunction(id: number) {
onChange(id)
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={
Go to Functions
}
/>
)
}
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) => {
const [visible, setVisible] = useState(false)
return (
onClick(id)}>
{
e.stopPropagation()
setVisible(!visible)
}}
icon={
}
>
{visible ? 'Hide definition' : 'View definition'}
)
}