import * as Tooltip from '@radix-ui/react-tooltip' import { PermissionAction } from '@supabase/shared-types/out/constants' import { includes, noop } from 'lodash' import { observer } from 'mobx-react-lite' import { useRouter } from 'next/router' import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, IconCheck, IconEdit3, IconFileText, IconMoreVertical, IconTrash, } from 'ui' import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' import Table from 'components/to-be-cleaned/Table' import { useCheckPermissions, useStore } from 'hooks' interface FunctionListProps { schema: string filterString: string isLocked: boolean editFunction: (fn: any) => void deleteFunction: (fn: any) => void } const FunctionList = ({ schema, filterString, isLocked, editFunction = noop, deleteFunction = noop, }: FunctionListProps) => { const router = useRouter() const { meta } = useStore() const { project: selectedProject } = useProjectContext() const functions = meta.functions.list() const filteredFunctions = functions.filter((x: any) => includes(x.name.toLowerCase(), filterString.toLowerCase()) ) const _functions = filteredFunctions.filter((x) => x.schema == schema) const projectRef = selectedProject?.ref const canUpdateFunctions = useCheckPermissions( PermissionAction.TENANT_SQL_ADMIN_WRITE, 'functions' ) if (_functions.length === 0 && filterString.length === 0) { return (

No functions created yet

There are no functions found in the schema "{schema}"

) } if (_functions.length === 0 && filterString.length > 0) { return (

No results found

Your search for "{filterString}" did not return any results

) } return ( <> {_functions.map((x) => { const isApiDocumentAvailable = schema == 'public' && x.return_type !== 'trigger' return (

{x.name}

{x.argument_types || '-'}

{x.return_type}

{x.security_definer ? 'Definer' : 'Invoker'} {!isLocked && (
{canUpdateFunctions ? ( {isApiDocumentAvailable && ( router.push(`/project/${projectRef}/api?rpc=${x.name}`)} >

Client API docs

)} editFunction(x)}>

Edit function

deleteFunction(x)}>

Delete function

) : (
)}
) })} ) } export default observer(FunctionList)